Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using log library of Go-Core instead of external library #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 46 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
inputs:
integration:
description: 'Integration'
description: 'Integration'
required: true
oec-version:
description: 'Version of OEC'
Expand Down Expand Up @@ -63,6 +63,12 @@ jobs:
file: oec-linux-amd64-${{ github.event.inputs.oec-version }}.zip
- name: Extracting Linux Package
run: unzip -qq oec-linux-amd64-${{ github.event.inputs.oec-version }}.zip -d .release/oec-linux/${{ env.INTEGRATION_FOLDER }}
- name: Copy Log File if Incoming part exist
run: |
if [ -d ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }} ]
then
cp -R release/log/log.go ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }}/.
fi
- name: Copy Integration Files
run: cp -R ${{ github.event.inputs.integration }}/. .release/oec-linux/${{ env.INTEGRATION_FOLDER }}
- name: Remove http script (todo remove when http version is released)
Expand All @@ -78,9 +84,9 @@ jobs:
run: |
INTEGRATION_PATH=oec-linux/${{ env.INTEGRATION_FOLDER }}/opsgenie-${{ env.INTEGRATION_NAME }}
echo ${INTEGRATION_PATH}
go get -u github.com/alexcesaro/log && \
cd ${INTEGRATION_PATH} && \
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go log.go
rm -f log.go
- name: Compressing Linux Package
run: |
cd .release/oec-linux/
Expand Down Expand Up @@ -128,6 +134,12 @@ jobs:
run: unzip -qq oec-linux-amd64-${{ github.event.inputs.oec-version }}.zip -d .release/oec-rpm
- name: Copy SPEC Files
run: cp -R release/oec-builder/oec-rpm/. .release/oec-rpm
- name: Copy Log File if Incoming part exist
run: |
if [ -d ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }} ]
then
cp -R release/log/log.go ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }}/.
fi
- name: Copy Integration Files
run: cp -R ${{ github.event.inputs.integration }}/. .release/oec-rpm/oec-scripts
- name: Check Incoming part exists
Expand All @@ -141,10 +153,10 @@ jobs:
run: |
INTEGRATION_PATH=oec-rpm/oec-scripts/opsgenie-${INTEGRATION_NAME}
echo ${INTEGRATION_PATH}
go get -u github.com/alexcesaro/log && \
cd ${INTEGRATION_PATH} && \
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go
- name: Create RPM Package
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go log.go
rm -f log.go
- name: Create RPM Package
working-directory: .release/oec-rpm
run: |
sed -i "s|<path_of_script>|$RPM_BUILD_ROOT/home/opsgenie/oec/scripts/actionExecutor.py|" oec-scripts/conf/config.json
Expand Down Expand Up @@ -222,6 +234,12 @@ jobs:
run: cp -R release/oec-builder/oec-deb/. .release/oec-deb
- name: Create Output Directory
run: mkdir -p .release/oec-deb/home/opsgenie/oec
- name: Copy Log File if Incoming part exist
run: |
if [ -d ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }} ]
then
cp -R release/log/log.go ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }}/.
fi
- name: Copy Integration Files
run: cp -R ${{ github.event.inputs.integration }}/. .release/oec-deb/home/opsgenie/oec
- name: Check Incoming part exists
Expand All @@ -235,10 +253,10 @@ jobs:
run: |
INTEGRATION_PATH=oec-deb/home/opsgenie/oec/opsgenie-${{ env.INTEGRATION_NAME }}
echo ${INTEGRATION_PATH}
go get -u github.com/alexcesaro/log && \
cd ${INTEGRATION_PATH} && \
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go
- name: Create Deb Package
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go log.go
rm -f log.go
- name: Create Deb Package
working-directory: .release/
run: |
sed -i "s|<path_of_script>|/home/opsgenie/oec/scripts/actionExecutor.py|" oec-deb/home/opsgenie/oec/conf/config.json
Expand All @@ -257,7 +275,7 @@ jobs:
with:
name: Debian Artifact
path: .release/oec-deb/opsgenie-${{ env.INTEGRATION_NAME }}_${{ env.INTEGRATION_VERSION }}_amd64.deb
- name: Upload
- name: Upload
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -274,7 +292,7 @@ jobs:
INTEGRATION_NAME: ${{ needs.setup.outputs.integration_name }}
INTEGRATION_VERSION: ${{ needs.setup.outputs.integration_version }}
INTEGRATION_FOLDER: opsgenie-${{ needs.setup.outputs.integration_name }}-${{ needs.setup.outputs.integration_version }}-win-386
if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/master'
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
Expand All @@ -296,6 +314,12 @@ jobs:
run: unzip -qq oec-win-386-${{ github.event.inputs.oec-version }}.zip -d .release/oec-win32/${{ env.INTEGRATION_FOLDER }}
- name: Copy OEC Service Conf
run: cp -R release/oec-builder/oec-win32/oecService.json.example .release/oec-win32/${{ env.INTEGRATION_FOLDER }}
- name: Copy Log File if Incoming part exist
run: |
if [ -d ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }} ]
then
cp -R release/log/log.go ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }}/.
fi
- name: Copy Integration Files
run: cp -R ${{ github.event.inputs.integration }}/. .release/oec-win32/${{ env.INTEGRATION_FOLDER }}
- name: Remove http script (todo remove when http version is released)
Expand All @@ -311,9 +335,9 @@ jobs:
run: |
INTEGRATION_PATH=oec-win32/${{ env.INTEGRATION_FOLDER }}/opsgenie-${{ env.INTEGRATION_NAME }}
echo ${INTEGRATION_PATH}
go get -u github.com/alexcesaro/log && \
cd ${INTEGRATION_PATH} && \
GOOS=windows GOARCH=386 go build -o send2opsgenie32.exe send2opsgenie.go
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go log.go
rm -f log.go
- name: Compressing Win32 Package
run: |
cd .release/oec-win32/
Expand All @@ -340,7 +364,7 @@ jobs:
INTEGRATION_NAME: ${{ needs.setup.outputs.integration_name }}
INTEGRATION_VERSION: ${{ needs.setup.outputs.integration_version }}
INTEGRATION_FOLDER: opsgenie-${{ needs.setup.outputs.integration_name }}-${{ needs.setup.outputs.integration_version }}-win-amd64
if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/master'
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
Expand All @@ -362,6 +386,12 @@ jobs:
run: unzip -qq oec-win-amd64-${{ github.event.inputs.oec-version }}.zip -d .release/oec-win64/${{ env.INTEGRATION_FOLDER }}
- name: Copy OEC Service Conf
run: cp -R release/oec-builder/oec-win64/oecService.json.example .release/oec-win64/${{ env.INTEGRATION_FOLDER }}
- name: Copy Log File if Incoming part exist
run: |
if [ -d ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }} ]
then
cp -R release/log/log.go ${{ github.event.inputs.integration }}/opsgenie-${{ env.INTEGRATION_NAME }}/.
fi
- name: Copy Integration Files
run: cp -R ${{ github.event.inputs.integration }}/. .release/oec-win64/${{ env.INTEGRATION_FOLDER }}
- name: Remove http script (todo remove when http version is released)
Expand All @@ -377,9 +407,9 @@ jobs:
run: |
INTEGRATION_PATH=oec-win64/${{ env.INTEGRATION_FOLDER }}/opsgenie-${{ env.INTEGRATION_NAME }}
echo ${INTEGRATION_PATH}
go get -u github.com/alexcesaro/log && \
cd ${INTEGRATION_PATH} && \
GOOS=windows GOARCH=amd64 go build -o send2opsgenie32.exe send2opsgenie.go
GOOS=linux GOARCH=amd64 go build -o send2opsgenie send2opsgenie.go log.go
rm -f log.go
- name: Compressing Win 64 Package
run: |
cd .release/oec-win64/
Expand Down
32 changes: 17 additions & 15 deletions BMCFootprintsV11/opsgenie-bmcfootprintsv11/send2opsgenie.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"encoding/xml"
"flag"
"fmt"
"github.com/alexcesaro/log"
"github.com/alexcesaro/log/golog"
"io"
"io/ioutil"
"net"
Expand Down Expand Up @@ -41,8 +39,8 @@ var bmcFootPrintsWebServiceURL string

var configPath string
var configPath2 string
var levels = map[string]log.Level{"info": log.Info, "debug": log.Debug, "warning": log.Warning, "error": log.Error}
var logger log.Logger
var levels = map[string]int{"info": LogInfo, "debug": LogDebug, "warning": LogWarning, "error": LogError}
var logger *OpsgenieFileLogger
var ogPrefix string = "[OpsGenie] "

type Item struct {
Expand Down Expand Up @@ -189,14 +187,18 @@ func main() {
parameters["closureCode"] = issueDetails.ClosureCode
} else if len(issueDetails.AllDescriptions.Items) > 1 {
if strings.HasPrefix(issueDetails.Description, ogPrefix) {
logger.Debug("Skipping, Incident or Problem was created from OpsGenie.")
if logger != nil {
logger.Debug("Skipping, Incident or Problem was created from OpsGenie.")
}
return
}

parameters["action"] = "AddNote"
} else {
if strings.HasPrefix(issueDetails.Description, ogPrefix) {
logger.Debug("Skipping, Incident or Problem was created from OpsGenie.")
if logger != nil {
logger.Debug("Skipping, Incident or Problem was created from OpsGenie.")
}
return
}

Expand Down Expand Up @@ -234,7 +236,7 @@ func main() {

func printConfigToLog() {
if logger != nil {
if logger.LogDebug() {
if logger.LogLevel == LogDebug {
logger.Debug("Config:")
for k, v := range configParameters {
if strings.Contains(k, "password") {
Expand Down Expand Up @@ -267,7 +269,7 @@ func readConfigFile(file io.Reader) {
}
}

func readConfigurationFileFromOECConfig(filepath string) (error) {
func readConfigurationFileFromOECConfig(filepath string) error {

jsonFile, err := os.Open(filepath)

Expand Down Expand Up @@ -302,7 +304,7 @@ type Configuration struct {
BaseUrl string `json:"baseUrl"`
}

func configureLogger() log.Logger {
func configureLogger() *OpsgenieFileLogger {
level := configParameters["bmcFootPrints2opsgenie.logger"]
var logFilePath = parameters["logPath"]

Expand All @@ -314,7 +316,7 @@ func configureLogger() log.Logger {
}
}

var tmpLogger log.Logger
var tmpLogger *OpsgenieFileLogger

file, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)

Expand All @@ -333,10 +335,10 @@ func configureLogger() log.Logger {
if errTmp != nil {
fmt.Println("Logging disabled. Reason: ", errTmp)
} else {
tmpLogger = golog.New(fileTmp, levels[strings.ToLower(level)])
tmpLogger = NewFileLogger(fileTmp, levels[strings.ToLower(level)])
}
} else {
tmpLogger = golog.New(file, levels[strings.ToLower(level)])
tmpLogger = NewFileLogger(file, levels[strings.ToLower(level)])
}

return tmpLogger
Expand Down Expand Up @@ -546,19 +548,19 @@ func parseFlags() {
if *apiKey != "" {
parameters["apiKey"] = *apiKey
} else {
parameters["apiKey"] = configParameters ["apiKey"]
parameters["apiKey"] = configParameters["apiKey"]
}

if *responders != "" {
parameters["responders"] = *responders
} else {
parameters["responders"] = configParameters ["responders"]
parameters["responders"] = configParameters["responders"]
}

if *tags != "" {
parameters["tags"] = *tags
} else {
parameters["tags"] = configParameters ["tags"]
parameters["tags"] = configParameters["tags"]
}

if *logPath != "" {
Expand Down
Loading