First commit: Add connection struct and define History
This commit is contained in:
89
history.go
Normal file
89
history.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package zabbix
|
||||||
|
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type historyBase struct {
|
||||||
|
Clock Time `json:"clock"`
|
||||||
|
ItemID string `json:"itemid"`
|
||||||
|
Ns int `json:"ns"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryFloat struct {
|
||||||
|
Value float32 `json:"value"`
|
||||||
|
historyBase
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryInt struct {
|
||||||
|
Value int `json:"value"`
|
||||||
|
historyBase
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryString struct {
|
||||||
|
Value string `json:"value"`
|
||||||
|
historyBase
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryText struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
HistoryString
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryLog struct {
|
||||||
|
LogEventID int `json:"logeventid"`
|
||||||
|
Severity int `json:"severity"`
|
||||||
|
Source int `json:"source"`
|
||||||
|
Timestamp Time `json:"timestamp"`
|
||||||
|
|
||||||
|
HistoryText
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryGet struct {
|
||||||
|
HistoryType int `json:"history,omitempty"`
|
||||||
|
HostIDs []int `json:"hostids,omitempty"`
|
||||||
|
ItemIDs []int `json:"itemids,omitempty"`
|
||||||
|
TimeFrom Time `json:"time_from,omitempty"`
|
||||||
|
TimeTill Time `json:"time_till,omitempty"`
|
||||||
|
SortField string `json:"sortfield,omitempty"`
|
||||||
|
commonGet
|
||||||
|
}
|
||||||
|
|
||||||
|
type historyReq struct{
|
||||||
|
JSONrpc string `json:"jsonrpc"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
Params HistoryGet `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func GetHistory(c *Connection,params *HistoryGet, result *HistoryInt) {
|
||||||
|
body := historyReq{
|
||||||
|
JSONrpc: "2.0",
|
||||||
|
Method: "history.get",
|
||||||
|
Params: ¶ms,
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyreq,err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
request, err = http.NewRequest(http.MethodPost, c.URL, bytes.NewBuffer(bodyreq))
|
||||||
|
request.Header.Set("Content-Type", "application/json")
|
||||||
|
request.Header.Set("Authorization", "Bearer "+c.APIKey)
|
||||||
|
client := &http.Client{
|
||||||
|
CheckRedirect: redirectPolicyFunc,
|
||||||
|
}
|
||||||
|
resp, err := client.Do(request)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := io.ReadAll()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
19
host.go
Normal file
19
host.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package zabbix
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
type HostGet struct {
|
||||||
|
GroupIds []string `json:"groupids,omitempty"`
|
||||||
|
DServiceIds []string `json:"dserviceids,omitempty"`
|
||||||
|
GraphIds []string `json:"graphids,omitempty"`
|
||||||
|
HostIds []string `json:"hostids,omitempty"`
|
||||||
|
HttpTestIds []string `json:"httptestids,omitempty"`
|
||||||
|
InterfaceIds []string `json:"interfaceids,omitempty"`
|
||||||
|
ItemIds []string `json:"itemids,omitempty"`
|
||||||
|
MaintenanceIds []string `json:"maintenanceids,omitempty"`
|
||||||
|
commonGet
|
||||||
|
|
||||||
|
}
|
||||||
24
zabbix.go
Normal file
24
zabbix.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package zabbix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
type Connection struct {
|
||||||
|
Host string
|
||||||
|
APIKey string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type commonGet struct {
|
||||||
|
CountOutput bool `json:"countOutput,omitempty"`
|
||||||
|
Editable bool `json:"editable,omitempty"`
|
||||||
|
ExcludeSearch bool `json:"excludeSearch,omitempty"`
|
||||||
|
Limit int `json:"limit,omitempty"`
|
||||||
|
Output string `json:"output,omitempty"`
|
||||||
|
PreserveKeys bool `json:"preserveKeys,omitempty"`
|
||||||
|
SearchByAny bool `json:"searchByAny,omitempty"`
|
||||||
|
SearchWildcardsEnabled bool `json:"searchWildcardsEnabled,omitempty"`
|
||||||
|
Sortorder string `json:"sortorder,omitempty"`
|
||||||
|
startSearch bool `json:"startSearch,omitempty"`
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user