diff --git a/Makefile b/Makefile index 9765960..f103441 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,8 @@ GOVERSION:=$(shell \ ) # also update go.mod files when changing minumum version # find . -name go.mod -MINGOVERSION:=00010025 -MINGOVERSIONSTR:=1.25 +MINGOVERSION:=00010026 +MINGOVERSIONSTR:=1.26 BUILD:=$(shell git rev-parse --short HEAD) # see https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md # and https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module @@ -84,7 +84,7 @@ build-watch: vendor tools test: dump vendor - $(GO) test -short -v $(TEST_FLAGS) pkg/... + $(GO) test -short -v $(TEST_FLAGS) ./pkg/* if grep -Irn TODO: ./cmd/ ./pkg/; then exit 1; fi if grep -Irn Dump ./cmd/ ./pkg/ | $(DUMPEXCEPTIONS); then exit 1; fi @@ -135,18 +135,18 @@ citest: tools vendor # benchmark: - $(GO) test $(TEST_FLAGS) -v -bench=B\* -run=^$$ -benchmem pkg/... + $(GO) test $(TEST_FLAGS) -v -bench=B\* -run=^$$ -benchmem ./pkg/* racetest: - $(GO) test -race -short $(TEST_FLAGS) -coverprofile=coverage.txt -covermode=atomic -gcflags "-d=checkptr=0" pkg/... + $(GO) test -race -short $(TEST_FLAGS) -coverprofile=coverage.txt -covermode=atomic -gcflags "-d=checkptr=0" ./pkg/* covertest: - $(GO) test -v $(TEST_FLAGS) -coverprofile=cover.out pkg/... + $(GO) test -v $(TEST_FLAGS) -coverprofile=cover.out ./pkg/* $(GO) tool cover -func=cover.out $(GO) tool cover -html=cover.out -o coverage.html coverweb: - $(GO) test -v $(TEST_FLAGS) -coverprofile=cover.out pkg/... + $(GO) test -v $(TEST_FLAGS) -coverprofile=cover.out ./pkg/* $(GO) tool cover -html=cover.out clean: @@ -192,6 +192,8 @@ golangci: tools # golangci combines a few static code analyzer # See https://github.com/golangci/golangci-lint # + @which golangci-lint + @golangci-lint version @set -e; for dir in $$(ls -1d pkg/* cmd); do \ echo $$dir; \ echo " - GOOS=linux"; \ diff --git a/cmd/nagflux/main.go b/cmd/nagflux/main.go index 66d9b9b..34b3551 100644 --- a/cmd/nagflux/main.go +++ b/cmd/nagflux/main.go @@ -1,8 +1,6 @@ package main -import ( - "pkg/nagflux" -) +import "github.com/ConSol-Monitoring/nagflux/pkg/nagflux" // Build contains the current git commit id // compile passing -ldflags "-X main.Build " to set the id. diff --git a/config.gcfg.example b/config.gcfg.example index 03d7783..3883530 100644 --- a/config.gcfg.example +++ b/config.gcfg.example @@ -68,6 +68,10 @@ Folder = "/var/spool/nagios" # This option takes predence over Main.NagiosSpoolfileWorker if set WorkerCount = 1 + PerfdataLabelMaxLength = 32 + PerfdataUOMMaxLength = 16 + PerfdataNumericValuesMaxLength = 32 + PerfdataThresholdsMaxLength = 64 [NagfluxSpoolfile] Enabled = true diff --git a/go.mod b/go.mod index e61737c..f8c3aa8 100644 --- a/go.mod +++ b/go.mod @@ -1,29 +1,33 @@ module github.com/ConSol-Monitoring/nagflux -go 1.25.7 +go 1.26.1 -replace pkg/nagflux => ./pkg/nagflux - -require pkg/nagflux v0.0.0-00010101000000-000000000000 +require ( + github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273 + github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038 + github.com/prometheus/client_golang v1.23.2 + github.com/stretchr/testify v1.11.1 + gopkg.in/gcfg.v1 v1.2.3 +) require ( - github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273 // indirect + github.com/appscode/go v0.0.0-20201105063637-5613f3b8169f // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/golang/glog v1.2.1 // indirect - github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/prometheus/client_golang v1.23.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.67.4 // indirect - github.com/prometheus/procfs v0.19.2 // indirect - go.yaml.in/yaml/v2 v2.4.3 // indirect - golang.org/x/sys v0.38.0 // indirect - google.golang.org/protobuf v1.36.10 // indirect - gopkg.in/gcfg.v1 v1.2.3 // indirect + github.com/prometheus/common v0.67.5 // indirect + github.com/prometheus/procfs v0.20.1 // indirect + go.yaml.in/yaml/v2 v2.4.4 // indirect + golang.org/x/sys v0.42.0 // indirect + google.golang.org/protobuf v1.36.11 // indirect gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2204d5d..636aee8 100644 --- a/go.sum +++ b/go.sum @@ -2,18 +2,34 @@ github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273 h1:Jweb6qie+w0ybSXG9jr github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273/go.mod h1:FseN9KxcgJsFW92Y7JhTk5qWF0KBfwy2t8WfKL6t+hQ= github.com/appscode/go v0.0.0-20201105063637-5613f3b8169f h1:heDuWjdnY2rJIgLwIQjWPgOc0BUWWX6OGOeB+0t8v/s= github.com/appscode/go v0.0.0-20201105063637-5613f3b8169f/go.mod h1:piHRpQ9+NTTuV3V98INxjU7o2KlAJMznaxvB6wHKkfU= +github.com/beevik/ntp v0.3.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20200712050446-30169cf553fe/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +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/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= -github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038 h1:ah2n2FwhELUb5o+KV0zAw8izxYC6UdK6dzjOKr3hfA8= github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038/go.mod h1:vLeQHWaOMUQZ1ytnCskhwI5fCcXA7xxK0QjCngYPqbo= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= @@ -24,37 +40,61 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.67.4 h1:yR3NqWO1/UyO1w2PhUvXlGQs/PtFmoveVO0KZ4+Lvsc= -github.com/prometheus/common v0.67.4/go.mod h1:gP0fq6YjjNCLssJCQp0yk4M8W6ikLURwkdd/YKtTbyI= -github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws= -github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw= +github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4= +github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw= +github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc= +github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= -go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= +go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= +go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= -golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= -google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +gomodules.xyz/password-generator v0.2.4/go.mod h1:TvwYYTx9+P1pPwKQKfZgB/wr2Id9MqAQ3B5auY7reNg= +gomodules.xyz/version v0.1.0/go.mod h1:Y8xuV02mL/45psyPKG3NCVOwvAOy6T5Kx0l3rCjKSjU= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -64,5 +104,7 @@ gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 h1:E846t8CnR+lv5nE+Vu gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5/go.mod h1:hiOFpYm0ZJbusNj2ywpbrXowU3G8U6GIQzqn2mw1UIE= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/pkg/nagflux/collector/Filterable.go b/pkg/collector/Filterable.go similarity index 100% rename from pkg/nagflux/collector/Filterable.go rename to pkg/collector/Filterable.go diff --git a/pkg/nagflux/collector/Filterable_test.go b/pkg/collector/Filterable_test.go similarity index 100% rename from pkg/nagflux/collector/Filterable_test.go rename to pkg/collector/Filterable_test.go diff --git a/pkg/nagflux/collector/IPrintable.go b/pkg/collector/IPrintable.go similarity index 100% rename from pkg/nagflux/collector/IPrintable.go rename to pkg/collector/IPrintable.go diff --git a/pkg/nagflux/collector/ResultQueues.go b/pkg/collector/ResultQueues.go similarity index 55% rename from pkg/nagflux/collector/ResultQueues.go rename to pkg/collector/ResultQueues.go index b878413..d803c13 100644 --- a/pkg/nagflux/collector/ResultQueues.go +++ b/pkg/collector/ResultQueues.go @@ -1,5 +1,5 @@ package collector -import "pkg/nagflux/data" +import "github.com/ConSol-Monitoring/nagflux/pkg/data" type ResultQueues map[data.Target]chan Printable diff --git a/pkg/nagflux/collector/SimplePrintable.go b/pkg/collector/SimplePrintable.go similarity index 90% rename from pkg/nagflux/collector/SimplePrintable.go rename to pkg/collector/SimplePrintable.go index 62fefb1..600b934 100644 --- a/pkg/nagflux/collector/SimplePrintable.go +++ b/pkg/collector/SimplePrintable.go @@ -1,6 +1,6 @@ package collector -import "pkg/nagflux/data" +import "github.com/ConSol-Monitoring/nagflux/pkg/data" // SimplePrintable can be used to send strings as printable type SimplePrintable struct { diff --git a/pkg/nagflux/collector/livestatus/Cache.go b/pkg/collector/livestatus/Cache.go similarity index 100% rename from pkg/nagflux/collector/livestatus/Cache.go rename to pkg/collector/livestatus/Cache.go diff --git a/pkg/nagflux/collector/livestatus/CacheBuilder.go b/pkg/collector/livestatus/CacheBuilder.go similarity index 98% rename from pkg/nagflux/collector/livestatus/CacheBuilder.go rename to pkg/collector/livestatus/CacheBuilder.go index cc412f5..abd56a1 100644 --- a/pkg/nagflux/collector/livestatus/CacheBuilder.go +++ b/pkg/collector/livestatus/CacheBuilder.go @@ -6,9 +6,8 @@ import ( "sync" "time" - "pkg/nagflux/config" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/collector/livestatus/CacheBuilder_test.go b/pkg/collector/livestatus/CacheBuilder_test.go similarity index 97% rename from pkg/nagflux/collector/livestatus/CacheBuilder_test.go rename to pkg/collector/livestatus/CacheBuilder_test.go index 320ef6a..47d2c4f 100644 --- a/pkg/nagflux/collector/livestatus/CacheBuilder_test.go +++ b/pkg/collector/livestatus/CacheBuilder_test.go @@ -4,8 +4,7 @@ import ( "testing" "time" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/nagflux/collector/livestatus/Cache_test.go b/pkg/collector/livestatus/Cache_test.go similarity index 100% rename from pkg/nagflux/collector/livestatus/Cache_test.go rename to pkg/collector/livestatus/Cache_test.go diff --git a/pkg/nagflux/collector/livestatus/Collector.go b/pkg/collector/livestatus/Collector.go similarity index 96% rename from pkg/nagflux/collector/livestatus/Collector.go rename to pkg/collector/livestatus/Collector.go index 0411e60..dea5d5c 100644 --- a/pkg/nagflux/collector/livestatus/Collector.go +++ b/pkg/collector/livestatus/Collector.go @@ -6,13 +6,12 @@ import ( "strings" "time" - "pkg/nagflux/collector" - "pkg/nagflux/config" - "pkg/nagflux/data" - "pkg/nagflux/filter" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/data" + "github.com/ConSol-Monitoring/nagflux/pkg/filter" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/collector/livestatus/Collector_test.go b/pkg/collector/livestatus/Collector_test.go similarity index 89% rename from pkg/nagflux/collector/livestatus/Collector_test.go rename to pkg/collector/livestatus/Collector_test.go index b57ea11..543a3ff 100644 --- a/pkg/nagflux/collector/livestatus/Collector_test.go +++ b/pkg/collector/livestatus/Collector_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "pkg/nagflux/collector" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) func TestNewLivestatusCollector(t *testing.T) { diff --git a/pkg/nagflux/collector/livestatus/CommentData.go b/pkg/collector/livestatus/CommentData.go similarity index 90% rename from pkg/nagflux/collector/livestatus/CommentData.go rename to pkg/collector/livestatus/CommentData.go index cfd03a5..cab1b22 100644 --- a/pkg/nagflux/collector/livestatus/CommentData.go +++ b/pkg/collector/livestatus/CommentData.go @@ -1,9 +1,9 @@ package livestatus import ( - "pkg/nagflux/collector" - "pkg/nagflux/helper" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) // CommentData adds Comments types to the livestatus data diff --git a/pkg/nagflux/collector/livestatus/CommentData_test.go b/pkg/collector/livestatus/CommentData_test.go similarity index 97% rename from pkg/nagflux/collector/livestatus/CommentData_test.go rename to pkg/collector/livestatus/CommentData_test.go index 153c849..fc2a76f 100644 --- a/pkg/nagflux/collector/livestatus/CommentData_test.go +++ b/pkg/collector/livestatus/CommentData_test.go @@ -3,8 +3,8 @@ package livestatus import ( "testing" - "pkg/nagflux/config" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) var PrintCommentData = []struct { diff --git a/pkg/nagflux/collector/livestatus/Connector.go b/pkg/collector/livestatus/Connector.go similarity index 100% rename from pkg/nagflux/collector/livestatus/Connector.go rename to pkg/collector/livestatus/Connector.go diff --git a/pkg/nagflux/collector/livestatus/Connector_test.go b/pkg/collector/livestatus/Connector_test.go similarity index 96% rename from pkg/nagflux/collector/livestatus/Connector_test.go rename to pkg/collector/livestatus/Connector_test.go index ec2c931..b3cf552 100644 --- a/pkg/nagflux/collector/livestatus/Connector_test.go +++ b/pkg/collector/livestatus/Connector_test.go @@ -9,9 +9,8 @@ import ( "testing" "time" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/stretchr/testify/assert" ) diff --git a/pkg/nagflux/collector/livestatus/Data.go b/pkg/collector/livestatus/Data.go similarity index 95% rename from pkg/nagflux/collector/livestatus/Data.go rename to pkg/collector/livestatus/Data.go index 5e02869..43b8ccc 100644 --- a/pkg/nagflux/collector/livestatus/Data.go +++ b/pkg/collector/livestatus/Data.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "pkg/nagflux/config" - "pkg/nagflux/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" ) // Data contains basic data extracted from livestatusqueries. diff --git a/pkg/nagflux/collector/livestatus/Data_test.go b/pkg/collector/livestatus/Data_test.go similarity index 96% rename from pkg/nagflux/collector/livestatus/Data_test.go rename to pkg/collector/livestatus/Data_test.go index f67e400..daff428 100644 --- a/pkg/nagflux/collector/livestatus/Data_test.go +++ b/pkg/collector/livestatus/Data_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "pkg/nagflux/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" ) func TestDataSanitizeValues(t *testing.T) { diff --git a/pkg/nagflux/collector/livestatus/DowntimeData.go b/pkg/collector/livestatus/DowntimeData.go similarity index 92% rename from pkg/nagflux/collector/livestatus/DowntimeData.go rename to pkg/collector/livestatus/DowntimeData.go index 7bebc90..f4a44f1 100644 --- a/pkg/nagflux/collector/livestatus/DowntimeData.go +++ b/pkg/collector/livestatus/DowntimeData.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "pkg/nagflux/collector" - "pkg/nagflux/helper" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) // DowntimeData adds Comments types to the livestatus data diff --git a/pkg/nagflux/collector/livestatus/DowntimeData_test.go b/pkg/collector/livestatus/DowntimeData_test.go similarity index 95% rename from pkg/nagflux/collector/livestatus/DowntimeData_test.go rename to pkg/collector/livestatus/DowntimeData_test.go index 48e907f..74f6fd7 100644 --- a/pkg/nagflux/collector/livestatus/DowntimeData_test.go +++ b/pkg/collector/livestatus/DowntimeData_test.go @@ -3,9 +3,8 @@ package livestatus import ( "testing" - "pkg/nagflux/config" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/stretchr/testify/assert" ) diff --git a/pkg/nagflux/collector/livestatus/NotificationData.go b/pkg/collector/livestatus/NotificationData.go similarity index 93% rename from pkg/nagflux/collector/livestatus/NotificationData.go rename to pkg/collector/livestatus/NotificationData.go index 53a9ba0..975f04a 100644 --- a/pkg/nagflux/collector/livestatus/NotificationData.go +++ b/pkg/collector/livestatus/NotificationData.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "pkg/nagflux/collector" - "pkg/nagflux/helper" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) // NotificationData adds notification types to the livestatus data diff --git a/pkg/nagflux/collector/livestatus/NotificationData_test.go b/pkg/collector/livestatus/NotificationData_test.go similarity index 98% rename from pkg/nagflux/collector/livestatus/NotificationData_test.go rename to pkg/collector/livestatus/NotificationData_test.go index 3b82434..062c2f7 100644 --- a/pkg/nagflux/collector/livestatus/NotificationData_test.go +++ b/pkg/collector/livestatus/NotificationData_test.go @@ -3,8 +3,8 @@ package livestatus import ( "testing" - "pkg/nagflux/config" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) func TestSanitizeValuesNotification(t *testing.T) { diff --git a/pkg/nagflux/collector/modgearman/gearmanWorker.go b/pkg/collector/modgearman/gearmanWorker.go similarity index 88% rename from pkg/nagflux/collector/modgearman/gearmanWorker.go rename to pkg/collector/modgearman/gearmanWorker.go index 01cf8a0..3360718 100644 --- a/pkg/nagflux/collector/modgearman/gearmanWorker.go +++ b/pkg/collector/modgearman/gearmanWorker.go @@ -4,15 +4,14 @@ import ( "fmt" "time" - "pkg/nagflux/collector" - "pkg/nagflux/collector/livestatus" - "pkg/nagflux/collector/spoolfile" - "pkg/nagflux/config" - "pkg/nagflux/filter" - "pkg/nagflux/helper" - "pkg/nagflux/helper/cryptohelper" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/livestatus" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/spoolfile" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/filter" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/helper/cryptohelper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" libworker "github.com/appscode/g2/worker" "github.com/kdar/factorlog" ) @@ -53,8 +52,7 @@ func NewGearmanWorker(address, queue, key string, results collector.ResultQueues pauseQuit: make(chan bool, 1), results: results, nagiosSpoolfileWorker: spoolfile.NewNagiosSpoolfileWorker( - -1, make(chan string), make(collector.ResultQueues), livestatusCacheBuilder, 4096, collector.AllFilterable, - ), + -1, make(chan string), make(collector.ResultQueues), livestatusCacheBuilder, 4096, collector.AllFilterable, spoolfile.PerfdataLabelMaxLengthDefault, spoolfile.PerfdataUOMMaxLengthDefault, spoolfile.PerfdataNumericValuesMaxLengthDefault, spoolfile.PerfdataThresholdsMaxLengthDefault), aesECBDecrypter: decrypter, worker: nil, address: address, diff --git a/pkg/nagflux/collector/modgearman/secret.go b/pkg/collector/modgearman/secret.go similarity index 100% rename from pkg/nagflux/collector/modgearman/secret.go rename to pkg/collector/modgearman/secret.go diff --git a/pkg/nagflux/collector/nagflux/NagfluxPrintable.go b/pkg/collector/nagflux/NagfluxPrintable.go similarity index 91% rename from pkg/nagflux/collector/nagflux/NagfluxPrintable.go rename to pkg/collector/nagflux/NagfluxPrintable.go index 5e0ca66..415522e 100644 --- a/pkg/nagflux/collector/nagflux/NagfluxPrintable.go +++ b/pkg/collector/nagflux/NagfluxPrintable.go @@ -3,8 +3,8 @@ package nagflux import ( "fmt" - "pkg/nagflux/collector" - "pkg/nagflux/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" ) // Printable converts from nagfluxfile format to X diff --git a/pkg/nagflux/collector/nagflux/dumpfileCollector.go b/pkg/collector/nagflux/dumpfileCollector.go similarity index 95% rename from pkg/nagflux/collector/nagflux/dumpfileCollector.go rename to pkg/collector/nagflux/dumpfileCollector.go index f0960aa..7cf00a9 100644 --- a/pkg/nagflux/collector/nagflux/dumpfileCollector.go +++ b/pkg/collector/nagflux/dumpfileCollector.go @@ -8,10 +8,9 @@ import ( "os" "time" - "pkg/nagflux/collector" - "pkg/nagflux/data" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/data" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go b/pkg/collector/nagflux/nagfluxFileCollector.go similarity index 93% rename from pkg/nagflux/collector/nagflux/nagfluxFileCollector.go rename to pkg/collector/nagflux/nagfluxFileCollector.go index 64c2924..ae32bd8 100644 --- a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go +++ b/pkg/collector/nagflux/nagfluxFileCollector.go @@ -5,12 +5,11 @@ import ( "os" "time" - "pkg/nagflux/collector" - "pkg/nagflux/collector/spoolfile" - "pkg/nagflux/config" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/spoolfile" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/kdar/factorlog" ) diff --git a/pkg/collector/spoolfile/nagiosSpoolfileCollector.go b/pkg/collector/spoolfile/nagiosSpoolfileCollector.go new file mode 100644 index 0000000..a2624d8 --- /dev/null +++ b/pkg/collector/spoolfile/nagiosSpoolfileCollector.go @@ -0,0 +1,196 @@ +package spoolfile + +import ( + "errors" + "os" + "path" + "time" + + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/livestatus" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/statistics" +) + +const ( + // MinFileAge is the duration to wait, before the files are parsed + MinFileAge = 3 * time.Second + + // IntervalToCheckDirectory the interval to check if there are new files + IntervalToCheckDirectory = 1500 * time.Millisecond + + // PerfdataLabelMaxLengthDefault: If a perfdata label is longer than this, it will be logged as an anomaly and skipped + PerfdataLabelMaxLengthDefault = int(32) + + // PerfdataUOMMaxLengthDefault: If a perfdata UOM is longer than this, it will be logged as an anomaly and skipped + PerfdataUOMMaxLengthDefault = int(16) + + // PerfdataNumericValuesMaxLengthDefault: If a perfdata numeric value, e.g current value, min, and max is longer than this, it will be logged as an anomaly and skipped + // Reasoning: Largest uint64 is 20 characters wide, floats are not printed with too much precision either + PerfdataNumericValuesMaxLengthDefault = int(32) + + // PerfdataThresholdsMaxLengthDefault: If a perfdata numeric value, e.g current value, min, and max is longer than this, it will be logged as an anomaly and skipped + // Reasoning: Twice the numeric value max length, since there are seperators as well + PerfdataThresholdsMaxLengthDefault = int(64) +) + +// NagiosSpoolfileCollector scans the nagios spoolfile folder and delegates the files to its workers. +type NagiosSpoolfileCollector struct { + quit chan bool + jobs chan string + spoolDirectory string + workers []*NagiosSpoolfileWorker +} + +// NagiosSpoolfileCollectorFactory creates the give amount of Woker and starts them. +func NagiosSpoolfileCollectorFactory(cfg config.Config, results collector.ResultQueues, + livestatusCacheBuilder *livestatus.CacheBuilder, fileBufferSize int, defaultTarget collector.Filterable, +) (*NagiosSpoolfileCollector, error) { + search, found := helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.Folder", []string{"Main.NagiosSpoolfileFolder"}) + if !found { + return nil, errors.New("could not find a config value for Nagios Spoolfile Folder") + } + + spoolDirectoryPtr, ok := search.(*string) + if !ok { + return nil, errors.New("expected a *string value out of the config value for Nagios Spoolfile Folder") + } + spoolDirectory := *(spoolDirectoryPtr) + + search, found = helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.WorkerCount", []string{"Main.NagiosSpoolfileWorker"}) + if !found { + return nil, errors.New("could not find a config value for Nagios Spoolfile Worker Count") + } + + workerAmountPtr, ok := search.(*int) + if !ok { + return nil, errors.New("expected a *int value out of the config value for Nagios Spoolfile Worker Count") + } + workerAmount := *(workerAmountPtr) + + perfdataLabelMaxLength := PerfdataLabelMaxLengthDefault + search, found = helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.PerfdataLabelMaxLength", []string{}) + if found { + perfdataLabelMaxLengthPtr, ok := search.(*int) + if ok { + perfdataLabelMaxLength = *(perfdataLabelMaxLengthPtr) + } else { + return nil, errors.New("expected a *int value out of the config value for Nagios Spoolfile Perfdata Label Max Length") + } + } + + perfdataUOMMaxLength := PerfdataUOMMaxLengthDefault + search, found = helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.PerfdataUOMMaxLength", []string{}) + if found { + perfdataUOMMaxLengthPtr, ok := search.(*int) + if ok { + perfdataUOMMaxLength = *(perfdataUOMMaxLengthPtr) + } else { + return nil, errors.New("expected a *int value out of the config value for Nagios Spoolfile Perfdata UOM Max Length") + } + } + + perfdataNumericValuesMaxLength := PerfdataNumericValuesMaxLengthDefault + search, found = helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.PerfdataNumericValuesMaxLength", []string{}) + if found { + perfdataNumericValuesMaxLengthPtr, ok := search.(*int) + if ok { + perfdataNumericValuesMaxLength = *(perfdataNumericValuesMaxLengthPtr) + } else { + return nil, errors.New("expected a *int value out of the config value for Nagios Spoolfile Perfdata UOM Max Length") + } + } + + perfdataThresholdsMaxLength := PerfdataThresholdsMaxLengthDefault + search, found = helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.PerfdataThresholdsMaxLength", []string{}) + if found { + perfdataThresholdsMaxLengthPtr, ok := search.(*int) + if ok { + perfdataThresholdsMaxLength = *(perfdataThresholdsMaxLengthPtr) + } else { + return nil, errors.New("expected a *int value out of the config value for Nagios Spoolfile Perfdata Thresholds Max Length") + } + } + + s := &NagiosSpoolfileCollector{ + quit: make(chan bool), + jobs: make(chan string, 100), + spoolDirectory: spoolDirectory, + workers: make([]*NagiosSpoolfileWorker, workerAmount), + } + + gen := NagiosSpoolfileWorkerGenerator(s.jobs, results, livestatusCacheBuilder, fileBufferSize, defaultTarget, perfdataLabelMaxLength, perfdataUOMMaxLength, perfdataNumericValuesMaxLength, perfdataThresholdsMaxLength) + + for w := range workerAmount { + s.workers[w] = gen() + } + + go s.run() + return s, nil +} + +// Stop stops his workers and itself. +func (s *NagiosSpoolfileCollector) Stop() { + s.quit <- true + <-s.quit + for _, worker := range s.workers { + worker.Stop() + } + logging.GetLogger().Debug("SpoolfileCollector stopped") +} + +// Delegates the files to its workers. +func (s *NagiosSpoolfileCollector) run() { + promServer := statistics.GetPrometheusServer() + for { + select { + case <-s.quit: + s.quit <- true + return + case <-time.After(IntervalToCheckDirectory): + pause := config.IsAnyTargetOnPause() + if pause { + logging.GetLogger().Debugln("NagiosSpoolfileCollector in pause") + continue + } + + logging.GetLogger().Debug("Reading Directory: ", s.spoolDirectory) + oldFiles, totalFiles := FilesInDirectoryOlderThanX(s.spoolDirectory, MinFileAge) + promServer.SpoolFilesOnDisk.Set(float64(totalFiles)) + for _, currentFile := range oldFiles { + logging.GetLogger().Debug("Reading file: ", currentFile) + + select { + case <-s.quit: + s.quit <- true + return + case s.jobs <- currentFile: + case <-time.After(time.Duration(1) * time.Minute): + logging.GetLogger().Warn("NagiosSpoolfileCollector: Could not write to buffer") + } + } + } + } +} + +// FilesInDirectoryOlderThanX returns a list of file, of a folder, names which are older then a certain duration. +func FilesInDirectoryOlderThanX(folder string, age time.Duration) (oldFiles []string, totalFiles int) { + files, _ := os.ReadDir(folder) + for _, currentFile := range files { + fsinfo, err := currentFile.Info() + if err != nil { + continue + } + if IsItTime(fsinfo.ModTime(), age) { + oldFiles = append(oldFiles, path.Join(folder, currentFile.Name())) + } + } + return oldFiles, len(files) +} + +// IsItTime checks if the timestamp plus duration is in the past. +func IsItTime(timeStamp time.Time, duration time.Duration) bool { + return time.Now().After(timeStamp.Add(duration)) +} diff --git a/pkg/collector/spoolfile/nagiosSpoolfileWorker.go b/pkg/collector/spoolfile/nagiosSpoolfileWorker.go new file mode 100644 index 0000000..f988a6e --- /dev/null +++ b/pkg/collector/spoolfile/nagiosSpoolfileWorker.go @@ -0,0 +1,527 @@ +package spoolfile + +import ( + "bufio" + "errors" + "fmt" + "io" + "os" + "regexp" + "strconv" + "strings" + "time" + + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/livestatus" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/filter" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/statistics" + "github.com/kdar/factorlog" +) + +const ( + nagfluxTags string = "NAGFLUX:TAG" + nagfluxField string = "NAGFLUX:FIELD" + nagfluxTarget string = "NAGFLUX:TARGET" + + hostPerfdata string = "HOSTPERFDATA" + + servicePerfdata string = "SERVICEPERFDATA" + + hostType string = "HOST" + serviceType string = "SERVICE" + + hostname string = "HOSTNAME" + timet string = "TIMET" + checkcommand string = "CHECKCOMMAND" + servicedesc string = "SERVICEDESC" +) + +var ( + // Start at the line, match anything that has two consecutive columns. + // First capture group is before the colon and the second is after the column. + checkMulitRegex = regexp.MustCompile(`^(.*::)(.*)`) + + // Digit, point or dash in a group, repeat this once or more + // This idea is to get how many numbers, possibly negative, are in a string + rangeRegex = regexp.MustCompile(`[\d\.\-]+`) + + // https://regex101.com/r/wNeesp/1 + // Read this as well if you are new to monitoring plugins output. + // https://www.monitoring-plugins.org/doc/guidelines.html#AEN197 + // https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT + // 1st Capture Group: ([^=]+) + // Anything without an '=' sign , at least one repeating + // Idea: It captures the name of the perfdata + // A literal '=' + // Required in a perfdata string, helps to capture anything before it as the name + // 2nd Capture Group: (U|[\d\.\,\-]+) + // There are two options here + // 1. Either a literal 'U'. + // Means "Unknown". This is used by plugins to indicate that it could not get performance data for some reason. + // Writing 'U' is better than not including it, which would mean its unavailable. + // 2. [\d\.,\-]+ + // '\d' is for digits, '\.' is a literal point, '\,' is a literal comma, '\-' is a literal dash i.e negative sign. Repat any of these one or more times. + // Idea: This captures the current value of the perfdata, which should be some kind of number, possibly negative as well. Examples: '123' '24.5' '-54,2' + // 3rd Capture Group: ([\pL\/\%]*) + // '\pL' matches any kind of letter in any language. '\/' matches a literal forward slash, '\%' matches a literal percentage sign. Repeat any of it zero or more times. + // Idea: This captures the Unit of Measurement for the current value. + // Might be empty since the raw value might be enough. Forward slash is used for rate. Examples: '' 's' 'ms' 'B' 'KB' '%' 'B/s' '/s' + // A literal ';'. Zero or Once. Semicolons are used as seperators between different fields in a perfdata. + // Idea: Perfdata might only have the current value, and does not report, warning, critical, min, max and other values. + // 4rd Capture Group: ([\d\.\,\-\:\~\@]*) + // Literal digits, point, comma, dash, colon, tilde, at sign. Colon and at sign is used in range definitions. Tilde is used when specifying ranges for negative infinity + // Repeat this capture group zero or one time. + // Idea: These are the threshold definitions for warning threshold. It does not have to be set + // A literal ';'. Zero or Once. Semicolons are used as seperators between different fields in a perfdata. + // 5th Capture Group: ([\d\.\,\-\:\~\@]*) + // Same as 4th capture group, but it is for critical threshold this time + // A literal ';'. Zero or Once. Semicolons are used as seperators between different fields in a perfdata. + // 6th Capture Group: ([\d\.\,\-]*) + // Similar to the 2nd capture group, but it might be repeated zero or more times instead, as this field may be empty + // Idea: Used for the min value so far. It does not need an Unit of Measurement or might be specified as a range like a threshold. Therefore it is simpler + // A literal ';'. Zero or Once. Semicolons are used as seperators between different fields in a perfdata. + // 7th Capture Group: ([\d\.\,\-]*) + // Same as 6th capture group, but it is for the maximum value this time. + // '\s' matches any whitespace character, infinite times. + // Idea: It separates different perf data values as this must be matched new capture group can be captured + // Overall this script will detect a perfdata in Nagios syntax + regexPerformancelable = regexp.MustCompile(`([^=]+)=(U|[\d\.\,\-]+)([\pL\/\%]*);?([\d\.\,\-\:\~\@]*)?;?([\d\.\,\-\:\~\@]*)?;?([\d\.\,\-]*)?;?([\d\.\,\-]*)?;?\s*`) + + // The perfdata part might have some alternative check at the end, recognize it by it being at the end and only containing letters, '_', '-' + // The check name will be in the capture group. + // This convention is not found in monitoring-plugins development guidelines + regexAlternativeCommand = regexp.MustCompile(`.*\[([a-zA-Z\_\-\.\ ]+)\]\s?$`) + + // The perfdata part might report errors for different data + // it has to put them in square brackets first, and use an equal sign for the error + // This is to differentiate it from alternative command, which does not have an equal sign. + // This convention is not found in monitoring-plugins development guidelines + regexStripErrors = regexp.MustCompile(`\[[^\]]*=[^\]]*\]`) +) + +var log *factorlog.FactorLog = logging.GetLogger() + +// NagiosSpoolfileWorker parses the given spoolfiles and adds the extraced perfdata to the queue. +type NagiosSpoolfileWorker struct { + workerID int + quit chan bool + jobs chan string + results collector.ResultQueues + livestatusCacheBuilder *livestatus.CacheBuilder + fileBufferSize int + defaultTarget collector.Filterable + filterProcessor filter.Processor + perfdataLabelMaxSize int + perfdataUOMMaxLength int + perfdataNumericValuesMaxLength int + perfdataThresholdsMaxLength int +} + +// NewNagiosSpoolfileWorker returns a new NagiosSpoolfileWorker. +func NewNagiosSpoolfileWorker(workerID int, jobs chan string, results collector.ResultQueues, + livestatusCacheBuilder *livestatus.CacheBuilder, fileBufferSize int, defaultTarget collector.Filterable, perfdataLabelMaxLength int, perfdataUOMMaxLength int, perfdataNumericValuesMaxLength int, perfdataThresholdsMaxLength int, +) *NagiosSpoolfileWorker { + cfg := config.GetConfig() + return &NagiosSpoolfileWorker{ + workerID: workerID, + quit: make(chan bool), + jobs: jobs, + results: results, + livestatusCacheBuilder: livestatusCacheBuilder, + fileBufferSize: fileBufferSize, + defaultTarget: defaultTarget, + filterProcessor: filter.NewFilter(cfg.Filter.SpoolFileLineTerms), + perfdataLabelMaxSize: perfdataLabelMaxLength, + perfdataUOMMaxLength: perfdataUOMMaxLength, + perfdataNumericValuesMaxLength: perfdataNumericValuesMaxLength, + perfdataThresholdsMaxLength: perfdataThresholdsMaxLength, + } +} + +// NagiosSpoolfileWorkerGenerator generates a worker and starts it. +func NagiosSpoolfileWorkerGenerator(jobs chan string, results collector.ResultQueues, + livestatusCacheBuilder *livestatus.CacheBuilder, fileBufferSize int, defaultTarget collector.Filterable, perfdataLabelMaxLength int, perfdataUOMMaxLength int, perfdataNumericValuesMaxLength int, perfdataThresholdsMaxLength int, +) func() *NagiosSpoolfileWorker { + workerID := 0 + return func() *NagiosSpoolfileWorker { + s := NewNagiosSpoolfileWorker(workerID, jobs, results, livestatusCacheBuilder, fileBufferSize, defaultTarget, perfdataLabelMaxLength, perfdataUOMMaxLength, perfdataNumericValuesMaxLength, perfdataThresholdsMaxLength) + workerID++ + go s.run() + return s + } +} + +// Stop stops the worker +func (w *NagiosSpoolfileWorker) Stop() { + w.quit <- true + <-w.quit + log.Debug("SpoolfileWorker stopped") +} + +// Waits for files to parse and sends the data to the main queue. +func (w *NagiosSpoolfileWorker) run() { + promServer := statistics.GetPrometheusServer() + var file string + for { + select { + case <-w.quit: + w.quit <- true + return + case file = <-w.jobs: + promServer.SpoolFilesInQueue.Set(float64(len(w.jobs))) + startTime := time.Now() + log.Debug("Reading file: ", file) + + filehandle, err := os.OpenFile(file, os.O_RDONLY, os.ModePerm) + if err != nil { + log.Warn("NagiosSpoolfileWorker: Opening file error: ", err) + break + } + reader := bufio.NewReaderSize(filehandle, w.fileBufferSize) + queries := 0 + line, isPrefix, err := reader.ReadLine() + for err == nil && !isPrefix { + splittedPerformanceData := helper.StringToMap(string(line), "\t", "::") + if skipLine := w.filterProcessor.TestLine(line); !skipLine { + log.Debugf("skipping line %s", string(line)) + + line, isPrefix, err = reader.ReadLine() + continue + } + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + for _, r := range w.results { + select { + case <-w.quit: + w.quit <- true + return + case r <- singlePerfdata: + queries++ + case <-time.After(time.Duration(10) * time.Second): + log.Warn("NagiosSpoolfileWorker: Could not write to buffer") + } + } + } + line, isPrefix, err = reader.ReadLine() + } + if err != nil && err != io.EOF { + log.Warn(err) + } + if isPrefix { + log.Warn("NagiosSpoolfileWorker: filebuffer is too small") + } + filehandle.Close() + err = os.Remove(file) + if err != nil { + log.Warn(err) + } + timeDiff := float64(time.Since(startTime).Nanoseconds() / 1000000) + if timeDiff >= 0 { + promServer.SpoolFilesParsedDuration.Add(timeDiff) + } + if queries >= 0 { + promServer.SpoolFilesLines.Add(float64(queries)) + } + case <-time.After(time.Duration(5) * time.Minute): + log.Debug("NagiosSpoolfileWorker: Got nothing to do") + } + } +} + +// PerformanceDataIterator returns an iterator to loop over generated perf data. +// +//nolint:maintidx // the lambda inside has to check all fields of the performance data, adds a lot of branching code +func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string) <-chan *PerformanceData { + ch := make(chan *PerformanceData) + dataType := findDataType(input) + if dataType == "" { + if len(input) > 1 { + log.Info("Line does not match the scheme: ", input) + } + close(ch) + return ch + } + + currentCommand := w.searchAlternativeCommand(input[dataType+"PERFDATA"], input[dataType+checkcommand]) + currentTime := helper.CastStringTimeFromSToMs(input[timet]) + currentService := "" + + if dataType != hostType { + currentService = input[servicedesc] + } + + // anonymous closure, starts immediately after definition in another goroutine without blocking + go func() { + perfdataString := input[dataType+"PERFDATA"] + perfdataStringErrorsRemoved := regexStripErrors.ReplaceAllString(perfdataString, "") + + // Slices up the string into a form like this + // Each match is put into an array with their capture groups + // These arrays are put into another array + // Example: [][]string len: 4, cap: 10, [ + // ["rta=0.024ms;3000.000;5000.000;0; ","rta","0.024","ms","3000.000","5000.000","0",""], + // ["rtmax=0.085ms;;;; ","rtmax","0.085","ms","","","",""], + // ["rtmin=0.000ms;;;; ","rtmin","0.000","ms","","","",""], + // ["pl=0%;80;100;0;100","pl","0","%","80","100","0","100"] + // ] + perfdataStringMatches := regexPerformancelable.FindAllStringSubmatch(perfdataStringErrorsRemoved, -1) + currentCheckMultiLabel := "" + + // try to find a check_multi prefix + if len(perfdataStringMatches) > 0 && len(perfdataStringMatches[0]) > 1 { + currentCheckMultiLabel = getCheckMultiRegexMatch(perfdataStringMatches[0][1]) + } + + // check if concataneting matches makes up the original string + matchesConcatenatedBuilder := strings.Builder{} + for _, matchAndCaptureGroups := range perfdataStringMatches { + match := matchAndCaptureGroups[0] + _, err := matchesConcatenatedBuilder.WriteString(match) + if err != nil { + log.Warnf("Error when building the matchesConcaatenated string: %s", err.Error()) + close(ch) + return + } + } + matchesConcatenated := matchesConcatenatedBuilder.String() + + if len(matchesConcatenated) > 0 && strings.TrimSpace(matchesConcatenated) != strings.TrimSpace(perfdataString) { + log.Warnf("Perfdata matches: '%v' when concatanted come up to be: '%s', and original perfdata string is: '%s' . They are not equal after stripping whitespace from both", perfdataStringMatches, matchesConcatenated, perfdataString) + close(ch) + return + } + + for _, perfdataStringMatch := range perfdataStringMatches { + // Allows to add tags and fields to spoolfileentries + tags := map[string]string{} + if tagString, ok := input[nagfluxTags]; ok { + tags = helper.StringToMap(tagString, " ", "=") + } + field := map[string]string{} + if fieldString, ok := input[nagfluxField]; ok { + field = helper.StringToMap(fieldString, " ", "=") + } + var target collector.Filterable + if targetString, ok := input[nagfluxTarget]; ok { + target = collector.Filterable{Filter: targetString} + } else { + target = collector.AllFilterable + } + + perf := &PerformanceData{ + Hostname: input[hostname], + Service: currentService, + Command: currentCommand, + Time: currentTime, + PerformanceLabel: perfdataStringMatch[Label], + Unit: perfdataStringMatch[UOM], + Tags: tags, + Fields: field, + Filterable: target, + } + + if currentCheckMultiLabel != "" { + // if an check_multi prefix was found last time, test if the current one has also one + if potentialNextOne := getCheckMultiRegexMatch(perf.PerformanceLabel); potentialNextOne == "" { + // if not put the last one in front the current + perf.PerformanceLabel = currentCheckMultiLabel + perf.PerformanceLabel + } else { + // else remember the current prefix for the next one + currentCheckMultiLabel = potentialNextOne + } + } + + // perfdataStringMatch might not have all fields like perfdataStringMatch[Crit] available, iterate each field until the end + for i, data := range perfdataStringMatch { + fieldType, err := indexToPerformanceDataSliceField(i) + if err != nil { + log.Warnf("Error when converting the index to a known field in performance data : %s", err.Error()) + goto perfdataStringMatchLoopEnd + } + + switch fieldType { + case RawMatch: + case Label: + if len(data) > w.perfdataLabelMaxSize { + log.Warnf("Perfdata Label: '%s' is too long with length: %d and longer than the limit: %d. Probably an anomally. Skipping this perfdata item, Host: %v , Service: %v, Perfdata fields: %v", data, len(data), w.perfdataLabelMaxSize, perf.Hostname, perf.Service, perfdataStringMatch) + goto perfdataStringMatchLoopEnd + } + case UOM: + if len(data) > w.perfdataUOMMaxLength { + log.Warnf("Perfdata UOM: '%s' is too long with length: %d and longer than the limit: %d. Probably an anomally. Host: %v , Service: %v, Perfdata fields: %v", data, len(data), w.perfdataUOMMaxLength, perf.Hostname, perf.Service, perfdataStringMatch) + goto perfdataStringMatchLoopEnd + } + case Value, Min, Max: + if len(data) > w.perfdataNumericValuesMaxLength { + log.Warnf("Perfdata field %s: '%s' is too long with length: %d and longer than the limit: %d. Probably an anomally. Host: %v , Service: %v, Perfdata fields: %v", fieldType.String(), data, len(data), w.perfdataNumericValuesMaxLength, perf.Hostname, perf.Service, perfdataStringMatch) + goto perfdataStringMatchLoopEnd + } + case Warn, Crit: + if len(data) > w.perfdataThresholdsMaxLength { + log.Warnf("Perfdata field %s: '%s' is too long with length: %d and longer than the limit: %d. Probably an anomally. Host: %v , Service: %v, Perfdata fields: %v", fieldType.String(), data, len(data), w.perfdataThresholdsMaxLength, perf.Hostname, perf.Service, perfdataStringMatch) + goto perfdataStringMatchLoopEnd + } + } + + if data == "" { + continue + } + // Anything after here is a number or a range, so convert all commas to points to help in the integer/float parsing + data = strings.ReplaceAll(data, ",", ".") + + // Add downtime tag if needed + if fieldType == Value && w.livestatusCacheBuilder != nil && w.livestatusCacheBuilder.IsServiceInDowntime(perf.Hostname, perf.Service, input[timet]) { + perf.Tags["downtime"] = "true" + } + + switch fieldType { + case Warn, Crit: + // Range handling + fillLabel := fieldType.String() + "-fill" + // find how many numbers are there in the string, if there are two it is a range + rangeHits := rangeRegex.FindAllStringSubmatch(data, -1) + if len(rangeHits) == 1 { + perf.Tags[fillLabel] = "none" + perf.Fields[fieldType.String()] = helper.StringIntToStringFloat(rangeHits[0][0]) + } else if len(rangeHits) == 2 { + // If there is a range with no infinity as border, create two points + if strings.Contains(data, "@") { + perf.Tags[fillLabel] = "inner" + } else { + perf.Tags[fillLabel] = "outer" + } + for i, tag := range []string{"min", "max"} { + tagKey := fmt.Sprintf("%s-%s", fieldType.String(), tag) + perf.Fields[tagKey] = helper.StringIntToStringFloat(rangeHits[i][0]) + } + } else { + log.Warnf("String: '%s' in field '%s' could not be parsed. Host: %v, Service: %v, Perf Data Fields: %v", data, fieldType.String(), perf.Hostname, perf.Service, perfdataStringMatch) + goto perfdataStringMatchLoopEnd + } + case Value, Min, Max: + if data == "U" { + perf.Fields["unknown"] = "true" + continue + } + if !helper.IsStringANumber(data) { + log.Warnf("String: '%s' in field '%s' is not a number, should be one. Host: %v, Service: %v, Perf Data Fields: %v", data, fieldType.String(), perf.Hostname, perf.Service, perfdataStringMatch) + goto perfdataStringMatchLoopEnd + } + perf.Fields[fieldType.String()] = helper.StringIntToStringFloat(data) + case RawMatch, Label, UOM: + } + } + + ch <- perf + + perfdataStringMatchLoopEnd: // To skip item without sending it to the channel + } + close(ch) + }() + + return ch +} + +func getCheckMultiRegexMatch(perfDataValueName string) string { + regexResult := checkMulitRegex.FindAllStringSubmatch(perfDataValueName, -1) + if len(regexResult) == 1 && len(regexResult[0]) == 3 { + return regexResult[0][1] + } + return "" +} + +func findDataType(input map[string]string) string { + var typ string + if isHostPerformanceData(input) { + typ = hostType + } else if isServicePerformanceData(input) { + typ = serviceType + } + return typ +} + +// searchAlternativeCommand looks for alternative command name in perfdata +func (w *NagiosSpoolfileWorker) searchAlternativeCommand(perfData, command string) string { + result := command + search := regexAlternativeCommand.FindAllStringSubmatch(perfData, 1) + if len(search) == 1 && len(search[0]) == 2 { + result = search[0][1] + } + return splitCommandInput(result) +} + +// Cuts the command at the first !. +func splitCommandInput(command string) string { + return strings.Split(command, "!")[0] +} + +// Tests if perfdata is of type hostperfdata. +func isHostPerformanceData(input map[string]string) bool { + return input["DATATYPE"] == hostPerfdata +} + +// Tests if perfdata is of type serviceperfdata. +func isServicePerformanceData(input map[string]string) bool { + return input["DATATYPE"] == servicePerfdata +} + +type PerformanceDataSliceFields int + +const ( + RawMatch PerformanceDataSliceFields = iota + Label + Value + UOM + Warn + Crit + Min + Max +) + +// Converts the index of the sliced perftype to an string. +func indexToPerformanceDataSliceField(index int) (PerformanceDataSliceFields, error) { + switch index { + case 0: + return RawMatch, nil + case 1: + return Label, nil + case 2: + return Value, nil + case 3: + return UOM, nil + case 4: + return Warn, nil + case 5: + return Crit, nil + case 6: + return Min, nil + case 7: + return Max, nil + default: + return 0, errors.New("Illegal index: " + strconv.Itoa(index)) + } +} + +// String returns the string representation of a PerformanceType +func (pt PerformanceDataSliceFields) String() string { + switch pt { + case RawMatch: + return "rawMatch" + case Label: + return "name" + case Value: + return "value" + case Warn: + return "warn" + case Crit: + return "crit" + case Min: + return "min" + case Max: + return "max" + default: + return "" + } +} diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go b/pkg/collector/spoolfile/nagiosSpoolfileWorker_test.go similarity index 54% rename from pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go rename to pkg/collector/spoolfile/nagiosSpoolfileWorker_test.go index 0a736d5..a1dd9cb 100644 --- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker_test.go +++ b/pkg/collector/spoolfile/nagiosSpoolfileWorker_test.go @@ -3,10 +3,9 @@ package spoolfile import ( "testing" - "pkg/nagflux/collector" - "pkg/nagflux/config" - "pkg/nagflux/helper" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" "github.com/stretchr/testify/assert" ) @@ -14,6 +13,12 @@ const configFileContent = ` [Filter] SpoolFileLineTerms = check-host-alive + +[NagiosSpoolfile] + PerfdataLabelMaxLength = 32 + PerfdataUOMMaxLength = 16 + PerfdataNumericValuesMaxLength = 32 + PerfdataThresholdsMaxLength = 64 ` func TestPerformanceDataParser_01(t *testing.T) { @@ -432,13 +437,282 @@ func testPerformanceDataParser(t *testing.T, input string, expect []PerformanceD config.InitConfigFromString(configFileContent) - w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable) + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) splittedPerformanceData := helper.StringToMap(input, "\t", "::") - //nolint:prealloc // do not know the size of the iterable collectedPerfData := []PerformanceData{} for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { collectedPerfData = append(collectedPerfData, *singlePerfdata) } assert.Equalf(t, expect, collectedPerfData, "performance data matches") } + +func TestPerformanceDataParser_LongPerformanceLabel(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'i_am_a_very_long_performance_label_exceeding_the_default_limit_for_performance_labels_yeah'=35512320B;;;; SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long label, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_LongValue(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'label'=123456789123456789123456789123456789;;;; SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length value, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_LongUOM(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + // If you use underscores in the uom, it gets split out and only the first part is taken. + // UOM is deliberately written without underscores here + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'label'=1iamaverylonguomthatshouldberejected;;;; SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length unit of measurement, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_LongWarnTrehsold(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'label'=1;123456789123456789123456789123456789:123456789123456789123456789123456789;;; SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of warning threshold, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_LongCritTrehsold(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + // If you use underscores in the uom, it gets split out and only the first part is taken. + // UOM is deliberately written without underscores here + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'label'=1;;123456789123456789123456789123456789:123456789123456789123456789123456789;; SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of critical threshold, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_LongMinValue(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'label'=1;;;123456789123456789123456789123456789; SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of minimum value, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_LongMaxValue(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::'label'=1;;;;123456789123456789123456789123456789 SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of maximum value, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata1(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::passme=1 failme=1;1:2;3:4;5;6-hello-i-am-garbage-string-that-should-be-detected-as-i-am-not-whitespace SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of maximum value, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata2(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::passme=1 failme=1;1:2;3:4;5;6-garbage foo bar xyz=3;4afvdv23 SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of maximum value, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata3(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::xyz=3;45afv SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken into the performance data due to long length of maximum value, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata4(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::label=1;2;label2 SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken it contains garbage data, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata5(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::asd label=1;2; other=1;3;4asdasdasd SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken it contains garbage data, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata6(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::asd label=1;2; other=1;3;4asdasdasd [anza=ffgg] [si signo=11] 'valid[1]'=5 [si_errno=0] [si_code=1] SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken it contains garbage data, splittedPerformanceData: %v", splittedPerformanceData) +} + +func TestPerformanceDataParser_GarbageStringAfterPerfdata7(t *testing.T) { + t.Helper() + + config.InitConfigFromString(configFileContent) + + w := NewNagiosSpoolfileWorker(0, nil, nil, nil, 4096, collector.AllFilterable, PerfdataLabelMaxLengthDefault, PerfdataUOMMaxLengthDefault, PerfdataNumericValuesMaxLengthDefault, PerfdataThresholdsMaxLengthDefault) + + splittedPerformanceData := helper.StringToMap( + "DATATYPE::SERVICEPERFDATA TIMET::1441791000 HOSTNAME::xxx SERVICEDESC::range SERVICEPERFDATA::asd label=1;2; other=1;3;4asdasdasd [anza=ffgg] [si signo=11] 'valid[1]'=5 [si_errno=0] [si_code=1]fasdgew SERVICECHECKCOMMAND::check_dummy SERVICESTATE::0 SERVICESTATETYPE::1", + "\t", "::") + + collectedPerfData := []PerformanceData{} + for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { + collectedPerfData = append(collectedPerfData, *singlePerfdata) + } + + assert.Emptyf(t, collectedPerfData, "Item should not be taken it contains garbage data, splittedPerformanceData: %v", splittedPerformanceData) +} diff --git a/pkg/nagflux/collector/spoolfile/performanceData.go b/pkg/collector/spoolfile/performanceData.go similarity index 93% rename from pkg/nagflux/collector/spoolfile/performanceData.go rename to pkg/collector/spoolfile/performanceData.go index 7478dff..0bd81ef 100644 --- a/pkg/nagflux/collector/spoolfile/performanceData.go +++ b/pkg/collector/spoolfile/performanceData.go @@ -3,9 +3,9 @@ package spoolfile import ( "fmt" - "pkg/nagflux/collector" - "pkg/nagflux/config" - "pkg/nagflux/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" ) // PerformanceData represents the nagios perfdata diff --git a/pkg/nagflux/config/Config.go b/pkg/config/Config.go similarity index 82% rename from pkg/nagflux/config/Config.go rename to pkg/config/Config.go index f623371..3c74054 100644 --- a/pkg/nagflux/config/Config.go +++ b/pkg/config/Config.go @@ -70,7 +70,11 @@ type Config struct { // This option takes predence over Main.NagiosSpoolfileFolder if set Folder *string // This option takes predence over Main.NagiosSpoolfileWorker if set - WorkerCount *int + WorkerCount *int + PerfdataLabelMaxLength *int // Log errors and skip perfdata if perfdata label length is longer than this length + PerfdataUOMMaxLength *int // Log errors and skip perfdata if perfdata Unit of Measurement length is longer than this length + PerfdataNumericValuesMaxLength *int // Log errors and skip perfdata if perfdata current value, min or max strings are longer than this length + PerfdataThresholdsMaxLength *int // Log errors and skip perfdata if perfdata warn/crit threshold strings are longer than this length } NagfluxSpoolfile struct { Enabled *bool diff --git a/pkg/nagflux/config/ConfigProvider.go b/pkg/config/ConfigProvider.go similarity index 100% rename from pkg/nagflux/config/ConfigProvider.go rename to pkg/config/ConfigProvider.go diff --git a/pkg/nagflux/config/ConfigProvider_test.go b/pkg/config/ConfigProvider_test.go similarity index 100% rename from pkg/nagflux/config/ConfigProvider_test.go rename to pkg/config/ConfigProvider_test.go diff --git a/pkg/nagflux/config/GlobalObjects.go b/pkg/config/GlobalObjects.go similarity index 92% rename from pkg/nagflux/config/GlobalObjects.go rename to pkg/config/GlobalObjects.go index c704dc8..89bb469 100644 --- a/pkg/nagflux/config/GlobalObjects.go +++ b/pkg/config/GlobalObjects.go @@ -3,7 +3,7 @@ package config import ( "sync" - "pkg/nagflux/data" + "github.com/ConSol-Monitoring/nagflux/pkg/data" ) // PauseMap is a map to store if an target requested pause or not diff --git a/pkg/nagflux/config/GlobalObjects_test.go b/pkg/config/GlobalObjects_test.go similarity index 92% rename from pkg/nagflux/config/GlobalObjects_test.go rename to pkg/config/GlobalObjects_test.go index d13447f..63f9516 100644 --- a/pkg/nagflux/config/GlobalObjects_test.go +++ b/pkg/config/GlobalObjects_test.go @@ -3,7 +3,7 @@ package config import ( "testing" - "pkg/nagflux/data" + "github.com/ConSol-Monitoring/nagflux/pkg/data" ) func TestStoreValue(t *testing.T) { diff --git a/pkg/nagflux/data/Datatype.go b/pkg/data/Datatype.go similarity index 100% rename from pkg/nagflux/data/Datatype.go rename to pkg/data/Datatype.go diff --git a/pkg/nagflux/data/Target.go b/pkg/data/Target.go similarity index 100% rename from pkg/nagflux/data/Target.go rename to pkg/data/Target.go diff --git a/pkg/nagflux/filter/Filter.go b/pkg/filter/Filter.go similarity index 95% rename from pkg/nagflux/filter/Filter.go rename to pkg/filter/Filter.go index cf54f30..f567b46 100644 --- a/pkg/nagflux/filter/Filter.go +++ b/pkg/filter/Filter.go @@ -5,7 +5,7 @@ import ( "strings" "sync" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) type Processor struct { diff --git a/pkg/nagflux/filter/Filter_test.go b/pkg/filter/Filter_test.go similarity index 91% rename from pkg/nagflux/filter/Filter_test.go rename to pkg/filter/Filter_test.go index 6634ed1..f5e8637 100644 --- a/pkg/nagflux/filter/Filter_test.go +++ b/pkg/filter/Filter_test.go @@ -3,9 +3,8 @@ package filter import ( "testing" - "pkg/nagflux/config" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/stretchr/testify/assert" ) diff --git a/pkg/nagflux/helper/config_helper.go b/pkg/helper/config_helper.go similarity index 89% rename from pkg/nagflux/helper/config_helper.go rename to pkg/helper/config_helper.go index 7eed945..0d1995c 100644 --- a/pkg/nagflux/helper/config_helper.go +++ b/pkg/helper/config_helper.go @@ -4,16 +4,17 @@ import ( "reflect" "strings" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) -// Config parser tries to populate the Config structy type with values from config file -// If the Config has a field, but config file does not specify it, it will be default initialized -// If the Config has a field that is a pointer to a type +// Config parser tries to populate the Config struct with values from config file +// If the Config struct has a field, but config file does not specify it, it will be default initialized +// If the Config struct has a field that is a pointer to a type, there are two options // Option 1: Config file has it -> the pointer will point to an instance of that type // Option 2: Config file does not have it -> the pointer will be set to nil -// This way we can determine if something is explicitly set in the config -// But the type of that value has to be a pointer, like *bool or *string +// This way we can determine if something is explicitly set in the config or unspecified +// But the type of that value has to be a pointer, like *bool or *string. +// It cant be a primitive non-pointer type like int. Those will be default initialized // GetPreferredConfigValue retrieves a value from a struct using a dot-separated path. // It takes a primaryPath and other deprecatedPaths. If a value is found on the mainPath, it notifies the user about deprecatedPaths diff --git a/pkg/nagflux/helper/cryptohelper/aes-ecb.go b/pkg/helper/cryptohelper/aes-ecb.go similarity index 100% rename from pkg/nagflux/helper/cryptohelper/aes-ecb.go rename to pkg/helper/cryptohelper/aes-ecb.go diff --git a/pkg/nagflux/helper/cryptohelper/aes-ecb_test.go b/pkg/helper/cryptohelper/aes-ecb_test.go similarity index 100% rename from pkg/nagflux/helper/cryptohelper/aes-ecb_test.go rename to pkg/helper/cryptohelper/aes-ecb_test.go diff --git a/pkg/nagflux/helper/elastic.go b/pkg/helper/elastic.go similarity index 90% rename from pkg/nagflux/helper/elastic.go rename to pkg/helper/elastic.go index 45a0b3a..4b32357 100644 --- a/pkg/nagflux/helper/elastic.go +++ b/pkg/helper/elastic.go @@ -4,14 +4,14 @@ import ( "fmt" "strings" - "pkg/nagflux/config" + "github.com/ConSol-Monitoring/nagflux/pkg/config" ) // CreateJSONFromStringMap creates a part of a JSON object func CreateJSONFromStringMap(input map[string]string) string { str := strings.Builder{} for k, v := range input { - str.WriteString(fmt.Sprintf(`,%s:%s`, GenJSONValueString(k), GenJSONValueString(v))) + fmt.Fprintf(&str, ",%s:%s", GenJSONValueString(k), GenJSONValueString(v)) } return str.String() } diff --git a/pkg/nagflux/helper/elastic_test.go b/pkg/helper/elastic_test.go similarity index 98% rename from pkg/nagflux/helper/elastic_test.go rename to pkg/helper/elastic_test.go index 887b5d0..ed9c4dd 100644 --- a/pkg/nagflux/helper/elastic_test.go +++ b/pkg/helper/elastic_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "pkg/nagflux/config" + "github.com/ConSol-Monitoring/nagflux/pkg/config" ) var CreateJSONFromStringMapData = []struct { diff --git a/pkg/nagflux/helper/http.go b/pkg/helper/http.go similarity index 100% rename from pkg/nagflux/helper/http.go rename to pkg/helper/http.go diff --git a/pkg/nagflux/helper/influx.go b/pkg/helper/influx.go similarity index 94% rename from pkg/nagflux/helper/influx.go rename to pkg/helper/influx.go index 2bd4c91..b99df5a 100644 --- a/pkg/nagflux/helper/influx.go +++ b/pkg/helper/influx.go @@ -3,7 +3,7 @@ package helper import ( "strings" - "pkg/nagflux/config" + "github.com/ConSol-Monitoring/nagflux/pkg/config" ) // SanitizeInfluxInput adds backslashes to special chars. diff --git a/pkg/nagflux/helper/influx_test.go b/pkg/helper/influx_test.go similarity index 96% rename from pkg/nagflux/helper/influx_test.go rename to pkg/helper/influx_test.go index 80ffb84..d837684 100644 --- a/pkg/nagflux/helper/influx_test.go +++ b/pkg/helper/influx_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "pkg/nagflux/config" + "github.com/ConSol-Monitoring/nagflux/pkg/config" ) var SanitizeInfluxData = []struct { diff --git a/pkg/nagflux/helper/map.go b/pkg/helper/map.go similarity index 100% rename from pkg/nagflux/helper/map.go rename to pkg/helper/map.go diff --git a/pkg/nagflux/helper/map_test.go b/pkg/helper/map_test.go similarity index 100% rename from pkg/nagflux/helper/map_test.go rename to pkg/helper/map_test.go diff --git a/pkg/nagflux/helper/slice.go b/pkg/helper/slice.go similarity index 100% rename from pkg/nagflux/helper/slice.go rename to pkg/helper/slice.go diff --git a/pkg/nagflux/helper/slice_test.go b/pkg/helper/slice_test.go similarity index 100% rename from pkg/nagflux/helper/slice_test.go rename to pkg/helper/slice_test.go diff --git a/pkg/nagflux/helper/string.go b/pkg/helper/string.go similarity index 98% rename from pkg/nagflux/helper/string.go rename to pkg/helper/string.go index a8e0987..2647690 100644 --- a/pkg/nagflux/helper/string.go +++ b/pkg/helper/string.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "pkg/nagflux/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" ) // IsStringANumber returns true if the given string can be casted to int or float. diff --git a/pkg/nagflux/helper/string_test.go b/pkg/helper/string_test.go similarity index 100% rename from pkg/nagflux/helper/string_test.go rename to pkg/helper/string_test.go diff --git a/pkg/nagflux/helper/tcp.go b/pkg/helper/tcp.go similarity index 100% rename from pkg/nagflux/helper/tcp.go rename to pkg/helper/tcp.go diff --git a/pkg/nagflux/helper/tcp_test.go b/pkg/helper/tcp_test.go similarity index 100% rename from pkg/nagflux/helper/tcp_test.go rename to pkg/helper/tcp_test.go diff --git a/pkg/nagflux/logging/logging.go b/pkg/logging/logging.go similarity index 100% rename from pkg/nagflux/logging/logging.go rename to pkg/logging/logging.go diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go deleted file mode 100644 index a16dd5d..0000000 --- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go +++ /dev/null @@ -1,114 +0,0 @@ -package spoolfile - -import ( - "os" - "path" - "time" - - "pkg/nagflux/collector" - "pkg/nagflux/collector/livestatus" - "pkg/nagflux/config" - "pkg/nagflux/logging" - "pkg/nagflux/statistics" -) - -const ( - // MinFileAge is the duration to wait, before the files are parsed - MinFileAge = 3 * time.Second - - // IntervalToCheckDirectory the interval to check if there are new files - IntervalToCheckDirectory = 1500 * time.Millisecond -) - -// NagiosSpoolfileCollector scans the nagios spoolfile folder and delegates the files to its workers. -type NagiosSpoolfileCollector struct { - quit chan bool - jobs chan string - spoolDirectory string - workers []*NagiosSpoolfileWorker -} - -// NagiosSpoolfileCollectorFactory creates the give amount of Woker and starts them. -func NagiosSpoolfileCollectorFactory(spoolDirectory string, workerAmount int, results collector.ResultQueues, - livestatusCacheBuilder *livestatus.CacheBuilder, fileBufferSize int, defaultTarget collector.Filterable, -) *NagiosSpoolfileCollector { - s := &NagiosSpoolfileCollector{ - quit: make(chan bool), - jobs: make(chan string, 100), - spoolDirectory: spoolDirectory, - workers: make([]*NagiosSpoolfileWorker, workerAmount), - } - - gen := NagiosSpoolfileWorkerGenerator(s.jobs, results, livestatusCacheBuilder, fileBufferSize, defaultTarget) - - for w := range workerAmount { - s.workers[w] = gen() - } - - go s.run() - return s -} - -// Stop stops his workers and itself. -func (s *NagiosSpoolfileCollector) Stop() { - s.quit <- true - <-s.quit - for _, worker := range s.workers { - worker.Stop() - } - logging.GetLogger().Debug("SpoolfileCollector stopped") -} - -// Delegates the files to its workers. -func (s *NagiosSpoolfileCollector) run() { - promServer := statistics.GetPrometheusServer() - for { - select { - case <-s.quit: - s.quit <- true - return - case <-time.After(IntervalToCheckDirectory): - pause := config.IsAnyTargetOnPause() - if pause { - logging.GetLogger().Debugln("NagiosSpoolfileCollector in pause") - continue - } - - logging.GetLogger().Debug("Reading Directory: ", s.spoolDirectory) - oldFiles, totalFiles := FilesInDirectoryOlderThanX(s.spoolDirectory, MinFileAge) - promServer.SpoolFilesOnDisk.Set(float64(totalFiles)) - for _, currentFile := range oldFiles { - logging.GetLogger().Debug("Reading file: ", currentFile) - - select { - case <-s.quit: - s.quit <- true - return - case s.jobs <- currentFile: - case <-time.After(time.Duration(1) * time.Minute): - logging.GetLogger().Warn("NagiosSpoolfileCollector: Could not write to buffer") - } - } - } - } -} - -// FilesInDirectoryOlderThanX returns a list of file, of a folder, names which are older then a certain duration. -func FilesInDirectoryOlderThanX(folder string, age time.Duration) (oldFiles []string, totalFiles int) { - files, _ := os.ReadDir(folder) - for _, currentFile := range files { - fsinfo, err := currentFile.Info() - if err != nil { - continue - } - if IsItTime(fsinfo.ModTime(), age) { - oldFiles = append(oldFiles, path.Join(folder, currentFile.Name())) - } - } - return oldFiles, len(files) -} - -// IsItTime checks if the timestamp plus duration is in the past. -func IsItTime(timeStamp time.Time, duration time.Duration) bool { - return time.Now().After(timeStamp.Add(duration)) -} diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go deleted file mode 100644 index 4f3c8f0..0000000 --- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go +++ /dev/null @@ -1,352 +0,0 @@ -package spoolfile - -import ( - "bufio" - "errors" - "fmt" - "io" - "os" - "regexp" - "strconv" - "strings" - "time" - - "pkg/nagflux/collector" - "pkg/nagflux/collector/livestatus" - "pkg/nagflux/config" - "pkg/nagflux/filter" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - "pkg/nagflux/statistics" -) - -const ( - nagfluxTags string = "NAGFLUX:TAG" - nagfluxField string = "NAGFLUX:FIELD" - nagfluxTarget string = "NAGFLUX:TARGET" - - hostPerfdata string = "HOSTPERFDATA" - - servicePerfdata string = "SERVICEPERFDATA" - - hostType string = "HOST" - serviceType string = "SERVICE" - - hostname string = "HOSTNAME" - timet string = "TIMET" - checkcommand string = "CHECKCOMMAND" - servicedesc string = "SERVICEDESC" -) - -var ( - checkMulitRegex = regexp.MustCompile(`^(.*::)(.*)`) - rangeRegex = regexp.MustCompile(`[\d\.\-]+`) - regexPerformancelable = regexp.MustCompile(`([^=]+)=(U|[\d\.,\-]+)([\pL\/%]*);?([\d\.,\-:~@]*)?;?([\d\.,\-:~@]*)?;?([\d\.,\-]*)?;?([\d\.,\-]*)?;?\s*`) - regexAltCommand = regexp.MustCompile(`.*\[([a-zA-Z_\-. ]+)\]\s?$`) - regexStripErrors = regexp.MustCompile(`\[[^\]]*=[^\]]*\]`) -) - -// NagiosSpoolfileWorker parses the given spoolfiles and adds the extraced perfdata to the queue. -type NagiosSpoolfileWorker struct { - workerID int - quit chan bool - jobs chan string - results collector.ResultQueues - livestatusCacheBuilder *livestatus.CacheBuilder - fileBufferSize int - defaultTarget collector.Filterable - filterProcessor filter.Processor -} - -// NewNagiosSpoolfileWorker returns a new NagiosSpoolfileWorker. -func NewNagiosSpoolfileWorker(workerID int, jobs chan string, results collector.ResultQueues, - livestatusCacheBuilder *livestatus.CacheBuilder, fileBufferSize int, defaultTarget collector.Filterable, -) *NagiosSpoolfileWorker { - cfg := config.GetConfig() - return &NagiosSpoolfileWorker{ - workerID: workerID, - quit: make(chan bool), - jobs: jobs, - results: results, - livestatusCacheBuilder: livestatusCacheBuilder, - fileBufferSize: fileBufferSize, - defaultTarget: defaultTarget, - filterProcessor: filter.NewFilter(cfg.Filter.SpoolFileLineTerms), - } -} - -// NagiosSpoolfileWorkerGenerator generates a worker and starts it. -func NagiosSpoolfileWorkerGenerator(jobs chan string, results collector.ResultQueues, - livestatusCacheBuilder *livestatus.CacheBuilder, fileBufferSize int, defaultTarget collector.Filterable, -) func() *NagiosSpoolfileWorker { - workerID := 0 - return func() *NagiosSpoolfileWorker { - s := NewNagiosSpoolfileWorker(workerID, jobs, results, livestatusCacheBuilder, fileBufferSize, defaultTarget) - workerID++ - go s.run() - return s - } -} - -// Stop stops the worker -func (w *NagiosSpoolfileWorker) Stop() { - w.quit <- true - <-w.quit - logging.GetLogger().Debug("SpoolfileWorker stopped") -} - -// Waits for files to parse and sends the data to the main queue. -func (w *NagiosSpoolfileWorker) run() { - promServer := statistics.GetPrometheusServer() - var file string - for { - select { - case <-w.quit: - w.quit <- true - return - case file = <-w.jobs: - promServer.SpoolFilesInQueue.Set(float64(len(w.jobs))) - startTime := time.Now() - logging.GetLogger().Debug("Reading file: ", file) - - filehandle, err := os.OpenFile(file, os.O_RDONLY, os.ModePerm) - if err != nil { - logging.GetLogger().Warn("NagiosSpoolfileWorker: Opening file error: ", err) - break - } - reader := bufio.NewReaderSize(filehandle, w.fileBufferSize) - queries := 0 - line, isPrefix, err := reader.ReadLine() - for err == nil && !isPrefix { - splittedPerformanceData := helper.StringToMap(string(line), "\t", "::") - if skipLine := w.filterProcessor.TestLine(line); !skipLine { - logging.GetLogger().Debugf("skipping line %s", string(line)) - - line, isPrefix, err = reader.ReadLine() - continue - } - for singlePerfdata := range w.PerformanceDataIterator(splittedPerformanceData) { - for _, r := range w.results { - select { - case <-w.quit: - w.quit <- true - return - case r <- singlePerfdata: - queries++ - case <-time.After(time.Duration(10) * time.Second): - logging.GetLogger().Warn("NagiosSpoolfileWorker: Could not write to buffer") - } - } - } - line, isPrefix, err = reader.ReadLine() - } - if err != nil && err != io.EOF { - logging.GetLogger().Warn(err) - } - if isPrefix { - logging.GetLogger().Warn("NagiosSpoolfileWorker: filebuffer is too small") - } - filehandle.Close() - err = os.Remove(file) - if err != nil { - logging.GetLogger().Warn(err) - } - timeDiff := float64(time.Since(startTime).Nanoseconds() / 1000000) - if timeDiff >= 0 { - promServer.SpoolFilesParsedDuration.Add(timeDiff) - } - if queries >= 0 { - promServer.SpoolFilesLines.Add(float64(queries)) - } - case <-time.After(time.Duration(5) * time.Minute): - logging.GetLogger().Debug("NagiosSpoolfileWorker: Got nothing to do") - } - } -} - -// PerformanceDataIterator returns an iterator to loop over generated perf data. -func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string) <-chan *PerformanceData { - ch := make(chan *PerformanceData) - typ := findType(input) - if typ == "" { - if len(input) > 1 { - logging.GetLogger().Info("Line does not match the scheme: ", input) - } - close(ch) - return ch - } - - currentCommand := w.searchAltCommand(input[typ+"PERFDATA"], input[typ+checkcommand]) - currentTime := helper.CastStringTimeFromSToMs(input[timet]) - currentService := "" - if typ != hostType { - currentService = input[servicedesc] - } - - go func() { - raw := input[typ+"PERFDATA"] - cleaned := regexStripErrors.ReplaceAllString(raw, "") - perfSlice := regexPerformancelable.FindAllStringSubmatch(cleaned, -1) - currentCheckMultiLabel := "" - // try to find a check_multi prefix - if len(perfSlice) > 0 && len(perfSlice[0]) > 1 { - currentCheckMultiLabel = getCheckMultiRegexMatch(perfSlice[0][1]) - } - - item: - for _, value := range perfSlice { - // Allows to add tags and fields to spoolfileentries - tag := map[string]string{} - if tagString, ok := input[nagfluxTags]; ok { - tag = helper.StringToMap(tagString, " ", "=") - } - field := map[string]string{} - if fieldString, ok := input[nagfluxField]; ok { - field = helper.StringToMap(fieldString, " ", "=") - } - var target collector.Filterable - if targetString, ok := input[nagfluxTarget]; ok { - target = collector.Filterable{Filter: targetString} - } else { - target = collector.AllFilterable - } - - perf := &PerformanceData{ - Hostname: input[hostname], - Service: currentService, - Command: currentCommand, - Time: currentTime, - PerformanceLabel: value[1], - Unit: value[3], - Tags: tag, - Fields: field, - Filterable: target, - } - - if currentCheckMultiLabel != "" { - // if an check_multi prefix was found last time - // test if the current one has also one - if potentialNextOne := getCheckMultiRegexMatch(perf.PerformanceLabel); potentialNextOne == "" { - // if not put the last one in front the current - perf.PerformanceLabel = currentCheckMultiLabel + perf.PerformanceLabel - } else { - // else remember the current prefix for the next one - currentCheckMultiLabel = potentialNextOne - } - } - - for i, data := range value { - data = strings.ReplaceAll(data, ",", ".") - if i > 1 && i != 3 && data != "" { - performanceType, err := indexToperformanceType(i) - if err != nil { - logging.GetLogger().Warn(err, value) - continue - } - - // Add downtime tag if needed - if performanceType == "value" && w.livestatusCacheBuilder != nil && w.livestatusCacheBuilder.IsServiceInDowntime(perf.Hostname, perf.Service, input[timet]) { - perf.Tags["downtime"] = "true" - } - - if performanceType == "warn" || performanceType == "crit" { - // Range handling - fillLabel := performanceType + "-fill" - rangeHits := rangeRegex.FindAllStringSubmatch(data, -1) - if len(rangeHits) == 1 { - perf.Tags[fillLabel] = "none" - perf.Fields[performanceType] = helper.StringIntToStringFloat(rangeHits[0][0]) - } else if len(rangeHits) == 2 { - // If there is a range with no infinity as border, create two points - if strings.Contains(data, "@") { - perf.Tags[fillLabel] = "inner" - } else { - perf.Tags[fillLabel] = "outer" - } - - for i, tag := range []string{"min", "max"} { - tagKey := fmt.Sprintf("%s-%s", performanceType, tag) - perf.Fields[tagKey] = helper.StringIntToStringFloat(rangeHits[i][0]) - } - } else { - logging.GetLogger().Warnf("Could not parse warn/crit value. Host: %v, Service: %v, Element: %v, Wholedata: %v", perf.Hostname, perf.Service, data, value) - } - } else { - if data == "U" { - perf.Fields["unknown"] = "true" - continue - } - if !helper.IsStringANumber(data) { - continue item - } - perf.Fields[performanceType] = helper.StringIntToStringFloat(data) - } - } - } - ch <- perf - } - close(ch) - }() - return ch -} - -func getCheckMultiRegexMatch(perfData string) string { - regexResult := checkMulitRegex.FindAllStringSubmatch(perfData, -1) - if len(regexResult) == 1 && len(regexResult[0]) == 3 { - return regexResult[0][1] - } - return "" -} - -func findType(input map[string]string) string { - var typ string - if isHostPerformanceData(input) { - typ = hostType - } else if isServicePerformanceData(input) { - typ = serviceType - } - return typ -} - -// searchAltCommand looks for alternative command name in perfdata -func (w *NagiosSpoolfileWorker) searchAltCommand(perfData, command string) string { - result := command - search := regexAltCommand.FindAllStringSubmatch(perfData, 1) - if len(search) == 1 && len(search[0]) == 2 { - result = search[0][1] - } - return splitCommandInput(result) -} - -// Cuts the command at the first !. -func splitCommandInput(command string) string { - return strings.Split(command, "!")[0] -} - -// Tests if perfdata is of type hostperfdata. -func isHostPerformanceData(input map[string]string) bool { - return input["DATATYPE"] == hostPerfdata -} - -// Tests if perfdata is of type serviceperfdata. -func isServicePerformanceData(input map[string]string) bool { - return input["DATATYPE"] == servicePerfdata -} - -// Converts the index of the perftype to an string. -func indexToperformanceType(index int) (string, error) { - switch index { - case 2: - return "value", nil - case 4: - return "warn", nil - case 5: - return "crit", nil - case 6: - return "min", nil - case 7: - return "max", nil - default: - return "", errors.New("Illegale index: " + strconv.Itoa(index)) - } -} diff --git a/pkg/nagflux/go.mod b/pkg/nagflux/go.mod deleted file mode 100644 index 40f2400..0000000 --- a/pkg/nagflux/go.mod +++ /dev/null @@ -1,36 +0,0 @@ -module nagflux - -go 1.25.7 - -replace pkg/nagflux => . - -require ( - github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273 - github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038 - github.com/prometheus/client_golang v1.23.2 - github.com/stretchr/testify v1.11.1 - gopkg.in/gcfg.v1 v1.2.3 - pkg/nagflux v0.0.0-00010101000000-000000000000 -) - -require ( - github.com/appscode/go v0.0.0-20201105063637-5613f3b8169f // indirect - github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/kr/text v0.2.0 // indirect - github.com/mattn/go-colorable v0.1.14 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.67.4 // indirect - github.com/prometheus/procfs v0.19.2 // indirect - go.yaml.in/yaml/v2 v2.4.3 // indirect - golang.org/x/sys v0.38.0 // indirect - google.golang.org/protobuf v1.36.10 // indirect - gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 // indirect - gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/pkg/nagflux/go.sum b/pkg/nagflux/go.sum deleted file mode 100644 index 492b0a4..0000000 --- a/pkg/nagflux/go.sum +++ /dev/null @@ -1,110 +0,0 @@ -github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273 h1:Jweb6qie+w0ybSXG9jrfQHCIoXSEHeoU/Sa1opJj22s= -github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273/go.mod h1:FseN9KxcgJsFW92Y7JhTk5qWF0KBfwy2t8WfKL6t+hQ= -github.com/appscode/go v0.0.0-20201105063637-5613f3b8169f h1:heDuWjdnY2rJIgLwIQjWPgOc0BUWWX6OGOeB+0t8v/s= -github.com/appscode/go v0.0.0-20201105063637-5613f3b8169f/go.mod h1:piHRpQ9+NTTuV3V98INxjU7o2KlAJMznaxvB6wHKkfU= -github.com/beevik/ntp v0.3.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= -github.com/codeskyblue/go-sh v0.0.0-20200712050446-30169cf553fe/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -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/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038 h1:ah2n2FwhELUb5o+KV0zAw8izxYC6UdK6dzjOKr3hfA8= -github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038/go.mod h1:vLeQHWaOMUQZ1ytnCskhwI5fCcXA7xxK0QjCngYPqbo= -github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co= -github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= -github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= -github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -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/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= -github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= -github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= -github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.67.4 h1:yR3NqWO1/UyO1w2PhUvXlGQs/PtFmoveVO0KZ4+Lvsc= -github.com/prometheus/common v0.67.4/go.mod h1:gP0fq6YjjNCLssJCQp0yk4M8W6ikLURwkdd/YKtTbyI= -github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws= -github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= -go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= -golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -gomodules.xyz/password-generator v0.2.4/go.mod h1:TvwYYTx9+P1pPwKQKfZgB/wr2Id9MqAQ3B5auY7reNg= -gomodules.xyz/version v0.1.0/go.mod h1:Y8xuV02mL/45psyPKG3NCVOwvAOy6T5Kx0l3rCjKSjU= -google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= -google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/gcfg.v1 v1.2.3 h1:m8OOJ4ccYHnx2f4gQwpno8nAX5OGOh7RLaaz0pj3Ogs= -gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 h1:E846t8CnR+lv5nE+VuiKTDG/v1U2stad0QzddfJC7kY= -gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5/go.mod h1:hiOFpYm0ZJbusNj2ywpbrXowU3G8U6GIQzqn2mw1UIE= -gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/pkg/nagflux/nagflux.go b/pkg/nagflux/nagflux.go index 0a54ed4..8a8da38 100644 --- a/pkg/nagflux/nagflux.go +++ b/pkg/nagflux/nagflux.go @@ -9,20 +9,19 @@ import ( "syscall" "time" - "pkg/nagflux/collector" - "pkg/nagflux/collector/livestatus" - "pkg/nagflux/collector/modgearman" - "pkg/nagflux/collector/nagflux" - "pkg/nagflux/collector/spoolfile" - "pkg/nagflux/config" - "pkg/nagflux/data" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - "pkg/nagflux/statistics" - "pkg/nagflux/target/elasticsearch" - "pkg/nagflux/target/file/jsontarget" - "pkg/nagflux/target/influx" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/livestatus" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/modgearman" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/nagflux" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/spoolfile" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/data" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/statistics" + "github.com/ConSol-Monitoring/nagflux/pkg/target/elasticsearch" + "github.com/ConSol-Monitoring/nagflux/pkg/target/file/jsontarget" + "github.com/ConSol-Monitoring/nagflux/pkg/target/influx" "github.com/kdar/factorlog" ) @@ -192,6 +191,7 @@ For further informations / bugs reports: https://github.com/ConSol-Monitoring/na } var nagiosCollector *spoolfile.NagiosSpoolfileCollector + var err error // nagios spoolfile collection is enabled by default nagiosSpoolFileCollectorEnabled := true if search, found := helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.Enabled", []string{}); found { @@ -202,45 +202,19 @@ For further informations / bugs reports: https://github.com/ConSol-Monitoring/na log.Warnf("Expected a *bool value out of the config value for Nagios Spoolfile Collection Enablement") } } - if nagiosSpoolFileCollectorEnabled { - spoolDirectoryString := "" - spoolDirectorySearch, spoolDirectoryFound := helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.Folder", []string{"Main.NagiosSpoolfileFolder"}) - if !spoolDirectoryFound { - log.Criticalf("Could not find a config value for Nagios Spoolfile Folder") - <-quit - } - spoolDirectoryPtr, ok := spoolDirectorySearch.(*string) - if ok { - spoolDirectoryString = *(spoolDirectoryPtr) - } else { - log.Warnf("Expected a *string value out of the config value for Nagios Spoolfile Folder") - } - workerCountInt := 0 - workerCountSearch, workerCountFound := helper.GetPreferredConfigValue(cfg, "NagiosSpoolfile.WorkerCount", []string{"Main.NagiosSpoolfileWorker"}) - if !workerCountFound { - log.Criticalf("Could not find a config value for Nagios Spoolfile Worker Count") + if nagiosSpoolFileCollectorEnabled { + nagiosCollector, err = spoolfile.NagiosSpoolfileCollectorFactory( + cfg, + resultQueues, + livestatusCache, + cfg.Main.FileBufferSize, + collector.Filterable{Filter: cfg.Main.DefaultTarget}, + ) + if err != nil { + log.Criticalf("Error when setting up NagiosSpoolfileCollectorFactory: %s", err.Error()) <-quit } - workerCountPtr, ok := workerCountSearch.(*int) - if ok { - workerCountInt = *(workerCountPtr) - } else { - log.Warnf("Expected a *int value out of the config value for Nagios Spoolfile Worker Count") - } - - if spoolDirectoryFound && workerCountFound { - log.Info("Nagios Spoolfile Directory: ", spoolDirectoryString) - log.Info("Nagios Spoolfile Worker Count: ", workerCountInt) - nagiosCollector = spoolfile.NagiosSpoolfileCollectorFactory( - spoolDirectoryString, - workerCountInt, - resultQueues, - livestatusCache, - cfg.Main.FileBufferSize, - collector.Filterable{Filter: cfg.Main.DefaultTarget}, - ) - } } // nagflux spoolfile collection is enabled by default diff --git a/pkg/nagflux/nagflux_test.go b/pkg/nagflux/nagflux_test.go index b8bc7d8..6780ca9 100644 --- a/pkg/nagflux/nagflux_test.go +++ b/pkg/nagflux/nagflux_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "pkg/nagflux/target/influx" + "github.com/ConSol-Monitoring/nagflux/pkg/target/influx" ) const ( @@ -219,7 +219,6 @@ func createTestData(folder, file string, data []testData) { if err := os.MkdirAll(folder, 0o700); err != nil { panic(err) } - //nolint: prealloc // data.input string are connected to bytes, need to precalculate their size. not too trivial fileData := []byte{} for _, data := range data { fileData = append(fileData, []byte(data.input)...) diff --git a/pkg/nagflux/statistics/prometheus.go b/pkg/statistics/prometheus.go similarity index 97% rename from pkg/nagflux/statistics/prometheus.go rename to pkg/statistics/prometheus.go index 9a3f62e..66dfca5 100644 --- a/pkg/nagflux/statistics/prometheus.go +++ b/pkg/statistics/prometheus.go @@ -7,9 +7,8 @@ import ( "sync" "time" - "pkg/nagflux/collector" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) diff --git a/pkg/nagflux/target/IHasWorker.go b/pkg/target/IHasWorker.go similarity index 100% rename from pkg/nagflux/target/IHasWorker.go rename to pkg/target/IHasWorker.go diff --git a/pkg/nagflux/target/elasticsearch/Connector.go b/pkg/target/elasticsearch/Connector.go similarity index 97% rename from pkg/nagflux/target/elasticsearch/Connector.go rename to pkg/target/elasticsearch/Connector.go index a67a4a0..2eb56ae 100644 --- a/pkg/nagflux/target/elasticsearch/Connector.go +++ b/pkg/target/elasticsearch/Connector.go @@ -6,11 +6,10 @@ import ( "strings" "time" - "pkg/nagflux/collector" - "pkg/nagflux/config" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/target/elasticsearch/JSONResult.go b/pkg/target/elasticsearch/JSONResult.go similarity index 100% rename from pkg/nagflux/target/elasticsearch/JSONResult.go rename to pkg/target/elasticsearch/JSONResult.go diff --git a/pkg/nagflux/target/elasticsearch/Worker.go b/pkg/target/elasticsearch/Worker.go similarity index 97% rename from pkg/nagflux/target/elasticsearch/Worker.go rename to pkg/target/elasticsearch/Worker.go index 6d95916..06c7535 100644 --- a/pkg/nagflux/target/elasticsearch/Worker.go +++ b/pkg/target/elasticsearch/Worker.go @@ -12,11 +12,10 @@ import ( "sync" "time" - "pkg/nagflux/collector" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - "pkg/nagflux/statistics" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/statistics" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/target/file/jsontarget/Worker.go b/pkg/target/file/jsontarget/Worker.go similarity index 97% rename from pkg/nagflux/target/file/jsontarget/Worker.go rename to pkg/target/file/jsontarget/Worker.go index 9c84eba..573d19d 100644 --- a/pkg/nagflux/target/file/jsontarget/Worker.go +++ b/pkg/target/file/jsontarget/Worker.go @@ -7,9 +7,8 @@ import ( "path" "time" - "pkg/nagflux/collector" - "pkg/nagflux/data" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/data" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/target/influx/Connector.go b/pkg/target/influx/Connector.go similarity index 97% rename from pkg/nagflux/target/influx/Connector.go rename to pkg/target/influx/Connector.go index 766e026..d8d4199 100644 --- a/pkg/nagflux/target/influx/Connector.go +++ b/pkg/target/influx/Connector.go @@ -9,12 +9,11 @@ import ( "regexp" "time" - "pkg/nagflux/collector" - "pkg/nagflux/config" - "pkg/nagflux/data" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/config" + "github.com/ConSol-Monitoring/nagflux/pkg/data" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" "github.com/kdar/factorlog" ) diff --git a/pkg/nagflux/target/influx/ShowSeriesResult.go b/pkg/target/influx/ShowSeriesResult.go similarity index 100% rename from pkg/nagflux/target/influx/ShowSeriesResult.go rename to pkg/target/influx/ShowSeriesResult.go diff --git a/pkg/nagflux/target/influx/Worker.go b/pkg/target/influx/Worker.go similarity index 96% rename from pkg/nagflux/target/influx/Worker.go rename to pkg/target/influx/Worker.go index 62daf8f..42e5b00 100644 --- a/pkg/nagflux/target/influx/Worker.go +++ b/pkg/target/influx/Worker.go @@ -11,13 +11,12 @@ import ( "sync" "time" - "pkg/nagflux/collector" - "pkg/nagflux/collector/nagflux" - "pkg/nagflux/data" - "pkg/nagflux/helper" - "pkg/nagflux/logging" - "pkg/nagflux/statistics" - + "github.com/ConSol-Monitoring/nagflux/pkg/collector" + "github.com/ConSol-Monitoring/nagflux/pkg/collector/nagflux" + "github.com/ConSol-Monitoring/nagflux/pkg/data" + "github.com/ConSol-Monitoring/nagflux/pkg/helper" + "github.com/ConSol-Monitoring/nagflux/pkg/logging" + "github.com/ConSol-Monitoring/nagflux/pkg/statistics" "github.com/kdar/factorlog" )