zabbix

package module
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: BSD-2-Clause Imports: 11 Imported by: 0

README

Go zabbix api

Note, this is not tested and is adjusted for use of tpretz/terraform-provider-zabbix

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/tpretz/go-zabbix-api

Getting started

package main

import (
	"fmt"

	"github.com/tpretz/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/Darren0829/go-zabbix-api`

Getting started

package main

import (
	"fmt"

	"github.com/Darren0829/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

View Source
const (
	GraphNormal   GraphType = "0"
	GraphStacked  GraphType = "1"
	GraphPie      GraphType = "2"
	GraphExploded GraphType = "3"

	GraphAxisCalculated GraphAxis = "0"
	GraphAxisFixed      GraphAxis = "1"
	GraphAxisItem       GraphAxis = "2"

	GraphItemMin  GraphItemFunc = "1"
	GraphItemAvg  GraphItemFunc = "2"
	GraphItemMax  GraphItemFunc = "4"
	GraphItemAll  GraphItemFunc = "7"
	GraphItemLast GraphItemFunc = "9"

	GraphItemLine     GraphItemDraw = "0"
	GraphItemFilled   GraphItemDraw = "1"
	GraphItemBold     GraphItemDraw = "2"
	GraphItemDot      GraphItemDraw = "3"
	GraphItemDashed   GraphItemDraw = "4"
	GraphItemGradient GraphItemDraw = "5"

	GraphItemSimple GraphItemType = "0"
	GraphItemSum    GraphItemType = "2"

	GraphItemLeft  GraphItemSide = "0"
	GraphItemRight GraphItemSide = "1"
)
View Source
const (
	LLDAndOr    LLDEvalType     = "0"
	LLDAnd      LLDEvalType     = "1"
	LLDOr       LLDEvalType     = "2"
	LLDCustom   LLDEvalType     = "3"
	LLDMatch    LLDOperatorType = "8"
	LLDNotMatch LLDOperatorType = "9"
)

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

	Config Config
	// contains filtered or unexported fields
}

API use to store connection information

func NewAPI

func NewAPI(c Config) (api *API, err error)

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 added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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) GraphGetByID added in v0.16.1

func (api *API) GraphGetByID(id string) (res *Graph, err error)

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

func (*API) GraphProtoGetByID added in v0.16.1

func (api *API) GraphProtoGetByID(id string) (res *Graph, err error)

func (*API) GraphProtosCreate added in v0.16.1

func (api *API) GraphProtosCreate(hostGroups Graphs) (err error)

func (*API) GraphProtosDelete added in v0.16.1

func (api *API) GraphProtosDelete(hostGroups Graphs) (err error)

func (*API) GraphProtosDeleteByIds added in v0.16.1

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

func (*API) GraphProtosGet added in v0.16.1

func (api *API) GraphProtosGet(params Params) (res Graphs, err error)

func (*API) GraphProtosUpdate added in v0.16.1

func (api *API) GraphProtosUpdate(hostGroups Graphs) (err error)

func (*API) GraphsCreate added in v0.16.1

func (api *API) GraphsCreate(hostGroups Graphs) (err error)

GraphsCreate Wrapper for graph.create https://www.zabbix.com/documentation/3.2/manual/api/reference/graph/create

func (*API) GraphsDelete added in v0.16.1

func (api *API) GraphsDelete(hostGroups Graphs) (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) GraphsDeleteByIds added in v0.16.1

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

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

func (*API) GraphsGet added in v0.16.1

func (api *API) GraphsGet(params Params) (res Graphs, err error)

GraphsGet Wrapper for graph.get https://www.zabbix.com/documentation/3.2/manual/api/reference/graph/get

func (*API) GraphsUpdate added in v0.16.1

func (api *API) GraphsUpdate(hostGroups Graphs) (err error)

GraphsUpdate Wrapper for graph.update https://www.zabbix.com/documentation/3.2/manual/api/reference/graph/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 added in v0.16.1

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 added in v0.16.1

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 added in v0.3.0

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 added in v0.3.0

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 added in v0.16.1

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) 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 added in v0.16.1

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 added in v0.16.1

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

ItemsGetByApplicationID Gets items by application Id.

func (*API) ItemsUpdate added in v0.16.1

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) LLDDeleteByIds added in v0.16.1

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

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

func (*API) LLDDeleteIDs added in v0.16.1

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

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

func (*API) LLDGetByID added in v0.16.1

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

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

func (*API) LLDsCreate added in v0.16.1

func (api *API) LLDsCreate(items LLDRules) (err error)

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

func (*API) LLDsDelete added in v0.16.1

func (api *API) LLDsDelete(items LLDRules) (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) LLDsGet added in v0.16.1

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

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

func (*API) LLDsUpdate added in v0.16.1

func (api *API) LLDsUpdate(items LLDRules) (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 added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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) ProtoItemGetByID added in v0.16.1

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

func (*API) ProtoItemsCreate added in v0.16.1

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

func (*API) ProtoItemsDelete added in v0.16.1

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

func (*API) ProtoItemsDeleteByIds added in v0.16.1

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

func (*API) ProtoItemsDeleteIDs added in v0.16.1

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

func (*API) ProtoItemsGet added in v0.16.1

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

func (*API) ProtoItemsGetByApplicationID added in v0.16.1

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

func (*API) ProtoItemsUpdate added in v0.16.1

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

func (*API) ProtoTriggerGetByID added in v0.16.1

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

func (*API) ProtoTriggersCreate added in v0.16.1

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

func (*API) ProtoTriggersDelete added in v0.16.1

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

func (*API) ProtoTriggersDeleteByIds added in v0.16.1

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

func (*API) ProtoTriggersDeleteIDs added in v0.16.1

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

func (*API) ProtoTriggersGet added in v0.16.1

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

func (*API) ProtoTriggersUpdate added in v0.16.1

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

func (*API) ProxiesGet added in v0.16.1

func (api *API) ProxiesGet(params Params) (res Proxies, err error)

ProxiesGet Wrapper for proxy.get https://www.zabbix.com/documentation/3.2/manual/api/reference/proxy/get

func (*API) SetClient added in v0.2.0

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

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

func (*API) TemplateGetByID added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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 added in v0.16.1

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 added in v0.3.0

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 added in v0.16.1

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 added in v0.16.1

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) TriggersCreate added in v0.3.1

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 added in v0.3.1

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 added in v0.3.1

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 added in v0.16.1

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 added in v0.3.1

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 added in v0.16.1

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 Config added in v0.16.1

type Config struct {
	Url         string
	TlsNoVerify bool
	Log         *log.Logger
	Serialize   bool
	Version     int
}

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 Graph added in v0.16.1

type Graph struct {
	GraphID        string    `json:"graphid,omitempty"`
	Name           string    `json:"name"`
	Height         string    `json:"height"`
	Width          string    `json:"width"`
	Type           GraphType `json:"graphtype,omitempty"`
	PercentLeft    string    `json:"percent_left,omitempty"`
	PercentRight   string    `json:"percent_right,omitempty"`
	Show3d         string    `json:"show_3d,omitempty"`
	ShowLegend     string    `json:"show_legend,omitempty"`
	ShowWorkPeriod string    `json:"show_work_period,omitempty"`
	YMax           string    `json:"yaxismax,omitempty"`
	YMaxItemId     string    `json:"ymax_itemid,omitempty"`
	YMaxType       GraphAxis `json:"ymax_type,omitempty"`
	YMin           string    `json:"yaxismin,omitempty"`
	YMinItemId     string    `json:"ymin_itemid,omitempty"`
	YMinType       GraphAxis `json:"ymin_type,omitempty"`

	GraphItems GraphItems `json:"gitems,omitempty"`
}

Graph represent Zabbix Graph object https://www.zabbix.com/documentation/3.2/manual/api/reference/graph/object

type GraphAxis added in v0.16.1

type GraphAxis string

type GraphItem added in v0.16.1

type GraphItem struct {
	GItemID   string        `json:"gitemid,omitempty"`
	GraphID   string        `json:"graphid,omitempty"`
	Color     string        `json:"color"`
	ItemID    string        `json:"itemid"`
	CalcFunc  GraphItemFunc `json:"calc_fnc,omitempty"`
	DrawType  GraphItemDraw `json:"drawtype,omitempty"`
	SortOrder string        `json:"sortorder,omitempty"`
	Type      GraphItemType `json:"type,omitempty"`
	YAxisSide GraphItemSide `json:"yaxisside,omitempty"`
}

type GraphItemDraw added in v0.16.1

type GraphItemDraw string

type GraphItemFunc added in v0.16.1

type GraphItemFunc string

type GraphItemSide added in v0.16.1

type GraphItemSide string

type GraphItemType added in v0.16.1

type GraphItemType string

type GraphItems added in v0.16.1

type GraphItems []GraphItem

type GraphType added in v0.16.1

type GraphType string

type Graphs added in v0.16.1

type Graphs []Graph

HostGroups is an array of HostGroup

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"`
	UserMacros Macros        `json:"macros,omitempty"`

	RawInventory json.RawMessage `json:"inventory,omitempty"`
	Inventory    Inventory       `json:"-"`

	RawInventoryMode *InventoryMode `json:"inventory_mode,string,omitempty"`
	InventoryMode    InventoryMode  `json:"-"`

	// Fields below used only when creating hosts
	GroupIds         HostGroupIDs   `json:"groups,omitempty"`
	Interfaces       HostInterfaces `json:"interfaces,omitempty"`
	TemplateIDs      TemplateIDs    `json:"templates,omitempty"`
	TemplateIDsClear TemplateIDs    `json:"templates_clear,omitempty"`
	// templates are read back from this one
	ParentTemplateIDs TemplateIDs `json:"parentTemplates,omitempty"`
	ProxyID           string      `json:"proxy_hostid,omitempty"`
	Tags              Tags        `json:"tags,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 added in v0.16.1

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

HostGroupID represent Zabbix GroupID

type HostGroupIDs added in v0.16.1

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 {
	InterfaceID string               `json:"interfaceid,omitempty"`
	DNS         string               `json:"dns"`
	IP          string               `json:"ip"`
	Main        string               `json:"main"`
	Port        string               `json:"port"`
	Type        InterfaceType        `json:"type"`
	UseIP       string               `json:"useip"`
	RawDetails  json.RawMessage      `json:"details,omitempty"`
	Details     *HostInterfaceDetail `json:"-"`
}

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

type HostInterfaceDetail added in v0.16.1

type HostInterfaceDetail struct {
	Version        string `json:"version,omitempty"`
	Bulk           string `json:"bulk,omitempty"`
	Community      string `json:"community,omitempty"`
	SecurityName   string `json:"securityname,omitempty"`
	SecurityLevel  string `json:"securitylevel,omitempty"`
	AuthPassphrase string `json:"authpassphrase,omitempty"`
	PrivPassphrase string `json:"privpassphrase,omitempty"`
	AuthProtocol   string `json:"authprotocol,omitempty"`
	PrivProtocol   string `json:"privprotocol,omitempty"`
	ContextName    string `json:"contextname,omitempty"`
}

type HostInterfaceDetails added in v0.16.1

type HostInterfaceDetails []HostInterfaceDetail

type HostInterfaces

type HostInterfaces []HostInterface

HostInterfaces is an array of HostInterface

type Hosts

type Hosts []Host

Hosts is an array of Host

type HttpHeaders added in v0.16.1

type HttpHeaders map[string]string

type InterfaceType

type InterfaceType string

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 InventoryMode added in v0.16.1

type InventoryMode int
const (
	InventoryDisabled  InventoryMode = -1
	InventoryManual    InventoryMode = 0
	InventoryAutomatic InventoryMode = 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"`
	Params       string    `json:"params,omitempty"`

	// list of strings on set, but list of objects on get
	RawApplications json.RawMessage `json:"applications,omitempty"`
	Applications    []string        `json:"-"`

	ItemParent Hosts `json:"hosts"`

	Preprocessors Preprocessors `json:"preprocessing,omitempty"`

	// HTTP Agent Fields
	Url             string          `json:"url,omitempty"`
	RequestMethod   string          `json:"request_method,omitempty"`
	PostType        string          `json:"post_type,omitempty"`
	RetrieveMode    string          `json:"retrieve_mode,omitempty"`
	Posts           string          `json:"posts,omitempty"`
	StatusCodes     string          `json:"status_codes,omitempty"`
	Timeout         string          `json:"timeout,omitempty"`
	VerifyHost      string          `json:"verify_host,omitempty"`
	VerifyPeer      string          `json:"verify_peer,omitempty"`
	AuthType        string          `json:"authtype,omitempty"`
	Username        string          `json:"username,omitempty"`
	Password        string          `json:"password,omitempty"`
	Headers         HttpHeaders     `json:"-"`
	RawHeaders      json.RawMessage `json:"headers,omitempty"`
	Proxy           string          `json:"http_proxy,omitempty"`
	FollowRedirects string          `json:"follow_redirects,omitempty"`

	// SNMP Fields
	SNMPOid              string `json:"snmp_oid,omitempty"`
	SNMPCommunity        string `json:"snmp_community,omitempty"`
	SNMPv3AuthPassphrase string `json:"snmpv3_authpassphrase,omitempty"`
	SNMPv3AuthProtocol   string `json:"snmpv3_authprotocol,omitempty"`
	SNMPv3ContextName    string `json:"snmpv3_contextname,omitempty"`
	SNMPv3PrivPasshrase  string `json:"snmpv3_privpassphrase,omitempty"`
	SNMPv3PrivProtocol   string `json:"snmpv3_privprotocol,omitempty"`
	SNMPv3SecurityLevel  string `json:"snmpv3_securitylevel,omitempty"`
	SNMPv3SecurityName   string `json:"snmpv3_securityname,omitempty"`

	// Dependent Fields
	MasterItemID string `json:"master_itemid,omitempty"`

	// Prototype
	RuleID        string   `json:"ruleid,omitempty"`
	DiscoveryRule *LLDRule `json:"discoveryRule,omitEmpty"`

	Tags Tags `json:"tags,omitempty"`
}

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

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
	SNMPTrap  ItemType = 17
	Dependent ItemType = 18
	HTTPAgent ItemType = 19
	SNMPAgent ItemType = 20
)

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 LLDEvalType added in v0.16.1

type LLDEvalType string

type LLDMacroPath added in v0.16.1

type LLDMacroPath struct {
	Macro string `json:"lld_macro"`
	Path  string `json:"path"`
}

type LLDMacroPaths added in v0.16.1

type LLDMacroPaths []LLDMacroPath

type LLDOperatorType added in v0.16.1

type LLDOperatorType string

type LLDRule added in v0.16.1

type LLDRule 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"`
	AuthType     string `json:"authtype,omitempty"`
	DelayFlex    string `json:"delay_flex,omitempty"`
	Description  string `json:"description"`
	Error        string `json:"error,omitempty"`
	IpmiSensor   string `json:"ipmi_sensor,omitempty"`
	LifeTime     string `json:"lifetime,omitempty"`
	Params       string `json:"params,omitempty"`
	PrivateKey   string `json:"privatekey,omitempty"`
	PublicKey    string `json:"publickey,omitempty"`
	Status       string `json:"status,omitempty"`
	TrapperHosts string `json:"trapper_hosts,omitempty"`
	MasterItemID string `json:"master_itemid,omitempty"`

	// ssh / telnet
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Port     string `json:"port,omitempty"`

	// HTTP Agent Fields
	Url             string          `json:"url,omitempty"`
	RequestMethod   string          `json:"request_method,omitempty"`
	AllowTraps      string          `json:"allow_traps,omitempty"`
	PostType        string          `json:"post_type,omitempty"`
	RetrieveMode    string          `json:"retrieve_mode,omitempty"`
	Posts           string          `json:"posts,omitempty"`
	StatusCodes     string          `json:"status_codes,omitempty"`
	Timeout         string          `json:"timeout,omitempty"`
	VerifyHost      string          `json:"verify_host,omitempty"`
	VerifyPeer      string          `json:"verify_peer,omitempty"`
	Headers         HttpHeaders     `json:"-"`
	RawHeaders      json.RawMessage `json:"headers,omitempty"`
	Proxy           string          `json:"http_proxy,omitempty"`
	FollowRedirects string          `json:"follow_redirects,omitempty"`

	// SNMP Fields
	SNMPOid              string `json:"snmp_oid,omitempty"`
	SNMPCommunity        string `json:"snmp_community,omitempty"`
	SNMPv3AuthPassphrase string `json:"snmpv3_authpassphrase,omitempty"`
	SNMPv3AuthProtocol   string `json:"snmpv3_authprotocol,omitempty"`
	SNMPv3ContextName    string `json:"snmpv3_contextname,omitempty"`
	SNMPv3PrivPasshrase  string `json:"snmpv3_privpassphrase,omitempty"`
	SNMPv3PrivProtocol   string `json:"snmpv3_privprotocol,omitempty"`
	SNMPv3SecurityLevel  string `json:"snmpv3_securitylevel,omitempty"`
	SNMPv3SecurityName   string `json:"snmpv3_securityname,omitempty"`

	Preprocessors Preprocessors `json:"preprocessing,omitempty"`
	Filter        LLDRuleFilter `json:"filter"`
	MacroPaths    LLDMacroPaths `json:"lld_macro_paths,omitempty"`
}

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

type LLDRuleFilter added in v0.16.1

type LLDRuleFilter struct {
	Conditions  LLDRuleFilterConditions `json:"conditions"`
	EvalType    LLDEvalType             `json:"evaltype"`
	EvalFormula string                  `json:"eval_formula,omitempty"`
	Formula     string                  `json:"formula"`
}

type LLDRuleFilterCondition added in v0.16.1

type LLDRuleFilterCondition struct {
	Macro     string          `json:"macro"`
	Value     string          `json:"value"`
	FormulaID string          `json:"formulaid,omitempty"`
	Operator  LLDOperatorType `json:"operator,omitempty"`
}

type LLDRuleFilterConditions added in v0.16.1

type LLDRuleFilterConditions []LLDRuleFilterCondition

type LLDRules added in v0.16.1

type LLDRules []LLDRule

Items is an array of Item

type Macro added in v0.16.1

type Macro struct {
	MacroID   string `json:"hostmacroids,omitempty"`
	HostID    string `json:"hostid,omitempty"`
	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 added in v0.16.1

type Macros []Macro

Macros is an array of Macro

type Params

type Params map[string]interface{}

Params Zabbix request param

type Preprocessor added in v0.16.1

type Preprocessor struct {
	Type               string `json:"type,omitempty"`
	Params             string `json:"params"`
	ErrorHandler       string `json:"error_handler,omitempty"`
	ErrorHandlerParams string `json:"error_handler_params"`
}

type Preprocessors added in v0.16.1

type Preprocessors []Preprocessor

type Proxies added in v0.16.1

type Proxies []Proxy

Proxies is an array of Proxy

type Proxy added in v0.16.1

type Proxy struct {
	ProxyID string `json:"proxyid,omitempty"`
	Host    string `json:"host"`
}

Proxy represent Zabbix proxy object https://www.zabbix.com/documentation/3.2/manual/api/reference/proxy/object

type RawResponse added in v0.16.1

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 added in v0.3.1

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 Tag added in v0.16.1

type Tag struct {
	Tag   string `json:"tag"`
	Value string `json:"value,omitempty"`
}

type Tags added in v0.16.1

type Tags []Tag

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"`
	Groups          HostGroupIDs `json:"groups"`
	UserMacros      Macros       `json:"macros"`
	LinkedTemplates TemplateIDs  `json:"templates,omitempty"`
	ParentTemplates TemplateIDs  `json:"parentTemplates,omitempty"`
	TemplatesClear  TemplateIDs  `json:"templates_clear,omitempty"`
	LinkedHosts     []string     `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 added in v0.16.1

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

TemplateID use with host creation

type TemplateIDs added in v0.16.1

type TemplateIDs []TemplateID

TemplateIDs is an Array of TemplateID structs.

type Templates added in v0.3.0

type Templates []Template

Templates is an Array of Template structs.

type Trigger added in v0.3.1

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

	Opdata             string `json:"opdata,omitempty"`
	Type               int    `json:"type,string"`
	Url                string `json:"url,omitempty"`
	RecoveryMode       int    `json:"recovery_mode,string"`
	RecoveryExpression string `json:"recovery_expression,omitempty"`
	CorrelationMode    int    `json:"correlation_mode,string"`
	CorrelationTag     string `json:"correlation_tag,omitempty"`
	ManualClose        int    `json:"manual_close,string"`

	Priority     SeverityType     `json:"priority,string"`
	Status       StatusType       `json:"status,string"`
	Dependencies TriggerIDs       `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"`
	Tags        Tags  `json:"tags,omitempty"`
}

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

type TriggerFunction added in v0.16.1

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 added in v0.16.1

type TriggerFunctions []TriggerFunction

TriggerFunctions is an array of TriggerFunction

type TriggerID added in v0.16.1

type TriggerID struct {
	TriggerID string `json:"triggerid"`
}

type TriggerIDs added in v0.16.1

type TriggerIDs []TriggerID

TemplateIDs is an Array of TemplateID structs.

type Triggers added in v0.3.1

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
JackTT - Gopher 🇻🇳