Skip to content

Commit

Permalink
Transform package code for Zabbix API v5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
borisershov committed May 15, 2020
1 parent 91fecc4 commit be2c480
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 148 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# nxs-go-zabbix

This Go package provides access to Zabbix API v4.4.
This Go package provides access to Zabbix API v5.0.
Also see older versions in other branches.

At the time not all Zabbix API methods are implemented, but work in progress.

## Install

```
go get github.com/nixys/nxs-go-zabbix/v4
go get github.com/nixys/nxs-go-zabbix/v5
```

## Example of usage
Expand All @@ -23,7 +24,7 @@ import (
"fmt"
"os"

"github.com/nixys/nxs-go-zabbix/v4"
"github.com/nixys/nxs-go-zabbix/v5"
)

func zabbixLogin(z *zabbix.Context, zbxHost, zbxUsername, zbxPassword string) {
Expand Down
50 changes: 21 additions & 29 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
// For `ActionOperationMessageObject` field: `DefaultMsg`
const (
ActionOperationMessageDefaultMsgFromOperation = 0
ActionOperationMessageDefaultMsgFromAction = 1
ActionOperationMessageDefaultMsgFromMediaType = 1
)

// For `ActionOperationConditionObject` field: `ConditionType`
Expand Down Expand Up @@ -141,18 +141,12 @@ const (

// ActionObject struct is used to store action operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action
type ActionObject struct {
ActionID int `json:"actionid,omitempty"`
EscPeriod int `json:"esc_period"`
Eventsource int `json:"eventsource"`
Name string `json:"name"`
DefLongdata string `json:"def_longdata,omitempty"`
DefShortdata string `json:"def_shortdata,omitempty"`
RlongData string `json:"r_longdata,omitempty"`
RshortData string `json:"r_shortdata,omitempty"`
AckLongdata string `json:"ack_longdata,omitempty"`
AckShortdata string `json:"ack_shortdata,omitempty"`
Status int `json:"status,omitempty"` // has defined consts, see above
PauseSuppressed int `json:"pause_suppressed,omitempty"` // has defined consts, see above

Expand All @@ -164,7 +158,7 @@ type ActionObject struct {

// ActionOperationObject struct is used to store action operations
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_operation
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation
type ActionOperationObject struct {
OperationID int `json:"operationid,omitempty"`
OperationType int `json:"operationtype"` // has defined consts, see above
Expand All @@ -187,26 +181,24 @@ type ActionOperationObject struct {

// ActionOperationCommandObject struct is used to store action operation commands
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_operation_command
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation_command
type ActionOperationCommandObject struct {
OperationID int `json:"operationid,omitempty"`
Command string `json:"command"`
Type int `json:"type"` // has defined consts, see above
AuthType int `json:"authtype,omitempty"` // has defined consts, see above
ExecuteOn int `json:"execute_on,omitempty"` // has defined consts, see above
Password string `json:"password,omitempty"`
Port string `json:"port,omitempty"`
PrivateKey string `json:"privatekey,omitempty"`
PublicKey string `json:"publickey,omitempty"`
ScriptID int `json:"scriptid,omitempty"`
UserName string `json:"username,omitempty"`
Command string `json:"command"`
Type int `json:"type"` // has defined consts, see above
AuthType int `json:"authtype,omitempty"` // has defined consts, see above
ExecuteOn int `json:"execute_on,omitempty"` // has defined consts, see above
Password string `json:"password,omitempty"`
Port string `json:"port,omitempty"`
PrivateKey string `json:"privatekey,omitempty"`
PublicKey string `json:"publickey,omitempty"`
ScriptID int `json:"scriptid,omitempty"`
UserName string `json:"username,omitempty"`
}

// ActionOperationMessageObject struct is used to store action operation messages
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_operation_message
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation_message
type ActionOperationMessageObject struct {
OperationID int `json:"operationid,omitempty"`
DefaultMsg int `json:"default_msg,omitempty"` // has defined consts, see above
MediatypeID int `json:"mediatypeid,omitempty"`
Message string `json:"message,omitempty"`
Expand All @@ -215,7 +207,7 @@ type ActionOperationMessageObject struct {

// ActionOperationConditionObject struct is used to store action operation conditions
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_operation_condition
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation_condition
type ActionOperationConditionObject struct {
OpconditionID int `json:"opconditionid,omitempty"`
ConditionType int `json:"conditiontype"` // has defined consts, see above
Expand All @@ -226,7 +218,7 @@ type ActionOperationConditionObject struct {

// ActionRecoveryOperationObject struct is used to store action recovery operations
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_recovery_operation
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_recovery_operation
type ActionRecoveryOperationObject struct {
OperationID int `json:"operationid"`
OperationType int `json:"operationtype,omitempty"` // has defined consts, see above
Expand All @@ -241,7 +233,7 @@ type ActionRecoveryOperationObject struct {

// ActionUpdateOperationObject struct is used to store action update operations
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_update_operation
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_update_operation
type ActionUpdateOperationObject struct {
OperationID int `json:"operationid"`
OperationType int `json:"operationtype,omitempty"` // has defined consts, see above
Expand All @@ -255,7 +247,7 @@ type ActionUpdateOperationObject struct {

// ActionFilterObject struct is used to store action filters
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_filter
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter
type ActionFilterObject struct {
Conditions []ActionFilterConditionObject `json:"conditions"`
EvalType int `json:"evaltype"` // has defined consts, see above
Expand All @@ -265,7 +257,7 @@ type ActionFilterObject struct {

// ActionFilterConditionObject struct is used to store action filter conditions
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/object#action_filter_condition
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter_condition
type ActionFilterConditionObject struct {
ConditionID int `json:"conditionid,omitempty"`
ConditionType int `json:"conditiontype"` // has defined consts, see above
Expand Down Expand Up @@ -322,7 +314,7 @@ type ActionOpinventoryObject struct {

// ActionGetParams struct is used for action get requests
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/action/get#parameters
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/get#parameters
type ActionGetParams struct {
GetParameters

Expand Down
10 changes: 4 additions & 6 deletions action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ func testActionCreate(t *testing.T, z Context, hostgrpID, usergrpID int) []int {

aCreatedIDs, _, err := z.ActionCreate([]ActionObject{
{
Name: testActionName,
Eventsource: 0,
Status: ActionStatusEnabled,
EscPeriod: testActionEscPeriod,
DefShortdata: testActionDefShortdata,
DefLongdata: testActionDefLongdata,
Name: testActionName,
Eventsource: 0,
Status: ActionStatusEnabled,
EscPeriod: testActionEscPeriod,
Filter: ActionFilterObject{
EvalType: ActionFilterEvalTypeAndOr,
Conditions: []ActionFilterConditionObject{
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/nixys/nxs-go-zabbix/v4
module github.com/nixys/nxs-go-zabbix/v5

go 1.13
go 1.14

require github.com/mitchellh/mapstructure v1.2.2
require github.com/mitchellh/mapstructure v1.3.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/mitchellh/mapstructure v1.2.2 h1:dxe5oCinTXiTIcfgmZecdCzPmAJKd46KsCWc35r0TV4=
github.com/mitchellh/mapstructure v1.2.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.3.0 h1:iDwIio/3gk2QtLLEsqU5lInaMzos0hDTz8a6lazSFVw=
github.com/mitchellh/mapstructure v1.3.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
12 changes: 6 additions & 6 deletions history.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (

// HistoryFloatObject struct is used to store history float operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/history/object#float_history
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#float_history
type HistoryFloatObject struct {
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
Expand All @@ -23,7 +23,7 @@ type HistoryFloatObject struct {

// HistoryIntegerObject struct is used to store history integer operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/history/object#integer_history
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#integer_history
type HistoryIntegerObject struct {
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
Expand All @@ -33,7 +33,7 @@ type HistoryIntegerObject struct {

// HistoryStringObject struct is used to store history string operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/history/object#string_history
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#string_history
type HistoryStringObject struct {
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
Expand All @@ -43,7 +43,7 @@ type HistoryStringObject struct {

// HistoryTextObject struct is used to store history text operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/history/object#text_history
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#text_history
type HistoryTextObject struct {
ID int `json:"id,omitempty"`
Clock int `json:"clock,omitempty"`
Expand All @@ -54,7 +54,7 @@ type HistoryTextObject struct {

// HistoryLogObject struct is used to store history log operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/history/object#log_history
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#log_history
type HistoryLogObject struct {
ID int `json:"id,omitempty"`
Clock int `json:"clock,omitempty"`
Expand All @@ -69,7 +69,7 @@ type HistoryLogObject struct {

// HistoryGetParams struct is used for history get requests
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/history/get#parameters
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/get#parameters
type HistoryGetParams struct {
GetParameters

Expand Down
4 changes: 2 additions & 2 deletions history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
testHistoryItemID = "44876"
testHistoryItemID = 45503
testHistoryType = 0
)

Expand All @@ -27,7 +27,7 @@ func testHistoryGet(t *testing.T, z Context) []HistoryFloatObject {

hObjects, _, err := z.HistoryGet(HistoryGetParams{
History: HistoryObjectTypeFloat,
ItemIDs: []int{44876},
ItemIDs: []int{testHistoryItemID},
GetParameters: GetParameters{
Limit: 1,
},
Expand Down
69 changes: 36 additions & 33 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const (

// HostObject struct is used to store host operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/host/object#host
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/object#host
type HostObject struct {
HostID int `json:"hostid,omitempty"`
Host string `json:"host,omitempty"`
Expand Down Expand Up @@ -140,27 +140,26 @@ type HostObject struct {
SnmpDisableUntil int `json:"snmp_disable_until,omitempty"`
SnmpError string `json:"snmp_error,omitempty"`
SnmpErrorsFrom int `json:"snmp_errors_from,omitempty"`
Status int `json:"status,omitempty"` // has defined consts, see above

TLSConnect int `json:"tls_connect,omitempty"` // has defined consts, see above
TLSAccept int `json:"tls_accept,omitempty"` // has defined consts, see above
TLSIssuer string `json:"tls_issuer,omitempty"`
TLSSubject string `json:"tls_subject,omitempty"`
TLSPSKIdentity string `json:"tls_psk_identity,omitempty"`
TLSPSK string `json:"tls_psk,omitempty"`

Groups []HostgroupObject `json:"groups,omitempty"`
Interfaces []HostinterfaceObject `json:"interfaces,omitempty"`
Tags []HostTagObject `json:"tags,omitempty"`
Macros []UsermacroObject `json:"macros,omitempty"`

ParentTemplates []TemplateObject `json:"parentTemplates,omitempty"` // Used to store result for `get` operations
Templates []TemplateObject `json:"templates,omitempty"` // Used for `create` operations
Status int `json:"status,omitempty"` // has defined consts, see above
TLSConnect int `json:"tls_connect,omitempty"` // has defined consts, see above
TLSAccept int `json:"tls_accept,omitempty"` // has defined consts, see above
TLSIssuer string `json:"tls_issuer,omitempty"`
TLSSubject string `json:"tls_subject,omitempty"`
TLSPSKIdentity string `json:"tls_psk_identity,omitempty"`
TLSPSK string `json:"tls_psk,omitempty"`

Groups []HostgroupObject `json:"groups,omitempty"`
Interfaces []HostinterfaceObject `json:"interfaces,omitempty"`
Tags []HostTagObject `json:"tags,omitempty"`
InheritedTags []HostTagObject `json:"inheritedTags,omitempty"`
Macros []UsermacroObject `json:"macros,omitempty"`
Templates []TemplateObject `json:"templates,omitempty"` // Used for `create` operations
ParentTemplates []TemplateObject `json:"parentTemplates,omitempty"` // Used to store result for `get` operations
}

// HostTagObject struct is used to store host tag
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/host/object#host_tag
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/object#host_tag
type HostTagObject struct {
Tag string `json:"tag"`
Value string `json:"value,omitempty"`
Expand All @@ -170,7 +169,7 @@ type HostTagObject struct {

// HostGetParams struct is used for host get requests
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/host/get#parameters
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/get#parameters
type HostGetParams struct {
GetParameters

Expand Down Expand Up @@ -202,24 +201,28 @@ type HostGetParams struct {
WithMonitoredTriggers bool `json:"with_monitored_triggers,omitempty"`
WithSimpleGraphItems bool `json:"with_simple_graph_items,omitempty"`
WithTriggers bool `json:"with_triggers,omitempty"`
WithProblemsSuppressed bool `json:"withProblemsSuppressed,omitempty"`
Evaltype int `json:"evaltype,omitempty"` // has defined consts, see above
Severities []int `json:"severities,omitempty"`
Tags []HostTagObject `json:"tags,omitempty"`

SelectGroups SelectQuery `json:"selectGroups,omitempty"`
SelectApplications SelectQuery `json:"selectApplications,omitempty"`
SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"`
SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule ,omitempty"`
SelectGraphs SelectQuery `json:"selectGraphs,omitempty"`
SelectHostDiscovery SelectQuery `json:"selectHostDiscovery ,omitempty"`
SelectHTTPTests SelectQuery `json:"selectHttpTests,omitempty"`
SelectInterfaces SelectQuery `json:"selectInterfaces,omitempty"`
SelectInventory SelectQuery `json:"selectInventory,omitempty"`
SelectItems SelectQuery `json:"selectItems,omitempty"`
InheritedTags bool `json:"inheritedTags,omitempty"`

// SelectApplications SelectQuery `json:"selectApplications,omitempty"` // not implemented yet
// SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"` // not implemented yet
// SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule ,omitempty"` // not implemented yet
// SelectGraphs SelectQuery `json:"selectGraphs,omitempty"` // not implemented yet
SelectGroups SelectQuery `json:"selectGroups,omitempty"`
// SelectHostDiscovery SelectQuery `json:"selectHostDiscovery ,omitempty"` // not implemented yet
// SelectHTTPTests SelectQuery `json:"selectHttpTests,omitempty"` // not implemented yet
SelectInterfaces SelectQuery `json:"selectInterfaces,omitempty"`
// SelectInventory SelectQuery `json:"selectInventory,omitempty"` // not implemented yet
// SelectItems SelectQuery `json:"selectItems,omitempty"` // not implemented yet
SelectMacros SelectQuery `json:"selectMacros,omitempty"`
SelectParentTemplates SelectQuery `json:"selectParentTemplates,omitempty"`
SelectScreens SelectQuery `json:"selectScreens,omitempty"`
SelectTags SelectQuery `json:"selectTags,omitempty"`
SelectTriggers SelectQuery `json:"selectTriggers,omitempty"`
// SelectScreens SelectQuery `json:"selectScreens,omitempty"` // not implemented yet
SelectTags SelectQuery `json:"selectTags,omitempty"`
SelectInheritedTags SelectQuery `json:"selectInheritedTags,omitempty"`
// SelectTriggers SelectQuery `json:"selectTriggers,omitempty"` // not implemented yet
}

// Structure to store creation result
Expand Down
4 changes: 2 additions & 2 deletions hostgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (

// HostgroupObject struct is used to store hostgroup operations results
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/hostgroup/object
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostgroup/object
type HostgroupObject struct {
GroupID int `json:"groupid,omitempty"`
Name string `json:"name,omitempty"`
Expand All @@ -27,7 +27,7 @@ type HostgroupObject struct {

// HostgroupGetParams struct is used for hostgroup get requests
//
// see: https://www.zabbix.com/documentation/4.4/manual/api/reference/hostgroup/get#parameters
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostgroup/get#parameters
type HostgroupGetParams struct {
GetParameters

Expand Down
Loading

0 comments on commit be2c480

Please sign in to comment.