diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7d53aa0..a49f98b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,4 +17,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.1.6 + version: v2.12.2 diff --git a/.golangci.yml b/.golangci.yml index 58d69f6..90aac91 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,7 +3,12 @@ run: tests: false linters: default: all + enable: + - wsl_v5 + - gomodguard_v2 disable: + - wsl + - gomodguard - cyclop - depguard - err113 diff --git a/cmd/config.go b/cmd/config.go index 057d68b..9dd7c46 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -70,7 +70,6 @@ func (c *Config) NewClient() *client.Client { KeyFile: c.KeyFile, CertFile: c.CertFile, }) - if err != nil { check.ExitError(err) } diff --git a/cmd/health.go b/cmd/health.go index 3102f4e..2068dcc 100644 --- a/cmd/health.go +++ b/cmd/health.go @@ -10,12 +10,10 @@ import ( "github.com/NETWAYS/check_logstash/internal/logstash" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" - "github.com/NETWAYS/go-check/result" "github.com/spf13/cobra" ) -// To store the CLI parameters. +// HealthConfig for the CLI parameters. type HealthConfig struct { FileDescThresWarning string FileDescThresCritical string @@ -26,7 +24,7 @@ type HealthConfig struct { UnreachableExitCode int } -// To store the parsed CLI parameters. +// HealthThreshold for the parsed CLI parameters. type HealthThreshold struct { fileDescThresWarn *check.Threshold fileDescThresCrit *check.Threshold @@ -89,11 +87,11 @@ func parseHealthThresholds(config HealthConfig) (HealthThreshold, error) { return t, nil } -func generatePerfdata(stat logstash.Stat, thres HealthThreshold) perfdata.PerfdataList { +func generatePerfdata(stat logstash.Stat, thres HealthThreshold) check.PerfdataList { // Generates the Perfdata from the results and thresholds - var l perfdata.PerfdataList + var l check.PerfdataList - l.Add(&perfdata.Perfdata{ + l.Add(&check.Perfdata{ Label: "process.cpu.percent", Value: stat.Process.CPU.Percent, Uom: "%", @@ -101,7 +99,7 @@ func generatePerfdata(stat logstash.Stat, thres HealthThreshold) perfdata.Perfda Crit: thres.cpuUseThresCrit, Min: 0, Max: 100}) - l.Add(&perfdata.Perfdata{ + l.Add(&check.Perfdata{ Label: "jvm.mem.heap_used_percent", Uom: "%", Value: stat.Jvm.Mem.HeapUsedPercent, @@ -109,11 +107,11 @@ func generatePerfdata(stat logstash.Stat, thres HealthThreshold) perfdata.Perfda Crit: thres.heapUseThresCrit, Min: 0, Max: 100}) - l.Add(&perfdata.Perfdata{ + l.Add(&check.Perfdata{ Label: "jvm.threads.count", Value: stat.Jvm.Threads.Count, Max: 0}) - l.Add(&perfdata.Perfdata{ + l.Add(&check.Perfdata{ Label: "process.open_file_descriptors", Value: stat.Process.OpenFileDescriptors, Warn: thres.fileDescThresWarn, @@ -143,7 +141,7 @@ var healthCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { var ( output string - rc int + rc check.Status stat logstash.Stat thresholds HealthThreshold fdstatus string @@ -152,7 +150,7 @@ var healthCmd = &cobra.Command{ ) // status + fdstatus + heapstatus + cpustatus = 4 - states := make([]int, 0, 4) + states := make([]check.Status, 0, 4) // Parse the thresholds into a central var since we need them later thresholds, err := parseHealthThresholds(cliHealthConfig) @@ -160,13 +158,18 @@ var healthCmd = &cobra.Command{ check.ExitError(err) } + unreachableExitCode, errExit := check.NewStatus(cliHealthConfig.UnreachableExitCode) + if errExit != nil { + unreachableExitCode = check.Unknown + } + // Creating an client and connecting to the API c := cliConfig.NewClient() u, _ := url.JoinPath(c.URL, "/_node/stats") - resp, err := c.Client.Get(u) + resp, err := c.Client.Get(u) if err != nil { - check.ExitRaw(cliHealthConfig.UnreachableExitCode, err.Error()) + check.Exit(unreachableExitCode, err.Error()) } if resp.StatusCode != http.StatusOK { @@ -174,8 +177,8 @@ var healthCmd = &cobra.Command{ } defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&stat) + err = json.NewDecoder(resp.Body).Decode(&stat) if err != nil { check.ExitError(err) } @@ -205,43 +208,47 @@ var healthCmd = &cobra.Command{ perfList := generatePerfdata(stat, thresholds) // Defaults for the subchecks - fdstatus = check.StatusText(check.OK) - heapstatus = check.StatusText(check.OK) - cpustatus = check.StatusText(check.OK) + fdstatus = check.OKString + heapstatus = check.OKString + cpustatus = check.OKString // File Descriptors Check fileDescriptorsPercent := (stat.Process.OpenFileDescriptors / stat.Process.MaxFileDescriptors) * 100 if thresholds.fileDescThresWarn.DoesViolate(fileDescriptorsPercent) { states = append(states, check.Warning) - fdstatus = check.StatusText(check.Warning) + fdstatus = check.WarningString } + if thresholds.fileDescThresCrit.DoesViolate(fileDescriptorsPercent) { states = append(states, check.Critical) - fdstatus = check.StatusText(check.Critical) + fdstatus = check.CriticalString } // Heap Usage Check if thresholds.heapUseThresWarn.DoesViolate(stat.Jvm.Mem.HeapUsedPercent) { states = append(states, check.Warning) - heapstatus = check.StatusText(check.Warning) + heapstatus = check.WarningString } + if thresholds.heapUseThresCrit.DoesViolate(stat.Jvm.Mem.HeapUsedPercent) { states = append(states, check.Critical) - heapstatus = check.StatusText(check.Critical) + heapstatus = check.CriticalString } // CPU Usage Check if thresholds.cpuUseThresWarn.DoesViolate(stat.Process.CPU.Percent) { states = append(states, check.Warning) - cpustatus = check.StatusText(check.Warning) + cpustatus = check.WarningString } + if thresholds.cpuUseThresCrit.DoesViolate(stat.Process.CPU.Percent) { states = append(states, check.Critical) - cpustatus = check.StatusText(check.Critical) + cpustatus = check.CriticalString } // Validate the various subchecks and use the worst state as return code - switch result.WorstState(states...) { + //nolint: exhaustive + switch check.WorstState(states...) { case 0: rc = check.OK output = "Logstash is healthy" @@ -258,11 +265,11 @@ var healthCmd = &cobra.Command{ // Generate summary for subchecks var summary strings.Builder - summary.WriteString(fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent)) - summary.WriteString(fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent)) - summary.WriteString(fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent)) + fmt.Fprintf(&summary, "\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent) + fmt.Fprintf(&summary, "\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent) + fmt.Fprintf(&summary, "\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent) - check.ExitRaw(rc, output, summary.String(), "|", perfList.String()) + check.ExitWithPerfdata(rc, perfList, output, summary.String()) }, } diff --git a/cmd/health_test.go b/cmd/health_test.go index 738ed73..f080276 100644 --- a/cmd/health_test.go +++ b/cmd/health_test.go @@ -150,7 +150,7 @@ func TestHealthCmd_Logstash7(t *testing.T) { w.Write([]byte(`{"host":"test","version":"7.17.8","status":"green","jvm":{"threads":{"count":50,"peak_count":51},"mem":{"heap_used_percent":20}},"process":{"open_file_descriptors": 120,"peak_open_file_descriptors": 120,"max_file_descriptors":16384,"cpu":{"percent": 1}}}`)) })), args: []string{"run", "../main.go", "health"}, - expected: "| process.cpu.percent=1%;100;100;0;100 jvm.mem.heap_used_percent=20%;70;80;0;100 jvm.threads.count=50;;;;0 process.open_file_descriptors=120;100;100;0;16384", + expected: "|process.cpu.percent=1%;100;100;0;100 jvm.mem.heap_used_percent=20%;70;80;0;100 jvm.threads.count=50;;;;0 process.open_file_descriptors=120;100;100;0;16384", }, { name: "health-red", @@ -290,7 +290,7 @@ func TestHealthCmd_Logstash8(t *testing.T) { w.Write([]byte(`{"host":"test","version":"8.6","status":"green","jvm":{"threads":{"count":50,"peak_count":51},"mem":{"heap_used_percent":20}},"process":{"open_file_descriptors": 120,"peak_open_file_descriptors": 120,"max_file_descriptors":16384,"cpu":{"percent": 1}}}`)) })), args: []string{"run", "../main.go", "health"}, - expected: "| process.cpu.percent=1%;100;100;0;100 jvm.mem.heap_used_percent=20%;70;80;0;100 jvm.threads.count=50;;;;0 process.open_file_descriptors=120;100;100;0;16384", + expected: "|process.cpu.percent=1%;100;100;0;100 jvm.mem.heap_used_percent=20%;70;80;0;100 jvm.threads.count=50;;;;0 process.open_file_descriptors=120;100;100;0;16384", }, { name: "health-cpu-heap-worst-state", diff --git a/cmd/pipeline.go b/cmd/pipeline.go index ca0a225..5964e73 100644 --- a/cmd/pipeline.go +++ b/cmd/pipeline.go @@ -10,19 +10,17 @@ import ( "github.com/NETWAYS/check_logstash/internal/logstash" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" - "github.com/NETWAYS/go-check/result" "github.com/spf13/cobra" ) -// To store the CLI parameters. +// PipelineConfig for the CLI parameters. type PipelineConfig struct { PipelineName string Warning string Critical string } -// To store the parsed CLI parameters. +// PipelineThreshold for the parsed CLI parameters. type PipelineThreshold struct { Warning *check.Threshold Critical *check.Threshold @@ -79,10 +77,10 @@ var pipelineCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { var ( output string - rc int + rc check.Status pp logstash.Pipeline thresholds PipelineThreshold - perfList perfdata.PerfdataList + perfList check.PerfdataList ) // Parse the thresholds into a central var since we need them later @@ -96,8 +94,8 @@ var pipelineCmd = &cobra.Command{ // localhost:9600/_node/stats/pipelines/ will return all Pipelines // localhost:9600/_node/stats/pipelines/foo will return the foo Pipeline u, _ := url.JoinPath(c.URL, "/_node/stats/pipelines", cliPipelineConfig.PipelineName) - resp, err := c.Client.Get(u) + resp, err := c.Client.Get(u) if err != nil { check.ExitError(err) } @@ -107,13 +105,13 @@ var pipelineCmd = &cobra.Command{ } defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&pp) + err = json.NewDecoder(resp.Body).Decode(&pp) if err != nil { check.ExitError(err) } - states := make([]int, 0, len(pp.Pipelines)) + states := make([]check.Status, 0, len(pp.Pipelines)) // Check status for each pipeline var summary strings.Builder @@ -122,41 +120,46 @@ var pipelineCmd = &cobra.Command{ inflightEvents := calculateInflightEvents(pipe.Events.In, pipe.Events.Out) summary.WriteString("\n \\_") + if thresholds.Critical.DoesViolate(float64(inflightEvents)) { states = append(states, check.Critical) - summary.WriteString(fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents)) + + fmt.Fprintf(&summary, "[CRITICAL] inflight_events_%s:%d;", name, inflightEvents) } else if thresholds.Warning.DoesViolate(float64(inflightEvents)) { states = append(states, check.Warning) - summary.WriteString(fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents)) + + fmt.Fprintf(&summary, "[WARNING] inflight_events_%s:%d;", name, inflightEvents) } else { states = append(states, check.OK) - summary.WriteString(fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents)) + + fmt.Fprintf(&summary, "[OK] inflight_events_%s:%d;", name, inflightEvents) } // Generate perfdata for each event - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.events.in", name), Uom: "c", Value: pipe.Events.In}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.events.out", name), Uom: "c", Value: pipe.Events.Out}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("inflight_events_%s", name), //nolint: perfsprint Warn: thresholds.Warning, Crit: thresholds.Critical, Value: inflightEvents}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.reloads.failures", name), Value: pipe.Reloads.Failures}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.reloads.successes", name), Value: pipe.Reloads.Successes}) } // Validate the various subchecks and use the worst state as return code - switch result.WorstState(states...) { + //nolint: exhaustive + switch check.WorstState(states...) { case 0: rc = check.OK output = "Inflight events alright" @@ -171,7 +174,7 @@ var pipelineCmd = &cobra.Command{ output = "Inflight events status unknown" } - check.ExitRaw(rc, output, summary.String(), "|", perfList.String()) + check.ExitWithPerfdata(rc, perfList, output, summary.String()) }, } @@ -190,7 +193,7 @@ var pipelineReloadCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { var ( output string - rc int + rc check.Status pp logstash.Pipeline ) @@ -199,8 +202,8 @@ var pipelineReloadCmd = &cobra.Command{ // localhost:9600/_node/stats/pipelines/ will return all Pipelines // localhost:9600/_node/stats/pipelines/foo will return the foo Pipeline u, _ := url.JoinPath(c.URL, "/_node/stats/pipelines", cliPipelineConfig.PipelineName) - resp, err := c.Client.Get(u) + resp, err := c.Client.Get(u) if err != nil { check.ExitError(err) } @@ -210,13 +213,13 @@ var pipelineReloadCmd = &cobra.Command{ } defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&pp) + err = json.NewDecoder(resp.Body).Decode(&pp) if err != nil { check.ExitError(err) } - states := make([]int, 0, len(pp.Pipelines)) + states := make([]check.Status, 0, len(pp.Pipelines)) // Check the reload configuration status for each pipeline var summary strings.Builder @@ -230,24 +233,30 @@ var pipelineReloadCmd = &cobra.Command{ if errSu != nil || errFa != nil { states = append(states, check.Unknown) - summary.WriteString(fmt.Sprintf("[UNKNOWN] Configuration reload for pipeline %s unknown;", name)) + + fmt.Fprintf(&summary, "[UNKNOWN] Configuration reload for pipeline %s unknown;", name) summary.WriteString("\n \\_") + continue } summary.WriteString("\n \\_") + if lastFailureReload.After(lastSuccessReload) { states = append(states, check.Critical) - summary.WriteString(fmt.Sprintf("[CRITICAL] Configuration reload for pipeline %s failed on %s;", name, lastFailureReload)) + + fmt.Fprintf(&summary, "[CRITICAL] Configuration reload for pipeline %s failed on %s;", name, lastFailureReload) } else { states = append(states, check.OK) - summary.WriteString(fmt.Sprintf("[OK] Configuration successfully reloaded for pipeline %s for on %s;", name, lastSuccessReload)) + + fmt.Fprintf(&summary, "[OK] Configuration successfully reloaded for pipeline %s for on %s;", name, lastSuccessReload) } } } // Validate the various subchecks and use the worst state as return code - switch result.WorstState(states...) { + //nolint: exhaustive + switch check.WorstState(states...) { case 0: rc = check.OK output = "Configuration successfully reloaded" @@ -262,7 +271,7 @@ var pipelineReloadCmd = &cobra.Command{ output = "Configuration reload status unknown" } - check.ExitRaw(rc, output, summary.String()) + check.Exit(rc, output, summary.String()) }, } @@ -281,10 +290,10 @@ var pipelineFlowCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { var ( output string - rc int + rc check.Status thresholds PipelineThreshold pp logstash.Pipeline - perfList perfdata.PerfdataList + perfList check.PerfdataList ) // Parse the thresholds into a central var since we need them later @@ -298,8 +307,8 @@ var pipelineFlowCmd = &cobra.Command{ // localhost:9600/_node/stats/pipelines/ will return all Pipelines // localhost:9600/_node/stats/pipelines/foo will return the foo Pipeline u, _ := url.JoinPath(c.URL, "/_node/stats/pipelines", cliPipelineConfig.PipelineName) - resp, err := c.Client.Get(u) + resp, err := c.Client.Get(u) if err != nil { check.ExitError(err) } @@ -309,49 +318,54 @@ var pipelineFlowCmd = &cobra.Command{ } defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&pp) + err = json.NewDecoder(resp.Body).Decode(&pp) if err != nil { check.ExitError(err) } - states := make([]int, 0, len(pp.Pipelines)) + states := make([]check.Status, 0, len(pp.Pipelines)) // Check the flow metrics for each pipeline var summary strings.Builder for name, pipe := range pp.Pipelines { summary.WriteString("\n \\_") + if thresholds.Critical.DoesViolate(pipe.Flow.QueueBackpressure.Current) { states = append(states, check.Critical) - summary.WriteString(fmt.Sprintf("[CRITICAL] queue_backpressure_%s:%.2f;", name, pipe.Flow.QueueBackpressure.Current)) + + fmt.Fprintf(&summary, "[CRITICAL] queue_backpressure_%s:%.2f;", name, pipe.Flow.QueueBackpressure.Current) } else if thresholds.Warning.DoesViolate(pipe.Flow.QueueBackpressure.Current) { states = append(states, check.Warning) - summary.WriteString(fmt.Sprintf("[WARNING] queue_backpressure_%s:%.2f;", name, pipe.Flow.QueueBackpressure.Current)) + + fmt.Fprintf(&summary, "[WARNING] queue_backpressure_%s:%.2f;", name, pipe.Flow.QueueBackpressure.Current) } else { states = append(states, check.OK) - summary.WriteString(fmt.Sprintf("[OK] queue_backpressure_%s:%.2f;", name, pipe.Flow.QueueBackpressure.Current)) + + fmt.Fprintf(&summary, "[OK] queue_backpressure_%s:%.2f;", name, pipe.Flow.QueueBackpressure.Current) } // Generate perfdata for each event - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.queue_backpressure_%s", name), //nolint: perfsprint Warn: thresholds.Warning, Crit: thresholds.Critical, Value: pipe.Flow.QueueBackpressure.Current}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.output_throughput", name), Value: pipe.Flow.OutputThroughput.Current}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.input_throughput", name), Value: pipe.Flow.InputThroughput.Current}) - perfList.Add(&perfdata.Perfdata{ + perfList.Add(&check.Perfdata{ Label: fmt.Sprintf("pipelines.%s.filter_throughput", name), Value: pipe.Flow.FilterThroughput.Current}) } // Validate the various subchecks and use the worst state as return code - switch result.WorstState(states...) { + //nolint: exhaustive + switch check.WorstState(states...) { case 0: rc = check.OK output = "Flow metrics alright" @@ -366,7 +380,7 @@ var pipelineFlowCmd = &cobra.Command{ output = "Flow metrics status unknown" } - check.ExitRaw(rc, output, summary.String(), "|", perfList.String()) + check.ExitWithPerfdata(rc, perfList, output, summary.String()) }, } diff --git a/cmd/pipeline_test.go b/cmd/pipeline_test.go index 7cbef41..9379b38 100644 --- a/cmd/pipeline_test.go +++ b/cmd/pipeline_test.go @@ -73,7 +73,7 @@ func TestPipelineCmd_Logstash7(t *testing.T) { w.Write([]byte(`{"host":"localhost","version":"7.17.8","http_address":"127.0.0.1:9600","id":"4","name":"test","ephemeral_id":"5","status":"green","snapshot":false,"pipeline":{"workers":2,"batch_size":125,"batch_delay":50},"pipelines":{"localhost-input":{"events":{"filtered":0,"duration_in_millis":0,"queue_push_duration_in_millis":0,"out":50,"in":100},"plugins":{"inputs":[{"id":"b","name":"beats","events":{"queue_push_duration_in_millis":0,"out":0}}],"codecs":[{"id":"plain","name":"plain","decode":{"writes_in":0,"duration_in_millis":0,"out":0},"encode":{"writes_in":0,"duration_in_millis":0}},{"id":"json","name":"json","decode":{"writes_in":0,"duration_in_millis":0,"out":0},"encode":{"writes_in":0,"duration_in_millis":0}}],"filters":[],"outputs":[{"id":"f","name":"redis","events":{"duration_in_millis":18,"out":50,"in":100}}]},"reloads":{"successes":0,"last_success_timestamp":null,"last_error":null,"last_failure_timestamp":null,"failures":0},"queue":{"type":"memory","events_count":0,"queue_size_in_bytes":0,"max_queue_size_in_bytes":0},"hash":"f","ephemeral_id":"f"}}}`)) })), args: []string{"run", "../main.go", "pipeline", "--inflight-events-warn", "200", "--inflight-events-crit", "500"}, - expected: "| pipelines.localhost-input.events.in=100c pipelines.localhost-input.events.out=50c inflight_events_localhost-input=50;200;500 pipelines.localhost-input.reloads.failures=0 pipelines.localhost-input.reloads.successes=0", + expected: "|pipelines.localhost-input.events.in=100c pipelines.localhost-input.events.out=50c inflight_events_localhost-input=50;200;500 pipelines.localhost-input.reloads.failures=0 pipelines.localhost-input.reloads.successes=0", }, { name: "pipeline-missing", @@ -186,7 +186,7 @@ func TestPipelineCmd_Logstash8(t *testing.T) { w.Write([]byte(`{"host":"foobar","version":"8.7.1","http_address":"127.0.0.1:9600","id":"4","name":"test","ephemeral_id":"5","status":"green","snapshot":false,"pipeline":{"workers":2,"batch_size":125,"batch_delay":50},"pipelines":{"ansible-input":{"flow":{"queue_backpressure":{"current":12.34,"last_1_minute":0,"lifetime":2.503e-05},"output_throughput":{"current":0,"last_1_minute":0.344,"lifetime":0.7051},"input_throughput":{"current":10,"last_1_minute":0.5734,"lifetime":1.089},"worker_concurrency":{"current":0.0001815,"last_1_minute":0.0009501,"lifetime":0.003384},"filter_throughput":{"current":0,"last_1_minute":0.5734,"lifetime":1.089}},"events":{"filtered":0,"duration_in_millis":0,"queue_push_duration_in_millis":0,"out":50,"in":100},"queue":{"type":"memory","events_count":0,"queue_size_in_bytes":0,"max_queue_size_in_bytes":0},"hash":"f","ephemeral_id":"f"}}}`)) })), args: []string{"run", "../main.go", "pipeline", "flow", "--warning", "15", "--critical", "20"}, - expected: "[OK] queue_backpressure_ansible-input:12.34; | pipelines.queue_backpressure_ansible-input=12.34;15;20 pipelines.ansible-input.output_throughput=0 pipelines.ansible-input.input_throughput=10 pipelines.ansible-input.filter_throughput=0", + expected: "[OK] queue_backpressure_ansible-input:12.34;|pipelines.queue_backpressure_ansible-input=12.34;15;20 pipelines.ansible-input.output_throughput=0 pipelines.ansible-input.input_throughput=10 pipelines.ansible-input.filter_throughput=0", }, { name: "pipeline-flow-critical", diff --git a/cmd/root.go b/cmd/root.go index 469e581..b4fc9a6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,7 +24,8 @@ func Execute(version string) { rootCmd.Version = version rootCmd.VersionTemplate() - if err := rootCmd.Execute(); err != nil { + err := rootCmd.Execute() + if err != nil { check.ExitError(err) } } diff --git a/go.mod b/go.mod index 73f830e..cb3963c 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/NETWAYS/check_logstash -go 1.24 +go 1.26 require ( - github.com/NETWAYS/go-check v0.6.4 + github.com/NETWAYS/go-check v1.0.0 github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41 github.com/spf13/cobra v1.10.2 ) diff --git a/go.sum b/go.sum index 7ca4909..7712dca 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/NETWAYS/go-check v0.6.4 h1:4WETSVNZNEP0Yudcp5xlvxq6RGn920cmUKq4fz/P1GQ= -github.com/NETWAYS/go-check v0.6.4/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= +github.com/NETWAYS/go-check v1.0.0 h1:YkzTwFfGR+Z+mK3Wsqpnu8wibzsB30im19iPNfCOsMQ= +github.com/NETWAYS/go-check v1.0.0/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41 h1:5PdguRs5fRgYvok56yQDXJssKXY91vNq6Tmhb4dFH/I= github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41/go.mod h1:jZ62Y7P8/T/TqNy6I7RI/G9G9tXEcpuqrlkkO+xgCRE= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= diff --git a/internal/logstash/api.go b/internal/logstash/api.go index cf1632b..8359cfb 100644 --- a/internal/logstash/api.go +++ b/internal/logstash/api.go @@ -73,7 +73,7 @@ type Stat struct { MajorVersion int } -// Custom Unmarshal since we might want to add or parse +// UnmarshalJSON is a custom unmarshal since we might want to add or parse // further fields in the future. This is simpler to extend and // to test here than during the CheckPlugin logic. func (s *Stat) UnmarshalJSON(b []byte) error { @@ -81,9 +81,7 @@ func (s *Stat) UnmarshalJSON(b []byte) error { t := (*Temp)(s) - // nolint: ifshort err := json.Unmarshal(b, t) - if err != nil { return err } @@ -92,8 +90,8 @@ func (s *Stat) UnmarshalJSON(b []byte) error { // but decided against the dependency if s.Version != "" { v := strings.Split(s.Version, ".") - majorVersion, convErr := strconv.Atoi(v[0]) + majorVersion, convErr := strconv.Atoi(v[0]) if convErr != nil { return errors.New("could not determine version") } diff --git a/main.go b/main.go index 51a4b70..078638a 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,8 @@ import ( "github.com/NETWAYS/check_logstash/cmd" ) -// nolint: gochecknoglobals var ( - // These get filled at build time with the proper vaules. + // These get filled at build time with the proper values. version = "development" commit = "HEAD" date = "latest"