Documentation ¶
Overview ¶
Package zabbix provides access to Zabbix API.
Before using it make sure you run tests as described in README: https://github.com/AlekSi/zabbix
Index ¶
- Constants
- type API
- func (api *API) ApplicationGetByHostIdAndName(hostId, name string) (res *Application, err error)
- func (api *API) ApplicationGetById(id string) (res *Application, err error)
- func (api *API) ApplicationsCreate(apps Applications) (err error)
- func (api *API) ApplicationsDelete(apps Applications) (err error)
- func (api *API) ApplicationsDeleteByIds(ids []string) (err error)
- func (api *API) ApplicationsGet(params Params) (res Applications, err error)
- func (api *API) Call(method string, params interface{}) (response Response, err error)
- func (api *API) CallWithError(method string, params interface{}) (response Response, err error)
- func (api *API) HostGetByHost(host string) (res *Host, err error)
- func (api *API) HostGetById(id string) (res *Host, err error)
- func (api *API) HostGroupGetById(id string) (res *HostGroup, err error)
- func (api *API) HostGroupsCreate(hostGroups HostGroups) (err error)
- func (api *API) HostGroupsDelete(hostGroups HostGroups) (err error)
- func (api *API) HostGroupsDeleteByIds(ids []string) (err error)
- func (api *API) HostGroupsGet(params Params) (res HostGroups, err error)
- func (api *API) HostGroupsUpdate(hostGroups HostGroups) (err error)
- func (api *API) HostsCreate(hosts Hosts) (err error)
- func (api *API) HostsDelete(hosts Hosts) (err error)
- func (api *API) HostsDeleteByIds(ids []string) (err error)
- func (api *API) HostsGet(params Params) (res Hosts, err error)
- func (api *API) HostsGetByHostGroupIds(ids []string) (res Hosts, err error)
- func (api *API) HostsGetByHostGroups(hostGroups HostGroups) (res Hosts, err error)
- func (api *API) HostsUpdate(hosts Hosts) (err error)
- func (api *API) ItemsCreate(items Items) (err error)
- func (api *API) ItemsDelete(items Items) (err error)
- func (api *API) ItemsDeleteByIds(ids []string) (err error)
- func (api *API) ItemsGet(params Params) (res Items, err error)
- func (api *API) ItemsGetByApplicationId(id string) (res Items, err error)
- func (api *API) Login(user, password string) (auth string, err error)
- func (api *API) ProxiesCreate(proxies Proxies) (err error)
- func (api *API) ProxiesDelete(proxies Proxies) (err error)
- func (api *API) ProxiesDeleteByIds(ids []string) (err error)
- func (api *API) ProxiesGet(params Params) (res Proxies, err error)
- func (api *API) ProxiesUpdate(proxies Proxies) (err error)
- func (api *API) ProxyGetById(id string) (res *Proxy, err error)
- func (api *API) ProxyGetByProxy(proxy string) (res *Proxy, err error)
- func (api *API) SetClient(c *http.Client)
- func (api *API) TemplatesGet(params Params) (res Templates, err error)
- func (api *API) Version() (v string, err error)
- type Application
- type Applications
- type AvailableType
- type DataType
- type DeltaType
- type Error
- type ExpectedMore
- type ExpectedOneResult
- type Host
- type HostGroup
- type HostGroupId
- type HostGroupIds
- type HostGroups
- type HostInterface
- type HostInterfaces
- type Hosts
- type InterfaceType
- type InternalType
- type Item
- type ItemType
- type Items
- type Params
- type Proxies
- type Proxy
- type Response
- type StatusType
- type Template
- type TemplateId
- type TemplateIds
- type Templates
- type TimestampType
- type ValueType
Examples ¶
Constants ¶
const ( ZabbixAgent ItemType = 0 SNMPv1Agent ItemType = 1 ZabbixTrapper ItemType = 2 SimpleCheck ItemType = 3 SNMPv2Agent ItemType = 4 ZabbixInternal ItemType = 5 SNMPv3Agent ItemType = 6 ZabbixAgentActive ItemType = 7 ZabbixAggregate ItemType = 8 WebItem ItemType = 9 ExternalCheck ItemType = 10 DatabaseMonitor ItemType = 11 IPMIAgent ItemType = 12 SSHAgent ItemType = 13 TELNETAgent ItemType = 14 Calculated ItemType = 15 JMXAgent ItemType = 16 Float ValueType = 0 Character ValueType = 1 Log ValueType = 2 Unsigned ValueType = 3 Text ValueType = 4 Decimal DataType = 0 Octal DataType = 1 Hexadecimal DataType = 2 Boolean DataType = 3 AsIs DeltaType = 0 Speed DeltaType = 1 Delta DeltaType = 2 )
const ( Available AvailableType = 1 Monitored StatusType = 0 Unmonitored StatusType = 1 ActiveProxy StatusType = 5 PassiveProxy StatusType = 6 )
const ( ZbxApiErrorParameters int = -32602 ZbxApiErrorInternal int = -32500 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { Auth string // auth token, filled by Login() Logger *log.Logger // request/response logger, nil by default // contains filtered or unexported fields }
func NewAPI ¶
Creates new API access object. Typical URL is http://host/api_jsonrpc.php or http://host/zabbix/api_jsonrpc.php. It also may contain HTTP basic auth username and password like http://username:password@host/api_jsonrpc.php.
func (*API) ApplicationGetByHostIdAndName ¶
func (api *API) ApplicationGetByHostIdAndName(hostId, name string) (res *Application, err error)
Gets application by host Id and name only if there is exactly 1 matching application.
func (*API) ApplicationGetById ¶
func (api *API) ApplicationGetById(id string) (res *Application, err error)
Gets application by Id only if there is exactly 1 matching application.
func (*API) ApplicationsCreate ¶
func (api *API) ApplicationsCreate(apps Applications) (err error)
Wrapper for application.create: https://www.zabbix.com/documentation/2.2/manual/appendix/api/application/create
func (*API) ApplicationsDelete ¶
func (api *API) ApplicationsDelete(apps Applications) (err error)
Wrapper for application.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/application/delete Cleans ApplicationId in all apps elements if call succeed.
func (*API) ApplicationsDeleteByIds ¶
Wrapper for application.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/application/delete
func (*API) ApplicationsGet ¶
func (api *API) ApplicationsGet(params Params) (res Applications, err error)
Wrapper for application.get: https://www.zabbix.com/documentation/2.2/manual/appendix/api/application/get
func (*API) Call ¶
Calls specified API method. Uses api.Auth if not empty. err is something network or marshaling related. Caller should inspect response.Error to get API error.
Example ¶
api := NewAPI("http://host/api_jsonrpc.php") api.Login("user", "password") res, _ := api.Call("item.get", Params{"itemids": "23970", "output": "extend"}) log.Print(res)
Output:
func (*API) CallWithError ¶
Uses Call() and then sets err to response.Error if former is nil and latter is not.
func (*API) HostGetByHost ¶
Gets host by Host only if there is exactly 1 matching host.
func (*API) HostGetById ¶
Gets host by Id only if there is exactly 1 matching host.
func (*API) HostGroupGetById ¶
Gets host group by Id only if there is exactly 1 matching host group.
func (*API) HostGroupsCreate ¶
func (api *API) HostGroupsCreate(hostGroups HostGroups) (err error)
Wrapper for hostgroup.create: https://www.zabbix.com/documentation/2.2/manual/appendix/api/hostgroup/create
func (*API) HostGroupsDelete ¶
func (api *API) HostGroupsDelete(hostGroups HostGroups) (err error)
Wrapper for hostgroup.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/hostgroup/delete Cleans GroupId in all hostGroups elements if call succeed.
func (*API) HostGroupsDeleteByIds ¶
Wrapper for hostgroup.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/hostgroup/delete
func (*API) HostGroupsGet ¶
func (api *API) HostGroupsGet(params Params) (res HostGroups, err error)
Wrapper for hostgroup.get: https://www.zabbix.com/documentation/2.2/manual/appendix/api/hostgroup/get
func (*API) HostGroupsUpdate ¶ added in v0.3.0
func (api *API) HostGroupsUpdate(hostGroups HostGroups) (err error)
Wrapper for hostgroup.update: https://www.zabbix.com/documentation/2.2/manual/api/reference/hostgroup/update
func (*API) HostsCreate ¶
Wrapper for host.create: https://www.zabbix.com/documentation/2.2/manual/appendix/api/host/create
func (*API) HostsDelete ¶
Wrapper for host.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/host/delete Cleans HostId in all hosts elements if call succeed.
func (*API) HostsDeleteByIds ¶
Wrapper for host.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/host/delete
func (*API) HostsGet ¶
Wrapper for host.get: https://www.zabbix.com/documentation/2.2/manual/appendix/api/host/get
func (*API) HostsGetByHostGroupIds ¶
Gets hosts by host group Ids.
func (*API) HostsGetByHostGroups ¶
func (api *API) HostsGetByHostGroups(hostGroups HostGroups) (res Hosts, err error)
Gets hosts by host groups.
func (*API) HostsUpdate ¶ added in v0.3.0
func (*API) ItemsCreate ¶
Wrapper for item.create: https://www.zabbix.com/documentation/2.2/manual/appendix/api/item/create
func (*API) ItemsDelete ¶
Wrapper for item.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/item/delete Cleans ItemId in all items elements if call succeed.
func (*API) ItemsDeleteByIds ¶
Wrapper for item.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/item/delete
func (*API) ItemsGet ¶
Wrapper for item.get https://www.zabbix.com/documentation/2.2/manual/appendix/api/item/get
func (*API) ItemsGetByApplicationId ¶
Gets items by application Id.
func (*API) Login ¶
Calls "user.login" API method and fills api.Auth field. This method modifies API structure and should not be called concurrently with other methods.
func (*API) ProxiesCreate ¶ added in v0.4.0
Wrapper for proxy.create: https://www.zabbix.com/documentation/2.2/manual/appendix/api/proxy/create
func (*API) ProxiesDelete ¶ added in v0.4.0
Wrapper for proxy.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/proxy/delete Cleans ProxyId in all proxies elements if call succeed.
func (*API) ProxiesDeleteByIds ¶ added in v0.4.0
Wrapper for proxy.delete: https://www.zabbix.com/documentation/2.2/manual/appendix/api/proxy/delete
func (*API) ProxiesGet ¶ added in v0.4.0
Wrapper for proxy.get: https://www.zabbix.com/documentation/2.0/manual/appendix/api/proxy/get
func (*API) ProxiesUpdate ¶ added in v0.4.0
func (*API) ProxyGetById ¶ added in v0.4.0
Gets proxy by Id only if there is exactly 1 matching proxy.
func (*API) ProxyGetByProxy ¶ added in v0.4.0
Gets proxy by Proxy only if there is exactly 1 matching proxy.
func (*API) SetClient ¶ added in v0.2.0
Allows one to use specific http.Client, for example with InsecureSkipVerify transport.
func (*API) TemplatesGet ¶ added in v0.3.0
Wrapper for template.get: https://www.zabbix.com/documentation/2.2/manual/api/reference/template/get
type Application ¶
type Application struct { ApplicationId string `json:"applicationid,omitempty"` HostId string `json:"hostid"` Name string `json:"name"` TemplateId string `json:"templateid,omitempty"` }
https://www.zabbix.com/documentation/2.2/manual/appendix/api/application/definitions
type Applications ¶
type Applications []Application
type AvailableType ¶
type AvailableType int
type Error ¶
type ExpectedMore ¶
func (*ExpectedMore) Error ¶
func (e *ExpectedMore) Error() string
type ExpectedOneResult ¶
type ExpectedOneResult int
func (*ExpectedOneResult) Error ¶
func (e *ExpectedOneResult) Error() string
type Host ¶
type Host struct { HostId string `json:"hostid,omitempty"` Host string `json:"host"` Available AvailableType `json:"available"` Error string `json:"error"` Name string `json:"name"` Status StatusType `json:"status"` TlsConnect int `json:"tls_connect"` TlsAccept int `json:"tls_accept"` TlsPskIdentity string `json:"tls_psk_identity"` TlsPsk string `json:"tls_psk"` ProxyHostId string `json:"proxy_hostid"` // Fields below used only when creating hosts GroupIds HostGroupIds `json:"groups,omitempty"` Interfaces HostInterfaces `json:"interfaces,omitempty"` TemplateIds TemplateIds `json:"templates,omitempty"` }
https://www.zabbix.com/documentation/2.2/manual/appendix/api/host/definitions
type HostGroup ¶
type HostGroup struct { GroupId string `json:"groupid,omitempty"` Name string `json:"name"` Internal InternalType `json:"internal,omitempty"` }
https://www.zabbix.com/documentation/2.2/manual/appendix/api/hostgroup/definitions
type HostGroupId ¶
type HostGroupId struct {
GroupId string `json:"groupid"`
}
type HostGroupIds ¶
type HostGroupIds []HostGroupId
type HostGroups ¶
type HostGroups []HostGroup
type HostInterface ¶
type HostInterface struct { DNS string `json:"dns"` IP string `json:"ip"` Main int `json:"main"` Port string `json:"port"` Type InterfaceType `json:"type"` UseIP int `json:"useip"` }
https://www.zabbix.com/documentation/2.2/manual/appendix/api/hostinterface/definitions
type HostInterfaces ¶
type HostInterfaces []HostInterface
type InterfaceType ¶
type InterfaceType int
const ( Agent InterfaceType = 1 SNMP InterfaceType = 2 IPMI InterfaceType = 3 JMX InterfaceType = 4 )
type InternalType ¶
type InternalType int
const ( NotInternal InternalType = 0 Internal InternalType = 1 )
type Item ¶
type Item struct { ItemId string `json:"itemid,omitempty"` Delay int `json:"delay"` HostId string `json:"hostid"` InterfaceId string `json:"interfaceid,omitempty"` Key string `json:"key_"` Name string `json:"name"` Type ItemType `json:"type"` ValueType ValueType `json:"value_type"` DataType DataType `json:"data_type"` Delta DeltaType `json:"delta"` Description string `json:"description"` Error string `json:"error"` History int `json:"history,omitempty"` Trends int `json:"trends,omitempty"` // Fields below used only when creating applications ApplicationIds []string `json:"applications,omitempty"` }
https://www.zabbix.com/documentation/2.2/manual/appendix/api/item/definitions
type Proxy ¶ added in v0.4.0
type Proxy struct { ProxyId string `json:"proxyid,omitempty"` Host string `json:"host"` Status StatusType `json:"status"` LastAccess TimestampType `json:"lastaccess"` // Fields below used only when creating proxies Interfaces HostInterfaces `json:"interfaces,omitempty"` // https://www.zabbix.com/documentation/2.2/manual/appendix/api/proxy/definitions Interface HostInterface `json:"interface,omitempty"` // https://www.zabbix.com/documentation/3.0/manual/appendix/api/proxy/definitions Description string `json:"description"` TlsConnect int `json:"tls_connect"` TlsAccept int `json:"tls_accept"` TlsPskIdentity string `json:"tls_psk_identity"` TlsPsk string `json:"tls_psk"` }
https://www.zabbix.com/documentation/2.0/manual/appendix/api/proxy/definitions
type StatusType ¶
type StatusType int
type Template ¶ added in v0.3.0
type Template struct { TemplateId string `json:"templateid,omitempty"` Host string `json:"host"` Description string `json:"description,omitempty"` Name string `json:"name,omitempty"` }
https://www.zabbix.com/documentation/2.2/manual/api/reference/template/object
type TemplateId ¶ added in v0.3.0
type TemplateId struct {
TemplateId string `json:"templateid"`
}
type TemplateIds ¶ added in v0.3.0
type TemplateIds []TemplateId
type TimestampType ¶ added in v0.4.3
type TimestampType uint64