Skip to content

Commit

Permalink
Merge pull request #9 from NGRsoftlab/fix-go-version
Browse files Browse the repository at this point in the history
fix: test&cosmetics; feat: go->1.22.3
  • Loading branch information
ElrondfromRussia authored May 24, 2024
2 parents 3efe07b + a33937c commit 7cb53c3
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 117 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.3'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
8 changes: 4 additions & 4 deletions cef_formatter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2020 NGR Softlab
//
// Copyright 2020-2024 NGR Softlab
package sysloger

import (
Expand All @@ -8,7 +7,8 @@ import (

syslog "github.com/RackSec/srslog"
"github.com/pcktdmp/cef/cefevent"
log "github.com/sirupsen/logrus"

logging "github.com/NGRsoftlab/ngr-logging"
)

// CefHeader CEF header parameters
Expand Down Expand Up @@ -85,7 +85,7 @@ func MakeCefString(header CefHeader, contentMap map[string]interface{}, keysAreL

cef, err := event.Generate()
if err != nil {
log.Warning("bad cef generation: ", err)
logging.Logger.Errorf("bad cef generation: %s", err)
return "", err
}

Expand Down
8 changes: 4 additions & 4 deletions cef_formatter_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2020 NGR Softlab
//
// Copyright 2020-2024 NGR Softlab
package sysloger

import (
"fmt"
syslog "github.com/RackSec/srslog"
"testing"

syslog "github.com/RackSec/srslog"
)

/////////////////////////////////////////////////
// ///////////////////////////////////////////////
func TestFormatter(t *testing.T) {
f := make(map[string]interface{})

Expand Down
1 change: 1 addition & 0 deletions cef_mapper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2020-2024 NGR Softlab
package sysloger

type FieldInfo struct {
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module github.com/NGRsoftlab/ngr-sysloger

go 1.13
go 1.22.3

require (
github.com/NGRsoftlab/ngr-logging v1.0.0
github.com/RackSec/srslog v0.0.0-20180709174129-a4725f04ec91
github.com/pcktdmp/cef v0.2.0
github.com/sirupsen/logrus v1.8.1
)

require (
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/sys v0.20.0 // indirect
)
20 changes: 14 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
github.com/NGRsoftlab/ngr-logging v1.0.0 h1:Yp42kvw/bofZ6xXC5jPlPx1HNabZQY9cvzGnB0earJY=
github.com/NGRsoftlab/ngr-logging v1.0.0/go.mod h1:99kZ+XwSK7rKRitmhZvqOdYnPf9Qepywt3zjJJcJDME=
github.com/RackSec/srslog v0.0.0-20180709174129-a4725f04ec91 h1:vX+gnvBc56EbWYrmlhYbFYRaeikAke1GL84N4BEYOFE=
github.com/RackSec/srslog v0.0.0-20180709174129-a4725f04ec91/go.mod h1:cDLGBht23g0XQdLjzn6xOGXDkLK182YfINAaZEQLCHQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pcktdmp/cef v0.2.0 h1:MgFUXCRqaXsITq83bN0+mmXVh4CGFgOeuyxNaT86Kj0=
github.com/pcktdmp/cef v0.2.0/go.mod h1:GXp8etaM/0qdUEx0djN3JmUvBY595+xhJlD0xLOXbgM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions level_selector.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2020 NGR Softlab
//
// Copyright 2020-2024 NGR Softlab
package sysloger

import (
"errors"

syslog "github.com/RackSec/srslog"
)

Expand Down
31 changes: 11 additions & 20 deletions syslog_utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright 2020-2022 NGR Softlab
//
// Copyright 2020-2024 NGR Softlab
package sysloger

import (
"fmt"
"time"

syslog "github.com/RackSec/srslog"
log "github.com/sirupsen/logrus"

logging "github.com/NGRsoftlab/ngr-logging"
)

/////////////////////////////////////////////////////////
Expand All @@ -18,18 +17,16 @@ import (
func SendListToSyslog(params SyslogParams, formatter syslog.Formatter, msgList []string) error {
writer, err := NewSyslogWriter(params, formatter)
if err != nil {
log.Error("ERROR failed to create writer:", err)
logging.Logger.Errorf("ERROR failed to create writer: %s", err.Error())
return err
}

defer func() { _ = writer.Close() }()

log.Info(fmt.Sprintf("need write: %d msgs to syslog", len(msgList)))

for i, msg := range msgList {
_, errW := doSuitableMethod(writer, params.Level, msg)
if errW != nil {
log.Warning(fmt.Sprintf("ERROR writing to syslog: %d %v", i, errW))
logging.Logger.Warningf("ERROR writing to syslog: %d %v", i, errW)
}
}

Expand All @@ -40,17 +37,15 @@ func SendListToSyslog(params SyslogParams, formatter syslog.Formatter, msgList [
func SendSingleSyslogMsg(params SyslogParams, formatter syslog.Formatter, msg string) error {
writer, err := NewSyslogWriter(params, formatter)
if err != nil {
log.Error("ERROR failed to create writer:", err)
logging.Logger.Errorf("ERROR failed to create writer: %s", err.Error())
return err
}

defer func() { _ = writer.Close() }()

log.Info("need write: 1 msg to syslog")

_, errW := doSuitableMethod(writer, params.Level, msg)
if errW != nil {
log.Error("ERROR writing to syslog: ", errW)
logging.Logger.Errorf("ERROR writing to syslog: %s", errW.Error())
return errW
}

Expand All @@ -61,18 +56,16 @@ func SendSingleSyslogMsg(params SyslogParams, formatter syslog.Formatter, msg st
func SendListToSyslogWithTimeout(params SyslogParams, formatter syslog.Formatter, msgList []string, timeout time.Duration) error {
writer, err := NewSyslogWriterWithTimeout(params, formatter, timeout)
if err != nil {
log.Error("ERROR failed to create writer:", err)
logging.Logger.Errorf("ERROR failed to create writer: %s", err.Error())
return err
}

defer func() { _ = writer.Close() }()

log.Info(fmt.Sprintf("need write: %d msgs to syslog", len(msgList)))

for i, msg := range msgList {
_, errW := doSuitableMethod(writer, params.Level, msg)
if errW != nil {
log.Warning(fmt.Sprintf("ERROR writing to syslog: %d %v", i, errW))
logging.Logger.Warningf("ERROR writing to syslog: %d %v", i, errW)
}
}

Expand All @@ -83,17 +76,15 @@ func SendListToSyslogWithTimeout(params SyslogParams, formatter syslog.Formatter
func SendSingleSyslogMsgWithTimeout(params SyslogParams, formatter syslog.Formatter, msg string, timeout time.Duration) error {
writer, err := NewSyslogWriterWithTimeout(params, formatter, timeout)
if err != nil {
log.Error("ERROR failed to create writer:", err)
logging.Logger.Errorf("ERROR failed to create writer: %s", err.Error())
return err
}

defer func() { _ = writer.Close() }()

log.Info("need write: 1 msg to syslog")

_, errW := doSuitableMethod(writer, params.Level, msg)
if errW != nil {
log.Error("ERROR writing to syslog: ", errW)
logging.Logger.Errorf("ERROR writing to syslog: %s", errW.Error())
return errW
}

Expand Down
14 changes: 7 additions & 7 deletions sysloger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2020 NGR Softlab
//
// Copyright 2020-2024 NGR Softlab
package sysloger

import (
Expand All @@ -10,7 +9,8 @@ import (
"time"

syslog "github.com/RackSec/srslog"
log "github.com/sirupsen/logrus"

logging "github.com/NGRsoftlab/ngr-logging"
)

// SyslogParams syslog dial params
Expand All @@ -34,7 +34,7 @@ func NewSyslogWriter(params SyslogParams, formatter syslog.Formatter) (*syslog.W

if params.NeedTls {
if params.TlsConf == nil {
log.Error("ERROR nil TlsConf")
logging.Logger.Error("ERROR nil TlsConf")
return nil, errors.New("nil TlsConf")
}

Expand All @@ -46,7 +46,7 @@ func NewSyslogWriter(params SyslogParams, formatter syslog.Formatter) (*syslog.W
}

if err != nil {
log.Error("ERROR failed to dial syslog:", err)
logging.Logger.Errorf("ERROR failed to dial syslog: %s", err.Error())
return nil, err
}

Expand All @@ -65,7 +65,7 @@ func NewSyslogWriterWithTimeout(params SyslogParams, formatter syslog.Formatter,

if params.NeedTls {
if params.TlsConf == nil {
log.Error("ERROR nil TlsConf")
logging.Logger.Error("ERROR nil TlsConf")
return nil, errors.New("nil TlsConf")
}

Expand All @@ -84,7 +84,7 @@ func NewSyslogWriterWithTimeout(params SyslogParams, formatter syslog.Formatter,
sysLogger, err = syslog.DialWithCustomDialer("custom", fmt.Sprintf("%s:%d", params.Host, params.Port),
params.Priority, params.Tag, dial)
if err != nil {
log.Error("ERROR failed to dial syslog:", err)
logging.Logger.Errorf("ERROR failed to dial syslog: %s", err.Error())
return nil, err
}

Expand Down
Loading

0 comments on commit 7cb53c3

Please sign in to comment.