diff --git a/cmd/config_test.go b/cmd/config_test.go new file mode 100644 index 0000000..f3fbabf --- /dev/null +++ b/cmd/config_test.go @@ -0,0 +1,13 @@ +package cmd + +import ( + "testing" +) + +func TestConfig(t *testing.T) { + c := cliConfig.NewClient() + expected := "http://localhost:9600" + if c.Url != "http://localhost:9600" { + t.Error("\nActual: ", c.Url, "\nExpected: ", expected) + } +} diff --git a/cmd/health.go b/cmd/health.go index 5ba4220..266cc7c 100644 --- a/cmd/health.go +++ b/cmd/health.go @@ -144,7 +144,6 @@ var healthCmd = &cobra.Command{ output string summary string rc int - states []int stat logstash.Stat thresholds HealthThreshold fdstatus string @@ -152,6 +151,9 @@ var healthCmd = &cobra.Command{ cpustatus string ) + // status + fdstatus + heapstatus + cpustatus = 4 + states := make([]int, 0, 4) + // Parse the thresholds into a central var since we need them later thresholds, err := parseHealthThresholds(cliHealthConfig) if err != nil { diff --git a/cmd/pipeline.go b/cmd/pipeline.go index 20e5165..eae0b9a 100644 --- a/cmd/pipeline.go +++ b/cmd/pipeline.go @@ -66,7 +66,6 @@ var pipelineCmd = &cobra.Command{ output string summary string rc int - states []int pp logstash.Pipeline thresholds PipelineThreshold perfList perfdata.PerfdataList @@ -100,6 +99,8 @@ var pipelineCmd = &cobra.Command{ check.ExitError(err) } + states := make([]int, 0, len(pp.Pipelines)) + // Check status for each pipeline for name, pipe := range pp.Pipelines { inflightEvents := pipe.Events.In - pipe.Events.Out diff --git a/internal/logstash/api_test.go b/internal/logstash/api_test.go new file mode 100644 index 0000000..6009cfa --- /dev/null +++ b/internal/logstash/api_test.go @@ -0,0 +1,40 @@ +package logstash + +import ( + "encoding/json" + "testing" +) + +func TestUmarshallPipeline(t *testing.T) { + + j := `{"host":"foobar","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":{"ansible-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"}}}` + + var pl Pipeline + err := json.Unmarshal([]byte(j), &pl) + + if err != nil { + t.Error(err) + } + + if pl.Host != "foobar" { + t.Error("\nActual: ", pl.Host, "\nExpected: ", "foobar") + } + +} + +func TestUmarshallStat(t *testing.T) { + + j := `{"host":"foobar","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}}}` + + var st Stat + err := json.Unmarshal([]byte(j), &st) + + if err != nil { + t.Error(err) + } + + if st.Host != "foobar" { + t.Error("\nActual: ", st.Host, "\nExpected: ", "foobar") + } + +}