Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 3 additions & 1 deletion cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ var healthCmd = &cobra.Command{
output string
summary string
rc int
states []int
stat logstash.Stat
thresholds HealthThreshold
fdstatus string
heapstatus string
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 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var pipelineCmd = &cobra.Command{
output string
summary string
rc int
states []int
pp logstash.Pipeline
thresholds PipelineThreshold
perfList perfdata.PerfdataList
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions internal/logstash/api_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

}