From b3bcaa3da8d00cf7088195d640f618a1846af317 Mon Sep 17 00:00:00 2001 From: asauerwein Date: Tue, 5 Apr 2022 23:46:50 +0200 Subject: [PATCH 1/3] add support for non json messages --- main.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 6a3754a..5503404 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "net/http" "os" "os/signal" + "strconv" "syscall" "time" @@ -84,13 +85,24 @@ func NewHandler() *handler { // handle is called when a message is received func (o *handler) handle(_ mqtt.Client, msg mqtt.Message) { - // We extract the count and write that out first to simplify checking for missing values - var message map[string]interface{} - err := json.Unmarshal(msg.Payload(), &message) - if err != nil { - fmt.Printf("Message could not be parsed (%s): %s", msg.Payload(), err) + // prepare map for sending to hec + var message = make(map[string]interface{}) + // save msg as string to conert easily + message_string := string(msg.Payload()) + // check if payload can be converted to number + messagePayload, interr := strconv.Atoi(message_string) + if interr != nil { + fmt.Printf("no number: %s\n", msg.Payload()) + // check if payload can be unmarshalled as json + err := json.Unmarshal(msg.Payload(), &message) + if err != nil { + fmt.Printf("Message could not be parsed (%s): %s\n", msg.Payload(), err) + // use string instead + message["payload"] = string(msg.Payload()) + } + } else { + message["payload"] = messagePayload } - if conf.WriteToConsole { fmt.Printf("received message: %s\n", msg.Payload()) } @@ -98,7 +110,7 @@ func (o *handler) handle(_ mqtt.Client, msg mqtt.Message) { message["TOPIC"] = msg.Topic() payload, jsonErr := json.Marshal(message) if jsonErr != nil { - fmt.Printf("ERROR creating json payload: %s\n", err.Error()) + fmt.Printf("ERROR creating json payload: %s\n", jsonErr.Error()) } event1 := hec.NewEvent(string(payload)) err := o.spl.WriteEvent(event1) From 783d85f9fc3afe66852b85fa41584d1a4be96b3e Mon Sep 17 00:00:00 2001 From: asauerwein Date: Tue, 5 Apr 2022 23:47:13 +0200 Subject: [PATCH 2/3] run docker build on dev branches --- .github/workflows/docker.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4f58666..86075d8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,7 +3,9 @@ name: Docker on: release: types: [published] - + push: + branches: + - 'dev*' jobs: build: From 3c942bb7ae43923eb9744211f67c347f25f6e092 Mon Sep 17 00:00:00 2001 From: Andreas Sauerwein-Schlosser Date: Sat, 28 Jan 2023 15:07:49 +0100 Subject: [PATCH 3/3] include more os builds --- .github/workflows/docker.yml | 3 +- .github/workflows/go.yml | 93 ++++++++++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4f58666..153a44c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,7 +5,6 @@ on: types: [published] jobs: - build: runs-on: ubuntu-latest steps: @@ -44,7 +43,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . - platforms: linux/amd64,linux/arm/v7 + platforms: linux/amd64,linux/arm/v6, linux/arm/v7, linux/arm64/v8 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} push: True diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b06aeef..62b50f5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,8 +5,7 @@ on: types: [published] jobs: - - build: + build-linux: runs-on: ubuntu-latest strategy: matrix: @@ -14,21 +13,75 @@ jobs: goarch: ["arm", "arm64", "386", "amd64"] go: ["1.17"] steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} - - - name: Build - env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - run: go build -o splunk-mqtt-$GOOS-$GOARCH-$GITHUB_REF_NAME -v ./... - - name: Test - run: go test -v ./... - - name: Release - uses: softprops/action-gh-release@v1 - with: - files: splunk-mqtt-* + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Build + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: go build -o splunk-mqtt-$GOOS-$GOARCH-$GITHUB_REF_NAME -v ./... + - name: Test + run: go test -v ./... + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: splunk-mqtt-* + + build-darwin: + runs-on: ubuntu-latest + strategy: + matrix: + goos: [darwin] + goarch: ["amd64", "arm64"] + go: ["1.17"] + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Build + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: go build -o splunk-mqtt-$GOOS-$GOARCH-$GITHUB_REF_NAME -v ./... + - name: Test + run: go test -v ./... + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: splunk-mqtt-* + + build-windows: + runs-on: ubuntu-latest + strategy: + matrix: + goos: [windows] + goarch: ["amd64", "arm64"] + go: ["1.17"] + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Build + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: go build -o splunk-mqtt-$GOOS-$GOARCH-$GITHUB_REF_NAME -v ./... + - name: Test + run: go test -v ./... + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: splunk-mqtt-*