Backend: implement alerting query (#847)
* Unit tests for backend * minor change * Implemented querNumericItems in backend * Added query type * Set alerting to true * Return TimeSeries from History * Updated alerting feature * Fix params marshal error * Fix params more * Update zabbixAPIConnector.js * Numbers, I guess * Params Output Type * Output marshaling * Unmarshal and decoder error catch * HistoryPoint and Unmarshal fixes * Unmarshal to History * Revert "Update zabbixAPIConnector.js" This reverts commit e0ffdff859b6f920893a47a709493f8076e38ef4. * Fix unmarshaling for real * Time range integer * Use more zabbix.Items * Update response_models.go * Update zabbix_api.go * Update models.go * Update zabbix_api.go * Tests * Adding more unit tests and cleaning up additional logging * Make history request param a pointer * Actually store datasource in cache * Debug logs and timings * Handle panics gracefully * Updated Regex filter parsing * Removed must compile * Clean up regex filter
This commit is contained in:
committed by
Alexander Zobnin
parent
c300debe35
commit
3f5719794a
60
pkg/models_test.go
Normal file
60
pkg/models_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_zabbixParamOutput(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input zabbixParams
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "Mode extend",
|
||||
input: zabbixParams{
|
||||
Output: &zabbixParamOutput{
|
||||
Mode: "extend",
|
||||
},
|
||||
GroupIDs: []string{"test1", "test2"},
|
||||
},
|
||||
want: `{ "output": "extend", "groupids": ["test1", "test2"] }`,
|
||||
},
|
||||
{
|
||||
name: "Fields",
|
||||
input: zabbixParams{
|
||||
Output: &zabbixParamOutput{
|
||||
Fields: []string{"name", "key_", "hostid"},
|
||||
},
|
||||
GroupIDs: []string{"test1", "test2"},
|
||||
},
|
||||
want: `{ "output": ["name", "key_", "hostid"], "groupids": ["test1", "test2"] }`,
|
||||
},
|
||||
{
|
||||
name: "No Output",
|
||||
input: zabbixParams{
|
||||
GroupIDs: []string{"test1", "test2"},
|
||||
},
|
||||
want: `{ "groupids": ["test1", "test2"] }`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
jsonOut, err := json.Marshal(tt.input)
|
||||
fmt.Printf("Output: %s\n", jsonOut)
|
||||
assert.NoError(t, err)
|
||||
if !assert.JSONEq(t, tt.want, string(jsonOut)) {
|
||||
return
|
||||
}
|
||||
|
||||
objOut := zabbixParams{}
|
||||
err = json.Unmarshal(jsonOut, &objOut)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.input, objOut)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user