commit 010ee8a64eb5f25ebf4649953d28e463847e3f82 Author: saul365 Date: Thu Aug 21 17:57:43 2025 -0600 First commit: Add connection struct and define History diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..10989fe --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go-zabbix + +go 1.22.12 diff --git a/history.go b/history.go new file mode 100644 index 0000000..4e0d4ca --- /dev/null +++ b/history.go @@ -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) + } + + + +} + diff --git a/host.go b/host.go new file mode 100644 index 0000000..943a37f --- /dev/null +++ b/host.go @@ -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 + +} diff --git a/zabbix.go b/zabbix.go new file mode 100644 index 0000000..41dceff --- /dev/null +++ b/zabbix.go @@ -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"` + +}