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:
vignesh-reddy
2020-01-13 01:38:24 -06:00
committed by Alexander Zobnin
parent c300debe35
commit 3f5719794a
9 changed files with 1106 additions and 33 deletions

View File

@@ -1,5 +1,10 @@
package main
import (
"encoding/json"
"fmt"
)
type connectionTestResponse struct {
ZabbixVersion string `json:"zabbixVersion"`
DbConnectorStatus *dbConnectionStatus `json:"dbConnectorStatus"`
@@ -9,3 +14,77 @@ type dbConnectionStatus struct {
DsType string `json:"dsType"`
DsName string `json:"dsName"`
}
type requestModel struct {
Target queryRequest `json:"target,omitempty"`
}
type queryRequest struct {
Method string `json:"method,omitempty"`
Params zabbixParams `json:"params,omitempty"`
}
type zabbixParamOutput struct {
Mode string
Fields []string
}
func (p *zabbixParamOutput) MarshalJSON() ([]byte, error) {
if p.Mode != "" {
return json.Marshal(p.Mode)
}
return json.Marshal(p.Fields)
}
func (p *zabbixParamOutput) UnmarshalJSON(data []byte) error {
if p == nil {
return fmt.Errorf("zabbixParamOutput: UnmarshalJSON on nil pointer")
}
var strArray []string
err := json.Unmarshal(data, &strArray)
if err == nil {
p.Fields = strArray
return nil
}
var str string
err = json.Unmarshal(data, &str)
if err == nil {
p.Mode = str
return nil
}
return fmt.Errorf("Unsupported type: %w", err)
}
type zabbixParams struct {
Output *zabbixParamOutput `json:"output,omitempty"`
SortField string `json:"sortfield,omitempty"`
SortOrder string `json:"sortorder,omitempty"`
Filter map[string][]int `json:"filter,omitempty"`
// Login
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
// Item GET
WebItems bool `json:"webitems,omitempty"`
SelectHosts []string `json:"selectHosts,omitempty"`
ItemIDs []string `json:"itemids,omitempty"`
GroupIDs []string `json:"groupids,omitempty"`
HostIDs []string `json:"hostids,omitempty"`
AppIDs []string `json:"applicationids,omitempty"`
// Host Group GET
RealHosts bool `json:"real_hosts,omitempty"`
// History GET
History *int `json:"history,omitempty,string"`
// History/Trends GET
TimeFrom int64 `json:"time_from,omitempty"`
TimeTill int64 `json:"time_till,omitempty"`
}