Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# yo000 Fork
An update to v7 API, where authentication is done via Authorization header.
Add item support

# nxs-go-zabbix

This Go package provides access to Zabbix API v5.0.
Expand Down Expand Up @@ -104,4 +108,4 @@ For support and feedback please contact me:

## License

nxs-go-zabbix is released under the [MIT License](LICENSE).
nxs-go-zabbix is released under the [MIT License](LICENSE).
11 changes: 11 additions & 0 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ const (
HostTagOperatorEquals = 1
)

// For `MonitoredBy` field: `Operator`
const (
MonitoredByZabbixServer = 0
MonitoredByProxy = 1
MonitoredByProxyGroup = 2
)


// HostObject struct is used to store host operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/object#host
Expand Down Expand Up @@ -135,7 +143,9 @@ type HostObject struct {
MaintenanceType int `json:"maintenance_type,omitempty"` // has defined consts, see above
MaintenanceID int `json:"maintenanceid,omitempty"`
Name string `json:"name,omitempty"`
MonitoredBy int `json:"monitored_by,omitempty"` // has defined consts, see above
ProxyHostID int `json:"proxy_hostid,omitempty"`
ProxyGroupID int `json:"proxy_groupid,omitempty"`
SnmpAvailable int `json:"snmp_available,omitempty"` // has defined consts, see above
SnmpDisableUntil int `json:"snmp_disable_until,omitempty"`
SnmpError string `json:"snmp_error,omitempty"`
Expand Down Expand Up @@ -184,6 +194,7 @@ type HostGetParams struct {
MaintenanceIDs []int `json:"maintenanceids,omitempty"`
MonitoredHosts bool `json:"monitored_hosts,omitempty"`
ProxyHosts bool `json:"proxy_hosts,omitempty"`
ProxyGroupIDs []int `json:"proxy_groupids,omitempty"`
ProxyIDs []int `json:"proxyids,omitempty"`
TemplatedHosts bool `json:"templated_hosts,omitempty"`
TemplateIDs []int `json:"templateids,omitempty"`
Expand Down
183 changes: 183 additions & 0 deletions item.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package zabbix

// For `ItemObject` field: `ItemType`
const (
ItemTypeZabbixAgent = 0
ItemTypeZabbixTrapper = 2
ItemTypeSimpleCheck = 3
ItemTypeZabbixInternal = 5
ItemTypeZabbixAgentActive = 7
ItemTypeWebItem = 9
ItemTypeExternalCheck = 10
ItemTypeDBMonitor = 11
ItemTypeIPMIAgent = 12
ItemTypeSSHAgent = 13
ItemTypeTelnetAgent = 14
ItemTypeCalculated = 15
ItemTypeJMXAgent = 16
ItemTypeSNMPTrap = 17
ItemTypeDependentItem = 18
ItemTypeHTTPAgent = 19
ItemTypeSNMPAgent = 20
ItemTypeScript = 21
ItemTypeBrowser = 22
)

// For `ItemObject` field: `ValueType`
const (
ItemValueTypeNumericFloat = 0
ItemValueTypeCharacter = 1
ItemValueTypeLog = 2
ItemValueTypeNumericUnsigned = 3
ItemValueTypeText = 4
ItemValueTypeBinary = 5
)

// For `ItemObject` field: `Status`
const (
ItemStatusEnabled = 0
ItemStatusDisabled = 1
)

// For `ItemGetParams` field: `Evaltype`
const (
ItemEvaltypeAndOr = 0
ItemEvaltypeOr = 2
)

// TemplateObject struct is used to store template operations results
//
// see: https://www.zabbix.com/documentation/7.0/manual/api/reference/template/object
type ItemObject struct {
ItemID int `json:"itemid,omitempty"`
Delay string `json:"delay,omitempty"`
HostID int `json:"hostid,omitempty"`
InterfaceID int `json:"interfaceid,omitempty"`
Key string `json:"key_,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ItemType int `json:"type,omitempty"`
ValueType int `json:"value_type,omitempty"`
SnmpOID string `json:"snmp_oid,omitempty"`
Status int `json:"status,omitempty"`
TemplateID int `json:"templateid,omitempty"`
UUID string `json:"uuid,omitempty"`

Groups []HostgroupObject `json:"groups,omitempty"`
Tags []ItemTagObject `json:"tags,omitempty"`
Templates []TemplateObject `json:"templates,omitempty"`
ParentTemplates []TemplateObject `json:"parentTemplates,omitempty"`
Macros []UsermacroObject `json:"macros,omitempty"`
Hosts []HostObject `json:"hosts,omitempty"`
}

// ItemTagObject struct is used to store item tag data
//
// see: https://www.zabbix.com/documentation/7.0/manual/api/reference/template/object#template_tag
type ItemTagObject struct {
Tag string `json:"tag,omitempty"`
Value string `json:"value,omitempty"`
}

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

ItemIDs []int `json:"itemids,omitempty"`
GroupIDs []int `json:"groupids,omitempty"`
TemplateIDs []int `json:"templateids,omitempty"`
HostIDs []int `json:"hostids,omitempty"`
ProxyIDs []int `json:"proxyids,omitempty"`
GraphIDs []int `json:"graphids,omitempty"`
TriggerIDs []int `json:"triggerids,omitempty"`

Inherited bool `json:"inherited,omitempty"`
Templated bool `json:"templated,omitempty"`
Monitored bool `json:"monitored,omitempty"`
Group string `json:"group,omitempty"`
Host string `json:"host,omitempty"`
WithItems bool `json:"with_items,omitempty"`
WithTriggers bool `json:"with_triggers,omitempty"`
Evaltype int `json:"evaltype,omitempty"` // has defined consts, see above
Tags []ItemTagObject `json:"tags,omitempty"`

SelectTags SelectQuery `json:"selectTags,omitempty"`
SelectHosts SelectQuery `json:"selectHosts,omitempty"`
SelectInterfaces SelectQuery `json:"selectInterfaces,omitempty"`
selectTriggers SelectQuery `json:"selectTriggers,omitempty"`

// SelectHttpTests SelectQuery `json:"selectHttpTests,omitempty"` // not implemented yet
// SelectItems SelectQuery `json:"selectItems,omitempty"` // not implemented yet
// SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"` // not implemented yet
// SelectTriggers SelectQuery `json:"selectTriggers,omitempty"` // not implemented yet
// SelectGraphs SelectQuery `json:"selectGraphs,omitempty"` // not implemented yet
// SelectApplications SelectQuery `json:"selectApplications,omitempty"` // not implemented yet
// SelectScreens SelectQuery `json:"selectScreens,omitempty"` // not implemented yet
}

// Structure to store creation result
type itemCreateResult struct {
ItemIDs []int `json:"itemids"`
}

type itemUpdateResult itemCreateResult
type itemDeleteResult itemCreateResult

/*// Structure to store deletion result
type itemDeleteResult struct {
ItemIDs []int `json:"itemids"`
}*/

// ItemGet gets items
func (z *Context) ItemGet(params ItemGetParams) ([]ItemObject, int, error) {

var result []ItemObject

status, err := z.request("item.get", params, &result)
if err != nil {
return nil, status, err
}

return result, status, nil
}

// ItemCreate creates items
func (z *Context) ItemCreate(params []ItemObject) ([]int, int, error) {

var result itemCreateResult

status, err := z.request("item.create", params, &result)
if err != nil {
return nil, status, err
}

return result.ItemIDs, status, nil
}

// ItemUpdate updates items
func (z *Context) ItemUpdate(params []ItemObject) ([]int, int, error) {

var result itemUpdateResult

status, err := z.request("item.update", params, &result)
if err != nil {
return nil, status, err
}

return result.ItemIDs, status, nil
}

// TemplateDelete deletes templates
func (z *Context) ItemDelete(itemIDs []int) ([]int, int, error) {

var result itemDeleteResult

status, err := z.request("item.delete", itemIDs, &result)
if err != nil {
return nil, status, err
}

return result.ItemIDs, status, nil
}
Loading