zabbix

package module
v0.0.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2022 License: BSD-2-Clause Imports: 7 Imported by: 0

README

Go zabbix api

Build Status

GoDoc MIT License Build Status

This Go package provides access to Zabbix API.

Tested on Zabbix 3.2, 3.4, 4.0, 4.2 and 4.4, but should work since 2.0 version.

This package aims to support multiple zabbix resources from its API like trigger, application, host group, host, item, template..

Install

Install it: go get github.com/DmitriySolopenkov/go-zabbix-api

Getting started

package main

import (
	"fmt"

	"github.com/DmitriySolopenkov/go-zabbix-api"
)

func main() {
	user := "MyZabbixUsername"
	pass := "MyZabbixPassword"
	api := zabbix.NewAPI("http://localhost/api_jsonrpc.php")
	api.Login(user, pass)

	res, err := api.Version()
	if err != nil {
		panic(err)
	}
	fmt.Printf("Connected to zabbix api v%s\n", res)
}

Tests

Considerations

You should run tests before using this package. Zabbix API doesn't match documentation in few details, which are changing in patch releases.

Tests are not expected to be destructive, but you are advised to run them against not-production instance or at least make a backup. For a safer and more accurate testing we advice to run tests with following minimum versions which implements strict validation of valuemap for get method:

For more information, please see issues ZBX-3783 and ZBX-3685

Run tests
export TEST_ZABBIX_URL=http://localhost:8080/zabbix/api_jsonrpc.php
export TEST_ZABBIX_USER=Admin
export TEST_ZABBIX_PASSWORD=zabbix
export TEST_ZABBIX_VERBOSE=1
go test -v

TEST_ZABBIX_URL may contain HTTP basic auth username and password: http://username:password@host/api_jsonrpc.php. Also, in some setups URL should be like http://host/zabbix/api_jsonrpc.php.

References

Documentation is available on godoc.org. Also, Rafael Fernandes dos Santos wrote a great article about using and extending this package.

License: Simplified BSD License (see LICENSE).

Documentation

Overview

Package zabbix provides bindings to interoperate between programs written in Go language and the Zabbix monitoring API.

Tested on Zabbix 3.2 but should work since 2.0 version. This package aims to support multiple zabbix resources from its API like trigger, application, host group, host, item, template..

Install it: `go get github.com/DmitriySolopenkov/go-zabbix-api`

Getting started

package main

import (
	"fmt"

	"github.com/DmitriySolopenkov/go-zabbix-api"
)

func main() {
	user := "MyZabbixUsername"
	pass := "MyZabbixPassword"
	api := zabbix.NewAPI("http://localhost/api_jsonrpc.php")
	api.Login(user, pass)

	res, err := api.Version()
	if err != nil {
		panic(err)
	}
	fmt.Printf("Connected to zabbix api v%s\n", res)
}

Run test You should run tests before using this package – Zabbix API doesn't match documentation in few details, which are changing in patch releases. Tests are not expected to be destructive, but you are advised to run them against not-production instance or at least make a backup.

export TEST_ZABBIX_URL=http://localhost:8080/zabbix/api_jsonrpc.php
export TEST_ZABBIX_USER=Admin
export TEST_ZABBIX_PASSWORD=zabbix
export TEST_ZABBIX_VERBOSE=1
go test -v

`TEST_ZABBIX_URL` may contain HTTP basic auth username and password: `http://username:password@host/api_jsonrpc.php`. Also, in some setups URL should be like `http://host/zabbix/api_jsonrpc.php`.

Index

Constants

This section is empty.

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
	UserAgent string
	// contains filtered or unexported fields
}

API use to store connection information

func NewAPI

func NewAPI(url string) (api *API)

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)

ApplicationGetByHostIDAndName 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)

ApplicationGetByID Gets application by Id only if there is exactly 1 matching application.

func (*API) ApplicationsCreate

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

ApplicationsCreate Wrapper for application.create https://www.zabbix.com/documentation/3.2/manual/api/reference/application/create

func (*API) ApplicationsDelete

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

ApplicationsDelete Wrapper for application.delete: Cleans ApplicationID in all apps elements if call succeed. https://www.zabbix.com/documentation/2.2/manual/appendix/api/application/delete

func (*API) ApplicationsDeleteByIds

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

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)

ApplicationsGet Wrapper for application.get https://www.zabbix.com/documentation/3.2/manual/api/reference/application/get

func (*API) Call

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

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.

func (*API) CallWithError

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

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

func (*API) CallWithErrorParse

func (api *API) CallWithErrorParse(method string, params interface{}, result interface{}) (err error)

CallWithErrorParse Calls specified API method. Parse the response of the api in the result variable.

func (*API) DiscoveryRulesCreate

func (api *API) DiscoveryRulesCreate(rules LLDRules) error

DiscoveryRulesCreate Wrapper for discoveryrule.create https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/create

func (*API) DiscoveryRulesDelete

func (api *API) DiscoveryRulesDelete(rules LLDRules) (err error)

DiscoveryRulesDelete Wrapper for discoveryrule.delete Cleans ItemID in all discovery rule element if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/delete

func (*API) DiscoveryRulesDeletesByIDs

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

DiscoveryRulesDeletesByIDs Wrapper for discorveryrule.delete Delete the discovery rule with the given ids https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/delete

func (*API) DiscoveryRulesDeletesIDs

func (api *API) DiscoveryRulesDeletesIDs(ids []string) (drulsids []interface{}, err error)

DiscoveryRulesDeletesIDs Wrapper for discorveryrule.delete Delete the item and return the id of the deleted item https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/delete

func (*API) DiscoveryRulesGet

func (api *API) DiscoveryRulesGet(params Params) (res LLDRules, err error)

DiscoveryRulesGet Wrapper for discoveryrule.get https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/get

func (*API) DiscoveryRulesGetByID

func (api *API) DiscoveryRulesGetByID(id string) (res *LLDRule, err error)

DiscoveryRulesGetByID Gets discovery rule by id only if there is exactly 1 matching discovery rule.

func (*API) DiscoveryRulesUpdate

func (api *API) DiscoveryRulesUpdate(rules LLDRules) error

DiscoveryRulesUpdate Wrapper for discoveryrule.update https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/update

func (*API) HostGetByHost

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

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

func (*API) HostGetByID

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

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

func (*API) HostGroupGetByID

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

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)

HostGroupsCreate Wrapper for hostgroup.create https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/create

func (*API) HostGroupsDelete

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

HostGroupsDelete Wrapper for hostgroup.delete Cleans GroupId in all hostGroups elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/delete

func (*API) HostGroupsDeleteByIds

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

HostGroupsDeleteByIds Wrapper for hostgroup.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/delete

func (*API) HostGroupsGet

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

HostGroupsGet Wrapper for hostgroup.get https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/get

func (*API) HostGroupsUpdate

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

HostGroupsUpdate Wrapper for hostgroup.update https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/update

func (*API) HostsCreate

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

HostsCreate Wrapper for host.create https://www.zabbix.com/documentation/3.2/manual/api/reference/host/create

func (*API) HostsDelete

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

HostsDelete Wrapper for host.delete Cleans HostId in all hosts elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/host/delete

func (*API) HostsDeleteByIds

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

HostsDeleteByIds Wrapper for host.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/host/delete

func (*API) HostsGet

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

HostsGet Wrapper for host.get https://www.zabbix.com/documentation/3.2/manual/api/reference/host/get

func (*API) HostsGetByHostGroupIds

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

HostsGetByHostGroupIds Gets hosts by host group Ids.

func (*API) HostsGetByHostGroups

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

HostsGetByHostGroups Gets hosts by host groups.

func (*API) HostsUpdate

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

HostsUpdate Wrapper for host.update https://www.zabbix.com/documentation/3.2/manual/api/reference/host/update

func (*API) ItemGetByID

func (api *API) ItemGetByID(id string) (res *Item, err error)

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

func (*API) ItemPrototypeGetByID

func (api *API) ItemPrototypeGetByID(id string) (res *ItemPrototype, err error)

ItemPrototypeGetByID Gets item by Id only if there is exactly 1 matching item.

func (*API) ItemPrototypesCreate

func (api *API) ItemPrototypesCreate(items ItemPrototypes) (err error)

ItemPrototypesCreate Wrapper for item.create https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/create

func (*API) ItemPrototypesDelete

func (api *API) ItemPrototypesDelete(items ItemPrototypes) (err error)

ItemPrototypesDelete Wrapper for item.delete Cleans ItemId in all items elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/delete

func (*API) ItemPrototypesDeleteByIds

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

ItemPrototypesDeleteByIds Wrapper for item.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/delete

func (*API) ItemPrototypesDeleteIDs

func (api *API) ItemPrototypesDeleteIDs(ids []string) (itemids1 []interface{}, err error)

ItemPrototypesDeleteIDs Wrapper for item.delete Delete the item prototype and return the id of the deleted item prototype https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/delete

func (*API) ItemPrototypesGet

func (api *API) ItemPrototypesGet(params Params) (res ItemPrototypes, err error)

ItemPrototypesGet Wrapper for item.get https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/get

func (*API) ItemPrototypesUpdate

func (api *API) ItemPrototypesUpdate(items ItemPrototypes) (err error)

ItemPrototypesUpdate Wrapper for item.update https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/update

func (*API) ItemsCreate

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

ItemsCreate Wrapper for item.create https://www.zabbix.com/documentation/3.2/manual/api/reference/item/create

func (*API) ItemsDelete

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

ItemsDelete Wrapper for item.delete Cleans ItemId in all items elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/item/delete

func (*API) ItemsDeleteByIds

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

ItemsDeleteByIds Wrapper for item.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/item/delete

func (*API) ItemsDeleteIDs

func (api *API) ItemsDeleteIDs(ids []string) (itemids []interface{}, err error)

ItemsDeleteIDs Wrapper for item.delete Delete the item and return the id of the deleted item

func (*API) ItemsGet

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

ItemsGet Wrapper for item.get https://www.zabbix.com/documentation/3.2/manual/api/reference/item/get

func (*API) ItemsGetByApplicationID

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

ItemsGetByApplicationID Gets items by application Id.

func (*API) ItemsUpdate

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

ItemsUpdate Wrapper for item.update https://www.zabbix.com/documentation/3.2/manual/api/reference/item/update

func (*API) Login

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

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) MacroGetByID

func (api *API) MacroGetByID(id string) (res *Macro, err error)

MacroGetByID Get macro by macro ID if there is exactly 1 matching macro

func (*API) MacrosCreate

func (api *API) MacrosCreate(macros Macros) error

MacrosCreate Wrapper for usermacro.create https://www.zabbix.com/documentation/3.2/manual/api/reference/usermacro/create

func (*API) MacrosDelete

func (api *API) MacrosDelete(macros Macros) (err error)

MacrosDelete Wrapper for usermacro.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/usermacro/delete

func (*API) MacrosDeleteByIDs

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

MacrosDeleteByIDs Wrapper for usermacro.delete Cleans MacroId in all macro elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/usermacro/delete

func (*API) MacrosGet

func (api *API) MacrosGet(params Params) (res Macros, err error)

MacrosGet Wrapper for usermacro.get https://www.zabbix.com/documentation/3.2/manual/api/reference/usermacro/get

func (*API) MacrosUpdate

func (api *API) MacrosUpdate(macros Macros) (err error)

MacrosUpdate Wrapper for usermacro.update https://www.zabbix.com/documentation/3.2/manual/api/reference/usermacro/update

func (*API) SetClient

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

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

func (*API) TemplateGetByID

func (api *API) TemplateGetByID(id string) (template *Template, err error)

TemplateGetByID Gets template by Id only if there is exactly 1 matching template.

func (*API) TemplatesCreate

func (api *API) TemplatesCreate(templates Templates) (err error)

TemplatesCreate Wrapper for template.create https://www.zabbix.com/documentation/3.2/manual/api/reference/template/create

func (*API) TemplatesDelete

func (api *API) TemplatesDelete(templates Templates) (err error)

TemplatesDelete Wrapper for template.delete Cleans ApplicationID in all apps elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/template/delete

func (*API) TemplatesDeleteByIds

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

TemplatesDeleteByIds Wrapper for template.delete Use template's id to delete the template https://www.zabbix.com/documentation/3.2/manual/api/reference/template/delete

func (*API) TemplatesGet

func (api *API) TemplatesGet(params Params) (res Templates, err error)

TemplatesGet Wrapper for template.get https://www.zabbix.com/documentation/3.2/manual/api/reference/template/get

func (*API) TemplatesUpdate

func (api *API) TemplatesUpdate(templates Templates) (err error)

TemplatesUpdate Wrapper for template.update https://www.zabbix.com/documentation/3.2/manual/api/reference/template/update

func (*API) TriggerGetByID

func (api *API) TriggerGetByID(id string) (res *Trigger, err error)

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

func (*API) TriggerPrototypeGetByID

func (api *API) TriggerPrototypeGetByID(id string) (res *TriggerPrototype, err error)

TriggerPrototypeGetByID Gets trigger by Id only if there is exactly 1 matching trigger.

func (*API) TriggerPrototypesCreate

func (api *API) TriggerPrototypesCreate(triggers TriggerPrototypes) (err error)

TriggerPrototypesCreate Wrapper for trigger.create https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/create

func (*API) TriggerPrototypesDelete

func (api *API) TriggerPrototypesDelete(triggers TriggerPrototypes) (err error)

TriggerPrototypesDelete Wrapper for trigger.delete Cleans TriggerID in all triggers elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/delete

func (*API) TriggerPrototypesDeleteByIds

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

TriggerPrototypesDeleteByIds Wrapper for trigger.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/delete

func (*API) TriggerPrototypesDeleteIDs

func (api *API) TriggerPrototypesDeleteIDs(ids []string) (triggerids []interface{}, err error)

TriggerPrototypesDeleteIDs Wrapper for trigger.delete return the id of the deleted trigger prototype https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/delete

func (*API) TriggerPrototypesGet

func (api *API) TriggerPrototypesGet(params Params) (res TriggerPrototypes, err error)

TriggerPrototypesGet Wrapper for trigger.get https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/get

func (*API) TriggerPrototypesUpdate

func (api *API) TriggerPrototypesUpdate(triggers TriggerPrototypes) (err error)

TriggerPrototypesUpdate Wrapper for trigger.update https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/update

func (*API) TriggersCreate

func (api *API) TriggersCreate(triggers Triggers) (err error)

TriggersCreate Wrapper for trigger.create https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/create

func (*API) TriggersDelete

func (api *API) TriggersDelete(triggers Triggers) (err error)

TriggersDelete Wrapper for trigger.delete Cleans ItemId in all triggers elements if call succeed. https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/delete

func (*API) TriggersDeleteByIds

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

TriggersDeleteByIds Wrapper for trigger.delete https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/delete

func (*API) TriggersDeleteIDs

func (api *API) TriggersDeleteIDs(ids []string) (triggerids []interface{}, err error)

TriggersDeleteIDs Wrapper for trigger.delete return the id of the deleted trigger

func (*API) TriggersGet

func (api *API) TriggersGet(params Params) (res Triggers, err error)

TriggersGet Wrapper for trigger.get https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/get

func (*API) TriggersUpdate

func (api *API) TriggersUpdate(triggers Triggers) (err error)

TriggersUpdate Wrapper for trigger.update https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/update

func (*API) Version

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

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

type Application

type Application struct {
	ApplicationID string `json:"applicationid,omitempty"`
	HostID        string `json:"hostid"`
	Name          string `json:"name"`
	TemplateID    string `json:"templateid,omitempty"`
}

Application represent Zabbix application object https://www.zabbix.com/documentation/3.2/manual/api/reference/application/object

type Applications

type Applications []Application

Applications is an array of Application

type AvailableType

type AvailableType int

AvailableType (readonly) Availability of Zabbix agent see "available" in: https://www.zabbix.com/documentation/3.2/manual/api/reference/host/object

const (
	// Unknown (default)
	Unknown AvailableType = 0
	// Available host is available
	Available AvailableType = 1
	// Unavailable host is unavailable
	Unavailable AvailableType = 2
)

type DataType

type DataType int

DataType data type of the item

const (

	// Decimal data (default)
	Decimal DataType = 0
	// Octal data
	Octal DataType = 1
	// Hexadecimal data
	Hexadecimal DataType = 2
	// Boolean data
	Boolean DataType = 3
)

type DeltaType

type DeltaType int

DeltaType value that will be stored

const (

	// AsIs as is (default)
	AsIs DeltaType = 0
	// Speed speed per second
	Speed DeltaType = 1
	// Delta simple change
	Delta DeltaType = 2
)

type Error

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

Error contains error data and code

func (*Error) Error

func (e *Error) Error() string

type ExpectedMore

type ExpectedMore struct {
	Expected int
	Got      int
}

ExpectedMore use to generate error when you expect more element

func (*ExpectedMore) Error

func (e *ExpectedMore) Error() string

type ExpectedOneResult

type ExpectedOneResult int

ExpectedOneResult use to generate error when you expect one result

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,string"`
	Error     string        `json:"error"`
	Name      string        `json:"name"`
	Status    StatusType    `json:"status,string"`

	// Fields below used only when creating hosts
	GroupIds    HostGroupIDs   `json:"groups,omitempty"`
	Interfaces  HostInterfaces `json:"interfaces,omitempty"`
	TemplateIDs TemplateIDs    `json:"templates,omitempty"`
}

Host represent Zabbix host object https://www.zabbix.com/documentation/3.2/manual/api/reference/host/object

type HostGroup

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

HostGroup represent Zabbix host group object https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/object

type HostGroupID

type HostGroupID struct {
	GroupID string `json:"groupid"`
}

HostGroupID represent Zabbix GroupID

type HostGroupIDs

type HostGroupIDs []HostGroupID

HostGroupIDs is an array of HostGroupId

type HostGroups

type HostGroups []HostGroup

HostGroups is an array of 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"`
}

HostInterface represents zabbix host interface type https://www.zabbix.com/documentation/3.2/manual/api/reference/hostinterface/object

type HostInterfaces

type HostInterfaces []HostInterface

HostInterfaces is an array of HostInterface

type Hosts

type Hosts []Host

Hosts is an array of Host

type InterfaceType

type InterfaceType int

InterfaceType different interface type

const (

	// Agent type
	Agent InterfaceType = 1
	// SNMP type
	SNMP InterfaceType = 2
	// IPMI type
	IPMI InterfaceType = 3
	// JMX type
	JMX InterfaceType = 4
)

type InternalType

type InternalType int

InternalType (readonly) Whether the group is used internally by the system. An internal group cannot be deleted. see "internal" in https://www.zabbix.com/documentation/3.2/manual/api/reference/hostgroup/object

const (
	// NotInternal (default) not internal
	NotInternal InternalType = 0
	// Internal internal
	Internal InternalType = 1
)

type Item

type Item struct {
	ItemID       string    `json:"itemid,omitempty"`
	Delay        string    `json:"delay"`
	HostID       string    `json:"hostid"`
	InterfaceID  string    `json:"interfaceid,omitempty"`
	Key          string    `json:"key_"`
	Name         string    `json:"name"`
	Type         ItemType  `json:"type,string"`
	ValueType    ValueType `json:"value_type,string"`
	DataType     DataType  `json:"data_type,string"`
	Delta        DeltaType `json:"delta,string"`
	Description  string    `json:"description"`
	Error        string    `json:"error,omitempty"`
	History      string    `json:"history,omitempty"`
	Trends       string    `json:"trends,omitempty"`
	TrapperHosts string    `json:"trapper_hosts,omitempty"`

	// Fields below used only when creating applications
	ApplicationIds []string `json:"applications,omitempty"`

	ItemParent Hosts `json:"hosts"`
}

Item represent Zabbix item object https://www.zabbix.com/documentation/3.2/manual/api/reference/item/object

type ItemPrototype

type ItemPrototype struct {
	ItemID               string    `json:"itemid,omitempty"`  // Readonly
	Delay                string    `json:"delay"`             // Required
	HostID               string    `json:"hostid"`            // Required
	InterfaceID          string    `json:"interfaceid"`       // Required
	Key                  string    `json:"key_"`              // Required
	Name                 string    `json:"name"`              // Required
	Type                 ItemType  `json:"type,string"`       // Required
	ValueType            ValueType `json:"value_type,string"` // Required
	RuleID               string    `json:"ruleid"`            // Required for item prototype creation
	AuthType             int       `json:"authtype,omitempty,string"`
	DataType             DataType  `json:"data_type,omitempty,string"`
	DelayFlex            string    `json:"delay_flex,omitempty"`
	Delta                DeltaType `json:"delta,omitempty,string"`
	Description          string    `json:"description,omitempty"`
	History              string    `json:"history,omitempty"`
	IpmiSensor           string    `json:"ipmi_sensor,omitempty"`
	Logtimefmt           string    `json:"logtimefmt,omitempty"`
	Multiplier           string    `json:"multiplier,omitempty"`
	Params               string    `json:"params,omitempty"`
	Password             string    `json:"password,omitempty"`
	Port                 string    `json:"port,omitempty"`
	PrivateKey           string    `json:"privatekey,omitempty"`
	PublicKey            string    `json:"publickey,omitempty"`
	SnmpCommunity        string    `json:"snmp_community,omitempty"`
	SnmpOid              string    `json:"snmp_oid,omitempty"`
	Snmpv3Authpassphrase string    `json:"snmpv3_authpassphrase,omitempty"`
	Snmpv3Authprotocol   int       `json:"snmpv3_authprotocol,omitempty,string"`
	Snmpv3Contextname    string    `json:"snmpv3_contextname,omitempty"`
	Snmpv3Privpassphrase string    `json:"snmpv3_privpassphrase,omitempty"`
	Snmpv3Privprotocol   int       `json:"snmpv3_privprotocol,omitempty,string"`
	Snmpv3Securitylevel  int       `json:"snmpv3_securitylevel,omitempty,string"`
	Snmpv3Securityname   string    `json:"snmpv3_securityname,omitempty"`
	Status               int       `json:"status,string"`
	Templateid           string    `json:"templateid,omitempty"`
	TrapperHosts         string    `json:"trapper_hosts,omitempty"`
	Trends               string    `json:"trends,omitempty"`
	Units                string    `json:"units,omitempty"`
	Username             string    `json:"username,omitempty"`
	Valuemapid           string    `json:"valuemapid,omitempty"`

	DiscoveryRule LLDRule `json:"DiscoveryRule,omitempty"`
	Hosts         Hosts   `json:"hosts,omitempty"`
}

ItemPrototype represent Zabbix item prototype object https://www.zabbix.com/documentation/3.2/manual/api/reference/itemprototype/object

type ItemPrototypes

type ItemPrototypes []ItemPrototype

ItemPrototypes is an array of ItemPrototype

type ItemType

type ItemType int

ItemType type of the item

const (

	// ZabbixAgent type
	ZabbixAgent ItemType = 0
	// SNMPv1Agent type
	SNMPv1Agent ItemType = 1
	// ZabbixTrapper type
	ZabbixTrapper ItemType = 2
	// SimpleCheck type
	SimpleCheck ItemType = 3
	// SNMPv2Agent type
	SNMPv2Agent ItemType = 4
	// ZabbixInternal type
	ZabbixInternal ItemType = 5
	// SNMPv3Agent type
	SNMPv3Agent ItemType = 6
	// ZabbixAgentActive type
	ZabbixAgentActive ItemType = 7
	// ZabbixAggregate type
	ZabbixAggregate ItemType = 8
	// WebItem type
	WebItem ItemType = 9
	// ExternalCheck type
	ExternalCheck ItemType = 10
	// DatabaseMonitor type
	DatabaseMonitor ItemType = 11
	//IPMIAgent type
	IPMIAgent ItemType = 12
	// SSHAgent type
	SSHAgent ItemType = 13
	// TELNETAgent type
	TELNETAgent ItemType = 14
	// Calculated type
	Calculated ItemType = 15
	// JMXAgent type
	JMXAgent ItemType = 16
)

type Items

type Items []Item

Items is an array of Item

func (Items) ByKey

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

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

type LLDRule

type LLDRule struct {
	ItemID               string        `json:"itemid,omitempty"` // Readonly
	Delay                string        `json:"delay"`            // Required
	HostID               string        `json:"hostid"`           // Required
	InterfaceID          string        `json:"interfaceid"`      // Required
	Key                  string        `json:"key_"`             // Required
	Name                 string        `json:"name"`             // Required
	Type                 ItemType      `json:"type,string"`      // Required
	AuthType             string        `json:"authtype,omitempty"`
	DelayFlex            string        `json:"delay_flex,omitempty"`
	Description          string        `json:"description,omitempty"`
	Error                string        `json:"error,omitempty"` //Readonly
	IpmiSensor           string        `json:"ipmi_sensor,omitempty"`
	LifeTime             string        `json:"lifetime,omitempty"`
	Params               string        `json:"params,omitempty"`
	Password             string        `json:"password,omitempty"`
	Port                 string        `json:"port,omitempty"`
	PrivateKey           string        `json:"privatekey,omitempty"`
	PublicKey            string        `json:"publickey,omitempty"`
	SnmpCommunity        string        `json:"snmp_community,omitempty"`
	SnmpOid              string        `json:"snmp_oid,omitempty"`
	Snmpv3Authpassphrase string        `json:"snmpv3_authpassphrase,omitempty"`
	Snmpv3Authprotocol   int           `json:"snmpv3_authprotocol,omitempty,string"`
	Snmpv3Contextname    string        `json:"snmpv3_contextname,omitempty"`
	Snmpv3Privpassphrase string        `json:"snmpv3_privpassphrase,omitempty"`
	Snmpv3Privprotocol   int           `json:"snmpv3_privprotocol,omitempty,string"`
	Snmpv3Securitylevel  int           `json:"snmpv3_securitylevel,omitempty,string"`
	Snmpv3Securityname   string        `json:"snmpv3_securityname,omitempty"`
	State                int           `json:"state,omitempty,string"`
	Status               int           `json:"status,omitempty,string"`
	Templateid           string        `json:"templateid,omitempty"`
	TrapperHosts         string        `json:"trapper_hosts,omitempty"`
	Username             string        `json:"username,omitempty"`
	Filter               LLDRuleFilter `json:"filter"`
}

LLDRule represent Zabbix low-level discovery rule(LLD rule) object https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/object#lld_rule

type LLDRuleFilter

type LLDRuleFilter struct {
	Conditions  LLDRulesFilterConditions `json:"conditions"`      // Required
	EvalType    int                      `json:"evaltype,string"` // Required
	EvalFormula string                   `json:"eval_formula,omitempty"`
	Formula     string                   `json:"formula,omitempty"`
}

LLDRuleFilter represent zabbix low-level discovery rules filter(LLD rule filter) object https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/object#lld_rule_filter

type LLDRules

type LLDRules []LLDRule

LLDRules is an array of LLDRule

type LLDRulesFilterCondition

type LLDRulesFilterCondition struct {
	LLDMacro  string `json:"macro"` // Required
	Value     string `json:"value"` // Required
	FormulaID string `json:"formulaid,omitempty"`
	Operator  int    `json:"operator,omitempty,string"`
}

LLDRulesFilterCondition represent zabbix low-level discovery rules filter condition(LLD rule file condition) object https://www.zabbix.com/documentation/3.2/manual/api/reference/discoveryrule/object#lld_rule_filter_condition

type LLDRulesFilterConditions

type LLDRulesFilterConditions []LLDRulesFilterCondition

LLDRulesFilterConditions is an array of LLDRulesFilterCondition

type Macro

type Macro struct {
	MacroID   string `json:"hostmacroids,omitempty"`
	HostID    string `json:"hostid"`
	MacroName string `json:"macro"`
	Value     string `json:"value"`
}

Macro represent Zabbix User MAcro object https://www.zabbix.com/documentation/3.2/manual/api/reference/usermacro/object

type Macros

type Macros []Macro

Macros is an array of Macro

type Params

type Params map[string]interface{}

Params Zabbix request param

type RawResponse

type RawResponse struct {
	Jsonrpc string          `json:"jsonrpc"`
	Error   *Error          `json:"error"`
	Result  json.RawMessage `json:"result"`
	ID      int32           `json:"id"`
}

RawResponse format of zabbix api

type Response

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

Response format of zabbix api

type SeverityType

type SeverityType int

SeverityType of a trigger Zabbix severity see : https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/object

const (

	// NotClassified is Not classified severity
	NotClassified SeverityType = 0
	// Information is Information severity
	Information SeverityType = 1
	// Warning is Warning severity
	Warning SeverityType = 2
	// Average is Average severity
	Average SeverityType = 3
	// High is high severity
	High SeverityType = 4
	// Critical is critical severity
	Critical SeverityType = 5
)

type StatusType

type StatusType int

StatusType Status and function of the host. see "status" in: https://www.zabbix.com/documentation/3.2/manual/api/reference/host/object

const (
	// Monitored monitored host(default)
	Monitored StatusType = 0
	// Unmonitored unmonitored host
	Unmonitored StatusType = 1
)
const (
	// Enabled trigger status enabled
	Enabled StatusType = 0
	// Disabled trigger status disabled
	Disabled StatusType = 1
)

type Template

type Template struct {
	TemplateID      string     `json:"templateid,omitempty"`
	Host            string     `json:"host"`
	Description     string     `json:"description,omitempty"`
	Name            string     `json:"name,omitempty"`
	Groups          HostGroups `json:"groups"`
	UserMacros      Macros     `json:"macros"`
	LinkedTemplates Templates  `json:"templates,omitempty"`
	TemplatesClear  Templates  `json:"templates_clear,omitempty"`
	LinkedHosts     Hosts      `json:"hosts,omitempty"`
}

Template represent Zabbix Template type returned from Zabbix API https://www.zabbix.com/documentation/3.2/manual/api/reference/template/object

type TemplateID

type TemplateID struct {
	TemplateID string `json:"templateid"`
}

TemplateID use with host creation

type TemplateIDs

type TemplateIDs []TemplateID

TemplateIDs is an Array of TemplateID structs.

type Templates

type Templates []Template

Templates is an Array of Template structs.

type Trigger

type Trigger struct {
	TriggerID   string `json:"triggerid,omitempty"`
	Description string `json:"description"`
	Expression  string `json:"expression"`
	Comments    string `json:"comments"`

	Priority     SeverityType     `json:"priority,string"`
	Status       StatusType       `json:"status,string"`
	Dependencies Triggers         `json:"dependencies,omitempty"`
	Functions    TriggerFunctions `json:"functions,omitempty"`
	// Items contained by the trigger in the items property.
	ContainedItems Items `json:"items,omitempty"`
	// Hosts that the trigger belongs to in the hosts property.
	ParentHosts Hosts `json:"hosts,omitempty"`
}

Trigger represent Zabbix trigger object https://www.zabbix.com/documentation/3.2/manual/api/reference/trigger/object

type TriggerFunction

type TriggerFunction struct {
	FunctionID string `json:"functionid"`
	ItemID     string `json:"itemid"`
	Function   string `json:"function"`
	Parameter  string `json:"parameter"`
}

TriggerFunction The function objects represents the functions used in the trigger expression

type TriggerFunctions

type TriggerFunctions []TriggerFunction

TriggerFunctions is an array of TriggerFunction

type TriggerPrototype

type TriggerPrototype struct {
	TriggerID          string            `json:"triggerid,omitempty"` // Readonly
	Description        string            `json:"description"`         // Reqired
	Expression         string            `json:"expression"`          // Required
	Commemts           string            `json:"comments,omitempty"`
	Priority           SeverityType      `json:"priority,omitempty,string"`
	Status             StatusType        `json:"status,omitempty,string"`
	TemplateID         string            `json:"templateid,omitempty"` // Readonly
	Type               int               `json:"type,omitempty,string"`
	URL                string            `json:"url,omitempty"`
	RecoveryMode       int               `json:"recovery_mode,omitempty,string"`
	RecoveryExpression string            `json:"recovery_expression,omitempty"`
	CorrelationMode    int               `json:"correlation_mode,omitempty,string"`
	CorrelationTag     string            `json:"correlation_tag,omitempty"`
	ManualClose        int               `json:"manual_close,omitempty,string"`
	Dependencies       TriggerPrototypes `json:"dependencies,omitempty"`

	Functions TriggerFunctions `json:"functions,omitempty"`
	// Return the hosts that the trigger prototype belongs to in the hosts property.
	ParentHosts Hosts `json:"hosts,omitempty"`
}

TriggerPrototype represent Zabbix trigger prototype object https://www.zabbix.com/documentation/3.2/manual/api/reference/triggerprototype/object

type TriggerPrototypes

type TriggerPrototypes []TriggerPrototype

TriggerPrototypes is an array of TriggerPrototype

type Triggers

type Triggers []Trigger

Triggers is an array of Trigger

type ValueType

type ValueType int

ValueType type of information of the item

const (

	// Float value
	Float ValueType = 0
	// Character value
	Character ValueType = 1
	// Log value
	Log ValueType = 2
	// Unsigned value
	Unsigned ValueType = 3
	// Text value
	Text ValueType = 4
)
const (

	// OK trigger value ok
	OK ValueType = 0
	// Problem trigger value probleme
	Problem ValueType = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL