Skip to content

Commit

Permalink
Merge pull request #2 from aSauerwein/dev
Browse files Browse the repository at this point in the history
release version 0.1.2
  • Loading branch information
aSauerwein authored Jan 28, 2023
2 parents 469c548 + 526dd38 commit 43d75ab
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 30 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ name: Docker
on:
release:
types: [published]

push:
branches:
- 'dev*'
jobs:

build:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -44,7 +45,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
93 changes: 73 additions & 20 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,83 @@ on:
types: [published]

jobs:

build:
build-linux:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux]
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-*
26 changes: 19 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"

Expand Down Expand Up @@ -84,21 +85,32 @@ 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())
}
if conf.WriteToSplunk {
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)
Expand Down

0 comments on commit 43d75ab

Please sign in to comment.