-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 e0ffdff. * 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
- Loading branch information
1 parent
c300deb
commit 3f57197
Showing
9 changed files
with
1,106 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package zabbix | ||
|
||
type Items []Item | ||
type Item struct { | ||
ID string `json:"itemid,omitempty"` | ||
Key string `json:"key_,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
ValueType int `json:"value_type,omitempty,string"` | ||
HostID string `json:"hostid,omitempty"` | ||
Hosts []ItemHost `json:"hosts,omitempty"` | ||
Status string `json:"status,omitempty"` | ||
State string `json:"state,omitempty"` | ||
} | ||
type ItemHost struct { | ||
ID string `json:"hostid,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
} | ||
|
||
type Trend []TrendPoint | ||
type TrendPoint struct { | ||
ItemID string `json:"itemid,omitempty"` | ||
Clock int64 `json:"clock,omitempty,string"` | ||
Num string `json:"num,omitempty"` | ||
ValueMin string `json:"value_min,omitempty"` | ||
ValueAvg string `json:"value_avg,omitempty"` | ||
ValueMax string `json:"value_max,omitempty"` | ||
} | ||
|
||
type History []HistoryPoint | ||
type HistoryPoint struct { | ||
ItemID string `json:"itemid,omitempty"` | ||
Clock int64 `json:"clock,omitempty,string"` | ||
Value float64 `json:"value,omitempty,string"` | ||
NS int64 `json:"ns,omitempty,string"` | ||
} |
Oops, something went wrong.