zabbix: Index | Examples | Files

package zabbix

import ""

Package zabbix provides access to Zabbix API.

Before using it make sure you run tests as described in README:



Package Files

application.go base.go doc.go host.go host_group.go host_interface.go item.go


const (
    Available   AvailableType = 1
    Unavailable AvailableType = 2

    Monitored   StatusType = 0
    Unmonitored StatusType = 1
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

type API Uses

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 Uses

func NewAPI(url string) (api *API)

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 Uses

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 Uses

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 Uses

func (api *API) ApplicationsCreate(apps Applications) (err error)

Wrapper for application.create:

func (*API) ApplicationsDelete Uses

func (api *API) ApplicationsDelete(apps Applications) (err error)

Wrapper for application.delete: Cleans ApplicationId in all apps elements if call succeed.

func (*API) ApplicationsDeleteByIds Uses

func (api *API) ApplicationsDeleteByIds(ids []string) (err error)

Wrapper for application.delete:

func (*API) ApplicationsGet Uses

func (api *API) ApplicationsGet(params Params) (res Applications, err error)

Wrapper for application.get:

func (*API) Call Uses

func (api *API) Call(method string, params interface{}) (response Response, err error)

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.


api := NewAPI("http://host/api_jsonrpc.php")
api.Login("user", "password")
res, _ := api.Call("item.get", Params{"itemids": "23970", "output": "extend"})

func (*API) CallWithError Uses

func (api *API) CallWithError(method string, params interface{}) (response Response, err error)

Uses Call() and then sets err to response.Error if former is nil and latter is not.

func (*API) HostGetByHost Uses

func (api *API) HostGetByHost(host string) (res *Host, err error)

Gets host by Host only if there is exactly 1 matching host.

func (*API) HostGetById Uses

func (api *API) HostGetById(id string) (res *Host, err error)

Gets host by Id only if there is exactly 1 matching host.

func (*API) HostGroupGetById Uses

func (api *API) HostGroupGetById(id string) (res *HostGroup, err error)

Gets host group by Id only if there is exactly 1 matching host group.

func (*API) HostGroupsCreate Uses

func (api *API) HostGroupsCreate(hostGroups HostGroups) (err error)

Wrapper for hostgroup.create:

func (*API) HostGroupsDelete Uses

func (api *API) HostGroupsDelete(hostGroups HostGroups) (err error)

Wrapper for hostgroup.delete: Cleans GroupId in all hostGroups elements if call succeed.

func (*API) HostGroupsDeleteByIds Uses

func (api *API) HostGroupsDeleteByIds(ids []string) (err error)

Wrapper for hostgroup.delete:

func (*API) HostGroupsGet Uses

func (api *API) HostGroupsGet(params Params) (res HostGroups, err error)

Wrapper for hostgroup.get:

func (*API) HostsCreate Uses

func (api *API) HostsCreate(hosts Hosts) (err error)

Wrapper for host.create:

func (*API) HostsDelete Uses

func (api *API) HostsDelete(hosts Hosts) (err error)

Wrapper for host.delete: Cleans HostId in all hosts elements if call succeed.

func (*API) HostsDeleteByIds Uses

func (api *API) HostsDeleteByIds(ids []string) (err error)

Wrapper for host.delete:

func (*API) HostsGet Uses

func (api *API) HostsGet(params Params) (res Hosts, err error)

Wrapper for host.get:

func (*API) HostsGetByHostGroupIds Uses

func (api *API) HostsGetByHostGroupIds(ids []string) (res Hosts, err error)

Gets hosts by host group Ids.

func (*API) HostsGetByHostGroups Uses

func (api *API) HostsGetByHostGroups(hostGroups HostGroups) (res Hosts, err error)

Gets hosts by host groups.

func (*API) ItemsCreate Uses

func (api *API) ItemsCreate(items Items) (err error)

Wrapper for item.create:

func (*API) ItemsDelete Uses

func (api *API) ItemsDelete(items Items) (err error)

Wrapper for item.delete: Cleans ItemId in all items elements if call succeed.

func (*API) ItemsDeleteByIds Uses

func (api *API) ItemsDeleteByIds(ids []string) (err error)

Wrapper for item.delete:

func (*API) ItemsGet Uses

func (api *API) ItemsGet(params Params) (res Items, err error)

Wrapper for item.get

func (*API) ItemsGetByApplicationId Uses

func (api *API) ItemsGetByApplicationId(id string) (res Items, err error)

Gets items by application Id.

func (*API) Login Uses

func (api *API) Login(user, password string) (auth string, err error)

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) SetClient Uses

func (api *API) SetClient(c *http.Client)

Allows one to use specific http.Client, for example with InsecureSkipVerify transport.

func (*API) Version Uses

func (api *API) Version() (v string, err error)

Calls "APIInfo.version" API method. This method temporary modifies API structure and should not be called concurrently with other methods.

type Application Uses

type Application struct {
    ApplicationId string `json:"applicationid,omitempty"`
    HostId        string `json:"hostid"`
    Name          string `json:"name"`
    TemplateId    string `json:"templateid,omitempty"`

type Applications Uses

type Applications []Application

type AvailableType Uses

type AvailableType int

type DataType Uses

type DataType int

type DeltaType Uses

type DeltaType int

type Error Uses

type Error struct {
    Code    int    `json:"code"`
    Message string `json:"message"`
    Data    string `json:"data"`

func (*Error) Error Uses

func (e *Error) Error() string

type ExpectedMore Uses

type ExpectedMore struct {
    Expected int
    Got      int

func (*ExpectedMore) Error Uses

func (e *ExpectedMore) Error() string

type ExpectedOneResult Uses

type ExpectedOneResult int

func (*ExpectedOneResult) Error Uses

func (e *ExpectedOneResult) Error() string

type Host Uses

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"`

    // Fields below used only when creating hosts
    GroupIds   HostGroupIds   `json:"groups,omitempty"`
    Interfaces HostInterfaces `json:"interfaces,omitempty"`

type HostGroup Uses

type HostGroup struct {
    GroupId  string       `json:"groupid,omitempty"`
    Name     string       `json:"name"`
    Internal InternalType `json:"internal,omitempty"`

type HostGroupId Uses

type HostGroupId struct {
    GroupId string `json:"groupid"`

type HostGroupIds Uses

type HostGroupIds []HostGroupId

type HostGroups Uses

type HostGroups []HostGroup

type HostInterface Uses

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"`

type HostInterfaces Uses

type HostInterfaces []HostInterface

type Hosts Uses

type Hosts []Host

type InterfaceType Uses

type InterfaceType int
const (
    Agent InterfaceType = 1
    SNMP  InterfaceType = 2
    IPMI  InterfaceType = 3
    JMX   InterfaceType = 4

type InternalType Uses

type InternalType int
const (
    NotInternal InternalType = 0
    Internal    InternalType = 1

type Item Uses

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"`

type ItemType Uses

type ItemType int

type Items Uses

type Items []Item

func (Items) ByKey Uses

func (items Items) ByKey() (res map[string]Item)

Converts slice to map by key. Panics if there are duplicate keys.

type Params Uses

type Params map[string]interface{}

type Response Uses

type Response struct {
    Jsonrpc string      `json:"jsonrpc"`
    Error   *Error      `json:"error"`
    Result  interface{} `json:"result"`
    Id      int32       `json:"id"`

type StatusType Uses

type StatusType int

type ValueType Uses

type ValueType int

Package zabbix imports 8 packages (graph) and is imported by 1 packages. Updated 2018-06-08. Refresh now. Tools for package owners.