zabbix

package module
v0.0.0-...-1cdce18 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: GPL-2.0 Imports: 11 Imported by: 0

README

go-zabbix

Go bindings for the Zabbix API

go report card cover.run GPL license GoDoc

Overview

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

A number of Zabbix API bindings already exist for Go with varying levels of maturity. This project aims to provide an alternative implementation which is stable, fast, and allows for loose typing (using types such asinterface{} or map[string]interface{}) as well as strong types (such as Host or Event).

The package aims to have comprehensive coverage of Zabbix API methods from v1.8 through to v3.0 without introducing limitations to the native API methods.

Getting started

package main

import (
	"crypto/tls"
	"fmt"
	"log"
	"net/http"

	"github.com/cavaliercoder/go-zabbix"
)

func main() {
	// Default approach - without session caching
	session, err := zabbix.NewSession("http://zabbix/api_jsonrpc.php", "Admin", "zabbix")
	if err != nil {
		panic(err)
	}

	version, err := session.GetVersion()

	if err != nil {
		panic(err)
	}

	fmt.Printf("Connected to Zabbix API v%s", version)

	// Use session builder with caching.
	// You can use own cache by implementing SessionAbstractCache interface
	// Optionally an http.Client can be passed to the builder, allowing to skip TLS verification,
	// pass proxy settings, etc.

	client := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true
			}
		}
	}

	cache := zabbix.NewSessionFileCache().SetFilePath("./zabbix_session")
	session, err := zabbix.CreateClient("http://zabbix/api_jsonrpc.php").
		WithCache(cache).
		WithHTTPClient(client).
		WithCredentials("Admin", "zabbix").
		Connect()
	if err != nil {
		log.Fatalf("%v\n", err)
	}

	version, err := session.GetVersion()

	if err != nil {
		log.Fatalf("%v\n", err)
	}

	fmt.Printf("Connected to Zabbix API v%s", version)
}

License

Released under the GNU GPL License

Documentation

Overview

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

A number of Zabbix API bindings already exist for Go with varying levels of maturity. This project aims to provide an alternative implementation which is stable, fast, and allows for loose typing (using types such as interface{} or map[string]interface{}) as well as strong types (such as zabbix.Host or zabbix.Event).

The package aims to have comprehensive coverage of Zabbix API methods from v1.8 through to v3.0 without introducing limitations to the native API methods.

package main

import (
	"fmt"
	"github.com/cavaliercoder/go-zabbix"
)

func main() {
	// Default approach - without session caching
	session, err := zabbix.NewSession("http://zabbix/api_jsonrpc.php", "Admin", "zabbix")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Connected to Zabbix API v%s", session.GetVersion())

	// Use session builder with caching.
	// You can use own cache by implementing SessionAbstractCache interface
	// Optionally an http.Client can be passed to the builder, allowing to skip TLS verification,
	// pass proxy settings, etc.

	client := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true
			}
		}
	}
	cache := zabbix.NewSessionFileCache().SetFilePath("./zabbix_session")
	session, err := zabbix.CreateClient("http://zabbix/api_jsonrpc.php").
		WithCache(cache).
		WithHTTPClient(client).
		WithCredentials("Admin", "zabbix").
		Connect()

	fmt.Printf("Connected to Zabbix API v%s", session.GetVersion())
}

For more information see: https://github.com/cavaliercoder/go-zabbix

Index

Constants

View Source
const (
	// ActionEvalTypeAndOr indicated that an Action will evaluate its conditions
	// using AND/OR bitwise logic.
	ActionEvalTypeAndOr = iota

	// ActionEvalTypeAnd indicated that an Action will evaluate its conditions
	// using AND bitwise logic.
	ActionEvalTypeAnd

	// ActionEvalTypeOr indicated that an Action will evaluate its conditions
	// using OR bitwise logic.
	ActionEvalTypeOr
)
View Source
const (
	// AlertTypeMessage indicates that an Alert is a notification message.
	AlertTypeMessage = iota

	// AlertTypeRemoteCommand indicates that an Alert is a remote command call.
	AlertTypeRemoteCommand
)
View Source
const (
	// AlertMessageStatusNotSent indicates that an Alert of type
	// AlertTypeMessage has not been sent yet.
	AlertMessageStatusNotSent = iota

	// AlertMessageStatusSent indicates that an Alert of type AlertTypeMessage
	// has been sent successfully.
	AlertMessageStatusSent

	// AlertMessageStatusFailed indicates that an Alert of type AlertTypeMessage
	// failed to send.
	AlertMessageStatusFailed
)
View Source
const (
	// AlertCommandStatusRun indicates that an Alert of type
	// AlertTypeRemoteCommand has been run.
	AlertCommandStatusRun = 1 + iota

	// AlertCommandStatusAgentUnavailable indicates that an Alert of type
	// AlertTypeRemoteCommand failed to run as the Zabbix Agent was unavailable.
	AlertCommandStatusAgentUnavailable
)
View Source
const (
	// EventSourceTrigger indicates that an Event was created by a Trigger.
	EventSourceTrigger = iota

	// EventSourceDiscoveryRule indicates than an Event was created by a
	// Discovery Rule.
	EventSourceDiscoveryRule

	// EventSourceAutoRegistration indicates that an Event was created by an
	// active Host registration rule.
	EventSourceAutoRegistration

	// EventSourceInternal indicates that an Event was created by an Internal
	// Event.
	EventSourceInternal
)
View Source
const (
	// EventObjectTypeTrigger indicates that an Event with Source type
	// EventSourceTrigger or EventSourceInternal is related to a Trigger.
	EventObjectTypeTrigger = iota

	// EventObjectTypeDiscoveredHost indicates that an Event with Source type
	// EventSourceDiscoveryRule is related to a discovered Host.
	EventObjectTypeDiscoveredHost

	// EventObjectTypeDiscoveredService indicates that an Event with Source type
	// EventSourceDiscoveryRule is related to a discovered Service.
	EventObjectTypeDiscoveredService

	// EventObjectTypeAutoRegisteredHost indicates that an Event with Source
	// type EventSourceAutoRegistration is related to an auto-registered Host.
	EventObjectTypeAutoRegisteredHost

	// EventObjectTypeItem indicates that an Event with Source type
	// EventSourceInternal is related to an Item.
	EventObjectTypeItem

	// EventObjectTypeLLDRule indicates that an Event with Source type
	// EventSourceInternal is related to a low-level Discovery Rule.
	EventObjectTypeLLDRule
)
View Source
const (
	// TriggerEventValueOK indicates that the Object related to an Event with
	// Source type EventSourceTrigger is in an "OK" state.
	TriggerEventValueOK = iota

	// TriggerEventValueProblem indicates that the Object related to an Event with
	// Source type EventSourceTrigger is in a "Problem" state.
	TriggerEventValueProblem
)
View Source
const (
	// DiscoveryEventValueUp indicates that the Host or Service related to an
	// Event with Source type EventSourceDiscoveryRule is in an "Up" state.
	DiscoveryEventValueUp = iota

	// DiscoveryEventValueDown indicates that the Host or Service related to an
	// Event with Source type EventSourceDiscoveryRule is in a "Down" state.
	DiscoveryEventValueDown

	// DiscoveryEventValueDiscovered indicates that the Host or Service related
	// to an Event with Source type EventSourceDiscoveryRule is in a
	// "Discovered" state.
	DiscoveryEventValueDiscovered

	// DiscoveryEventValueLost indicates that the Host or Service related to an
	// Event with Source type EventSourceDiscoveryRule is in a "Lost" state.
	DiscoveryEventValueLost
)
View Source
const (
	// InternalEventValueNormal indicates that the Object related to an Event
	// with Source type EventSourceInternal is in a "Normal" state.
	InternalEventValueNormal = iota

	// InternalEventValueNotSupported indicates that the Object related to an
	// Event with Source type EventSourceInternal is in an "Unknown" or
	// "Not supported" state.
	InternalEventValueNotSupported
)
View Source
const (
	// SortOrderAscending is a valid value for GetParameters.SortOrder and
	// causes an API query to return all results sorted in ascending order by
	// the fields specified in GetParmeters.SortField.
	SortOrderAscending = "ASC"

	// SortOrderDescending is a valid value for GetParameters.SortOrder and
	// causes an API query to return all results sorted in descending order by
	// the fields specified in GetParmeters.SortField.
	SortOrderDescending = "DESC"
)
View Source
const (
	// HostSourceDefault indicates that a Host was created in the normal way.
	HostSourceDefault = 0

	// HostSourceDiscovery indicates that a Host was created by Host discovery.
	HostSourceDiscovery = 4
)
View Source
const (
	// HostgroupSourcePlain indicates that a Hostgroup was created in the normal way.
	HostgroupSourcePlain = 0

	// HostgroupSourceDiscovery indicates that a Hostgroup was created by Host discovery.
	HostgroupSourceDiscovery = 4

	// HostgroupInternalNo indicates that a Hostgroup is used not internally by the system.
	HostgroupInternalNo = 0

	// HostgroupInternalYes indicates that a Hostgroup is used internally by the system.
	HostgroupInternalYes = 1
)
View Source
const (
	Once int = iota
	EveryDay
	EveryWeek
	EveryMonth
)
View Source
const (
	// SelectExtendedOutput may be given as a SelectQuery in search parameters
	// to return all available feilds for all objects in the search results.
	SelectExtendedOutput = "extend"

	// SelectCount may be given as a SelectQuery for supported search parameters
	// to return only the number of available search results, instead of the
	// search result details.
	SelectCount = "count"
)
View Source
const (
	// TriggerAlarmStateOK means a normal trigger state. Called FALSE in older Zabbix versions.
	TriggerAlarmStateOK = iota

	// TriggerAlarmStateProblem normally means that something happened.
	TriggerAlarmStateProblem
)
View Source
const (
	// TriggerStateNormal means normal trigger state
	TriggerStateNormal = iota

	// TriggerStateUnknown means unknown trigger state
	TriggerStateUnknown
)
View Source
const (
	// TriggerSeverityNotClassified is Not classified severity
	TriggerSeverityNotClassified = iota

	// TriggerSeverityInformation is Information severity
	TriggerSeverityInformation

	// TriggerSeverityWarning is Warning severity
	TriggerSeverityWarning

	// TriggerSeverityAverage is Average severity
	TriggerSeverityAverage

	// TriggerSeverityHigh is High severity
	TriggerSeverityHigh

	// TriggerSeverityDisaster is Disaster severity
	TriggerSeverityDisaster
)

Variables

View Source
var ErrMaintenanceHostNotFound = errors.New("Failed to find ID by host name")
View Source
var ErrNotFound = errors.New("No results were found matching the given search parameters")

ErrNotFound describes an empty result set for an API call.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// Code is the Zabbix API error code.
	Code int `json:"code"`

	// Message is a short error summary.
	Message string `json:"message"`

	// Data is a detailed error message.
	Data string `json:"data"`
}

APIError represents a Zabbix API error.

func (*APIError) Error

func (e *APIError) Error() string

Error returns the string representation of an APIError.

type Action

type Action struct {
	// ActionID is the unique ID of the Action.
	ActionID string

	// StepDuration is the interval in seconds between each operation step.
	StepDuration int

	// EvaluationType determines the bitwise logic used to evaluate the Actions
	// conditions.
	//
	// EvaluationType must be one of the ActionEvalType constants.
	//
	// EvaluationType is only supported up to Zabbix v2.2.
	EvaluationType int

	// EventType is the type of Events that this Action will handle.
	//
	// Source must be one of the EventSource constants.
	EventType int

	// Name is the name of the Action.
	Name string

	// ProblemMessageBody is the message body text to be submitted for this
	// Action.
	ProblemMessageBody string

	// ProblemMessageSubject is the short summary text to be submitted for this
	// Action.
	ProblemMessageSubject string

	// RecoveryMessageBody is the message body text to be submitted for this
	// Action.
	RecoveryMessageBody string

	// RecoveryMessageSubject is the short summary text to be submitted for this
	// Action.
	RecoveryMessageSubject string

	// RecoveryMessageEnabled determines whether recovery messages will be
	// submitted for the Action when the source problem is resolved.
	RecoveryMessageEnabled bool

	// Enabled determines whether the Action is enabled or disabled.
	Enabled bool

	// Conditions are the conditions which must be met for this Action to
	// execute.
	Conditions []ActionCondition

	// Operations are the operations which will be exectuted for this Action.
	Operations []ActionOperation
}

Action represents a Zabbix Action returned from the Zabbix API.

See: https://www.zabbix.com/documentation/2.2/manual/config/notifications/action

type ActionCondition

type ActionCondition struct{}

ActionCondition is action condition

type ActionGetParams

type ActionGetParams struct {
	GetParameters
}

ActionGetParams is query params for action.get call

type ActionOperation

type ActionOperation struct{}

ActionOperation is action operation

type Alert

type Alert struct {
	// AlertID is the unique ID of the Alert.
	AlertID string

	// ActionID is the unique ID of the Action that generated this Alert.
	ActionID string

	// AlertType is the type of the Alert.
	// AlertType must be one of the AlertType constants.
	AlertType int

	// Timestamp is the UTC timestamp at which the Alert was generated.
	Timestamp time.Time

	// ErrorText is the error message if there was a problem sending a message
	// or running a remote command.
	ErrorText string

	// EscalationStep is the escalation step during which the Alert was
	// generated.
	EscalationStep int

	// EventID is the unique ID of the Event that triggered this Action that
	// generated this Alert.
	EventID string

	// MediaTypeID is the unique ID of the Media Type that was used to send this
	// Alert if the AlertType is AlertTypeMessage.
	MediaTypeID string

	// Message is the Alert message body if AlertType is AlertTypeMessage.
	Message string

	// RetryCount is the number of times Zabbix tried to send a message.
	RetryCount int

	// Recipient is the end point address of a message if AlertType is
	// AlertTypeMessage.
	Recipient string

	// Status indicates the outcome of executing the Alert.
	//
	// If AlertType is AlertTypeMessage, Status must be one of the
	// AlertMessageStatus constants.
	//
	// If AlertType is AlertTypeRemoteCommand, Status must be one of the
	// AlertCommandStatus constants.
	Status int

	// Subject is the Alert message subject if AlertType is AlertTypeMessage.
	Subject string

	// UserID is the unique ID of the User the Alert message was sent to.
	UserID string

	// Hosts is an array of Hosts that triggered this Alert.
	//
	// Hosts is only populated if AlertGetParams.SelectHosts is given in the
	// query parameters that returned this Alert.
	Hosts []Host
}

Alert represents a Zabbix Alert returned from the Zabbix API.

See: https://www.zabbix.com/documentation/2.2/manual/config/notifications

type AlertGetParams

type AlertGetParams struct {
	GetParameters

	// SelectHosts causes all Hosts which triggered the Alert to be attached in
	// the search results.
	SelectHosts SelectQuery `json:"selectHosts,omitempty"`

	// SelectMediaTypes causes the Media Types used for the Alert to be attached
	// in the search results.
	SelectMediaTypes SelectQuery `json:"selectMediatypes,omitempty"`

	// SelectUsers causes all Users to which the Alert was addressed to be
	// attached in the search results.
	SelectUsers SelectQuery `json:"selectUsers,omitempty"`
}

AlertGetParams is query params for alert.get call

type ClientBuilder

type ClientBuilder struct {
	// contains filtered or unexported fields
}

ClientBuilder is Zabbix API client builder

func CreateClient

func CreateClient(apiEndpoint string) *ClientBuilder

CreateClient creates a Zabbix API client builder

func (*ClientBuilder) Connect

func (builder *ClientBuilder) Connect() (session *Session, err error)

Connect creates Zabbix API client and connects to the API server or provides a cached server if any cache was specified

func (*ClientBuilder) WithCache

func (builder *ClientBuilder) WithCache(cache SessionAbstractCache) *ClientBuilder

WithCache sets cache for Zabbix sessions

func (*ClientBuilder) WithCredentials

func (builder *ClientBuilder) WithCredentials(username string, password string) *ClientBuilder

WithCredentials sets auth credentials for Zabbix API

func (*ClientBuilder) WithHTTPClient

func (builder *ClientBuilder) WithHTTPClient(client *http.Client) *ClientBuilder

WithHTTPClient sets the HTTP client to use to connect to the Zabbix API

type Event

type Event struct {
	// EventID is the ID of the Event.
	EventID string

	// Acknowledged indicates if the Event has been acknowledged by an operator.
	Acknowledged bool

	// Timestamp is the UTC timestamp at which the Event occurred.
	Timestamp time.Time

	// Source is the type of the Event source.
	//
	// Source must be one of the EventSource constants.
	Source int

	// ObjectType is the type of the Object that is related to the Event.
	// ObjectType must be one of the EventObjectType constants.
	ObjectType int

	// ObjectID is the unique identifier of the Object that caused this Event.
	ObjectID int

	// Value is the state of the related Object.
	//
	// Value must be one of the EventValue constants, according to the Event's
	// Source type.
	Value int

	// ValueChanges indicates if the state of the related Object has changed
	// since the previous Event.
	ValueChanged bool

	// Hosts is an array of Host which contained the Object which created this
	// Event.
	//
	// Hosts is only populated if EventGetParams.SelectHosts is given in the
	// query parameters that returned this Event and the Event Source is one of
	// EventSourceTrigger or EventSourceDiscoveryRule.
	Hosts []Host
}

Event represents a Zabbix Event returned from the Zabbix API. Events are readonly as they may only be created by the Zabbix server.

See: https://www.zabbix.com/documentation/2.2/manual/config/events

type EventGetParams

type EventGetParams struct {
	GetParameters

	// EventIDs filters search results to Events that matched the given Event
	// IDs.
	EventIDs []string `json:"eventids,omitempty"`

	// GroupIDs filters search results to events for hosts that are members of
	// the given Group IDs.
	GroupIDs []string `json:"groupids,omitempty"`

	// HostIDs filters search results to events for hosts that matched the given
	// Host IDs.
	HostIDs []string `json:"hostids,omitempty"`

	// ObjectIDs filters search results to events for Objects that matched
	// the given Object IDs.
	ObjectIDs []string `json:"objectids,omitempty"`

	// ObjectType filters search results to events created by the given Object
	// Type. Must be one of the EventObjectType constants.
	//
	// Default: EventObjectTypeTrigger
	ObjectType int `json:"object"`

	// AcknowledgedOnly filters search results to event which have been
	// acknowledged.
	AcknowledgedOnly bool `json:"acknowledged"`

	// MinEventID filters search results to Events with an ID greater or equal
	// to the given ID.
	MinEventID string `json:"eventid_from,omitempty"`

	// MaxEventID filters search results to Events with an ID lesser or equal
	// to the given ID.
	MaxEventID string `json:"eventid_till,omitempty"`

	// MinTime filters search results to Events with a timestamp lesser than or
	// equal to the given timestamp.
	MinTime int64 `json:"time_from,omitempty"`

	// MaxTime filters search results to Events with a timestamp greater than or
	// equal to the given timestamp.
	MaxTime int64 `json:"time_till,omitempty"`

	// Value filters search results to Events with the given values. Each value
	// must be one of the EventValue constants for the given ObjectType.
	Value []int `json:"value,omitempty"`

	// SelectHosts causes all Hosts which contain the object that caused each
	// Event to be attached in the search results.
	SelectHosts SelectQuery `json:"selectHosts,omitempty"`

	// SelectRelatedObject causes the object which caused each Event to be
	// attached in the search results.
	SelectRelatedObject SelectQuery `json:"selectRelatedObject,omitempty"`

	// SelectAlerts causes Alerts generated by each Event to be attached in the
	// search results.
	SelectAlerts SelectQuery `json:"select_alerts,omitempty"`

	// SelectAcknowledgements causes Acknowledgments for each Event to be
	// attached in the search results in reverse chronological order.
	SelectAcknowledgements SelectQuery `json:"select_acknowledges,omitempty"`
}

EventGetParams is query params for event.get call

type GetParameters

type GetParameters struct {
	// CountOutput indicates whether an API call should return the number of
	// records in the result instead of the actual data.
	CountOutput bool `json:"countOutput,omitempty"`

	// EditableOnly indicates whether an API call should only return results
	// that the user has write permissions to.
	EditableOnly bool `json:"editable,omitempty"`

	// ExcludeSearch indicates whether an API call should only return result
	// that do not match the given Search parameter.
	ExcludeSearch bool `json:"excludeSearch,omitempty"`

	// Filter causes an API query to return only results that exactly match the
	// given filter where map keys are the API fields to query and map values
	// are an exact value (or array of values) that must match each key field.
	//
	// Not valid for text fields.
	Filter map[string]interface{} `json:"filter,omitempty"`

	// ResultLimit limits the number of records returned by an API query.
	ResultLimit int `json:"limit,omitempty"`

	// NodeIDs causes an API query to return only the result that belong to the
	// given Zabbix nodes.
	NodeIDs []string `json:"nodeids,omitempty"`

	// OutputFields causes an API query to return only the given fields for each
	// result.
	//
	// Default: SelectExtendedOutput
	OutputFields SelectQuery `json:"output,omitempty"`

	// TextSearch causes an API query to return only results that match the
	// given wilcard search where the map keys are the desired field names and
	// the map values are the search expression.
	//
	// Only string and text fields are supported.
	TextSearch map[string]string `json:"search,omitempty"`

	// TextSearchByStart causes an API query to return only results that match
	// the search parameters given in TextSearch where each given field starts
	// with the given search expressions.
	//
	// By default, TextSearch will return results that match a search expression
	// anywhere in a field's value; not just the start.
	TextSearchByStart bool `json:"startSearch,omitempty"`

	// SearchByAny currently has an unknown affect (TODO). According to the
	// Zabbix API documentation: If set to true return results that match any of
	// the criteria given in the filter or search parameter instead of all of
	// them.
	SearchByAny bool `json:"searchByAny,omitempty"`

	// EnableTextSearchWildcards enables the use of "*" as a wildcard character
	// in the given TextSearch search criteria.
	EnableTextSearchWildcards bool `json:"searchWildcardsEnabled,omitempty"`

	// Return only hosts that have inventory data matching the given wildcard search.
	// This parameter is affected by the same additional parameters as search.
	SearchInventory map[string]string `json:"searchInventory,omitempty"`

	// SortField causes an API query to return all results sorted by the given
	// field names.
	SortField []string `json:"sortfield,omitempty"`

	// SortOrder causes an API query to return all results sorted in the given
	// order if SortField is defined.
	//
	// Must be one of SortOrderAscending or SortOrderDescending.
	SortOrder string `json:"sortorder,omitempty"`
}

GetParameters represents the common parameters for all API Get methods. See: https://www.zabbix.com/documentation/2.2/manual/api/reference_commentary#common_get_method_parameters

type History

type History struct {
	// Clock is the time when that value was received.
	Clock int

	// ItemID is the ID of the related item.
	ItemID int

	// Ns is the nanoseconds when the value was received.
	Ns int

	// Value is the received value.
	// Possible types: 0 - float; 1 - character; 2 - log; 3 - int; 4 - text;
	Value string

	// LogEventID is the Windows event log entry ID.
	LogEventID int

	// Severity is the Windows event log entry level.
	Severity int

	// Source is the Windows event log entry source.
	Source string

	// Timestamp is the Windows event log entry time.
	Timestamp string
}

History represents a Zabbix History returned from the Zabbix API.

See: https://www.zabbix.com/documentation/4.0/manual/api/reference/history/object

type HistoryGetParams

type HistoryGetParams struct {
	GetParameters

	// History object types to return
	// Possible values: 0 - numeric float, 1 - character, 2 - log,
	// 3 - numeric signed, 4, text
	// Default: 3
	History int `json:"history"`

	// HistoryIDs filters search results to histories with the given History ID's.
	HistoryIDs []string `json:"historyids,omitempty"`

	// ItemIDs filters search results to histories belong to the hosts
	// of the given Item ID's.
	ItemIDs []string `json:"itemids,omitempty"`

	// Return only values that have been received after or at the given time.
	TimeFrom float64 `json:"time_from,omitempty"`

	// Return only values that have been received before or at the given time.
	TimeTill float64 `json:"time_till,omitempty"`
}

type Host

type Host struct {
	// HostID is the unique ID of the Host.
	HostID string

	// Hostname is the technical name of the Host.
	Hostname string

	// DisplayName is the visible name of the Host.
	DisplayName string

	// Source is the origin of the Host and must be one of the HostSource
	// constants.
	Source int

	// Macros contains all Host Macros assigned to the Host.
	Macros []HostMacro

	// Groups contains all Host Groups assigned to the Host.
	Groups []Hostgroup
}

Host represents a Zabbix Host returned from the Zabbix API.

See: https://www.zabbix.com/documentation/2.2/manual/config/hosts

type HostGetParams

type HostGetParams struct {
	GetParameters

	// GroupIDs filters search results to hosts that are members of the given
	// Group IDs.
	GroupIDs []string `json:"groupids,omitempty"`

	// ApplicationIDs filters search results to hosts that have items in the
	// given Application IDs.
	ApplicationIDs []string `json:"applicationids,omitempty"`

	// DiscoveredServiceIDs filters search results to hosts that are related to
	// the given discovered service IDs.
	DiscoveredServiceIDs []string `json:"dserviceids,omitempty"`

	// GraphIDs filters search results to hosts that have the given graph IDs.
	GraphIDs []string `json:"graphids,omitempty"`

	// HostIDs filters search results to hosts that matched the given Host IDs.
	HostIDs []string `json:"hostids,omitempty"`

	// WebCheckIDs filters search results to hosts with the given Web Check IDs.
	WebCheckIDs []string `json:"httptestids,omitempty"`

	// InterfaceIDs filters search results to hosts that use the given Interface
	// IDs.
	InterfaceIDs []string `json:"interfaceids,omitempty"`

	// ItemIDs filters search results to hosts with the given Item IDs.
	ItemIDs []string `json:"itemids,omitempty"`

	// MaintenanceIDs filters search results to hosts that are affected by the
	// given Maintenance IDs
	MaintenanceIDs []string `json:"maintenanceids,omitempty"`

	// MonitoredOnly filters search results to return only monitored hosts.
	MonitoredOnly bool `json:"monitored_hosts,omitempty"`

	// ProxyOnly filters search results to hosts which are Zabbix proxies.
	ProxiesOnly bool `json:"proxy_host,omitempty"`

	// ProxyIDs filters search results to hosts monitored by the given Proxy
	// IDs.
	ProxyIDs []string `json:"proxyids,omitempty"`

	// IncludeTemplates extends search results to include Templates.
	IncludeTemplates bool `json:"templated_hosts,omitempty"`

	// SelectGroups causes the Host Groups that each Host belongs to to be
	// attached in the search results.
	SelectGroups SelectQuery `json:"selectGroups,omitempty"`

	// SelectApplications causes the Applications from each Host to be attached
	// in the search results.
	SelectApplications SelectQuery `json:"selectApplications,omitempty"`

	// SelectDiscoveries causes the Low-Level Discoveries from each Host to be
	// attached in the search results.
	SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"`

	// SelectDiscoveryRule causes the Low-Level Discovery Rule that created each
	// Host to be attached in the search results.
	SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule,omitempty"`

	// SelectGraphs causes the Graphs from each Host to be attached in the
	// search results.
	SelectGraphs SelectQuery `json:"selectGraphs,omitempty"`

	SelectHostDiscovery SelectQuery `json:"selectHostDiscovery,omitempty"`

	SelectWebScenarios SelectQuery `json:"selectHttpTests,omitempty"`

	SelectInterfaces SelectQuery `json:"selectInterfaces,omitempty"`

	SelectInventory SelectQuery `json:"selectInventory,omitempty"`

	SelectItems SelectQuery `json:"selectItems,omitempty"`

	SelectMacros SelectQuery `json:"selectMacros,omitempty"`

	SelectParentTemplates SelectQuery `json:"selectParentTemplates,omitempty"`
	SelectScreens         SelectQuery `json:"selectScreens,omitempty"`
	SelectTriggers        SelectQuery `json:"selectTriggers,omitempty"`
}

HostGetParams represent the parameters for a `host.get` API call.

See: https://www.zabbix.com/documentation/2.2/manual/api/reference/host/get#parameters

type HostMacro

type HostMacro struct {
	// HostMacroID is the unique ID of the Host Macro.
	HostMacroID string `json:"hostmacroid"`

	// HostID is the ID of the Host which owns this Macro.
	HostID string `json:"hostid"`

	// Macro is the name of the Macro (e.g. '{HOST.MACRO}').
	Macro string `json:"macro"`

	// Value is the value of the Macro.
	Value string `json:"value"`
}

HostMacro represents a Zabbix Host Macro returned from the Zabbix API.

type Hostgroup

type Hostgroup struct {
	GroupID  string `json:"groupid"`
	Name     string `json:"name"`
	Flags    string `json:"flags"`
	Internal string `json:"internal"`
	Hosts    []Host `json:"hosts,omitempty"`
}

Hostgroup represents a Zabbix Hostgroup Object returned from the Zabbix API (see zabbix documentation).

type HostgroupGetParams

type HostgroupGetParams struct {
	GetParameters

	// Return only host groups that contain hosts or templates with the given graphs
	GraphIDs []string `json:"graphids,omitempty"`

	// Return only host groups with the given host group IDs
	GroupIDs []string `json:"groupids,omitempty"`

	// Return only host groups that contain the given hosts
	HostIDs []string `json:"hostids,omitempty"`

	// Return only host groups that are affected by the given maintenances
	MaintenanceIDs []string `json:"maintenanceids,omitempty"`

	// Return only host groups that contain monitored hosts
	MonitoredHosts int `json:"monitored_hosts,omitempty"`

	// Return only host groups that contain hosts
	RealHosts int `json:"real_hosts,omitempty"`

	// Return only host groups that contain templates
	TemplatedHosts int `json:"templated_hosts,omitempty"`

	// Return only host groups that contain the given templates
	TemplateIDs []string `json:"templateids,omitempty"`

	// Return only host groups that contain hosts or templates with the given triggers
	TriggerIDs []string `json:"triggerids,omitempty"`

	// Return only host groups that contain hosts with applications
	WithApplications int `json:"with_applications,omitempty"`

	// Return only host groups that contain hosts with graphs
	WithGraphs int `json:"with_graphs,omitempty"`

	// Return only host groups that contain hosts or templates
	WithHostsAndTemplates int `json:"with_hosts_and_templates,omitempty"`

	// Return only host groups that contain hosts with web checks
	WithHttptests int `json:"with_httptests,omitempty"`

	// Return only host groups that contain hosts or templates with items
	WithItems int `json:"with_items,omitempty"`

	// Return only host groups that contain hosts with enabled web checks
	WithMonitoredHttptests int `json:"with_monitored_httptests,omitempty"`

	// Return only host groups that contain hosts or templates with enabled items
	WithMonitoredItems int `json:"with_monitored_items,omitempty"`

	// Return only host groups that contain hosts with enabled triggers
	WithMonitoredTriggers int `json:"with_monitored_triggers,omitempty"`

	// Return only host groups that contain hosts with numeric items
	WithSimpleGraphItems int `json:"with_simple_graph_items,omitempty"`

	// Return only host groups that contain hosts with triggers
	WithTriggers int `json:"with_triggers,omitempty"`

	// Return the LLD rule that created the host group in the discoveryRule property
	SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule,omitempty"`

	// Return the host group discovery object in the groupDiscovery property
	SelectGroupDiscovery SelectQuery `json:"selectGroupDiscovery,omitempty"`

	// Return the hosts that belong to the host group in the hosts property
	SelectHosts SelectQuery `json:"selectHosts,omitempty"`

	// Return the templates that belong to the host group in the templates property
	SelectTemplates SelectQuery `json:"selectTemplates,omitempty"`

	// Limits the number of records returned by subselects
	LimitSelects int `json:"limitSelects,omitempty"`

	// Return only host groups that contain the given templates
	Sortfield []string `json:"sortfield,omitempty"`
}

HostgroupGetParams represent the parameters for a `hostgroup.get` API call (see zabbix documentation).

type Item

type Item struct {
	// HostID is the unique ID of the Host.
	HostID int

	// ItemID is the unique ID of the Item.
	ItemID int

	// Itemname is the technical name of the Item.
	ItemName string

	// ItemDescr is the description of the Item.
	ItemDescr string

	// LastClock is the last Item epoh time.
	LastClock int

	// LastValue is the last value of the Item.
	LastValue string

	// LastValueType is the type of LastValue
	// 0 - float; 1 - text; 3 - int;
	LastValueType int
}

Item represents a Zabbix Item returned from the Zabbix API.

See: https://www.zabbix.com/documentation/4.0/manual/api/reference/item/object

type ItemGetParams

type ItemGetParams struct {
	GetParameters

	// ItemIDs filters search results to items with the given Item ID's.
	ItemIDs []string `json:"itemids,omitempty"`

	// GroupIDs filters search results to items belong to the hosts
	// of the given Group ID's.
	GroupIDs []string `json:"groupids,omitempty"`

	// TemplateIDs filters search results to items belong to the
	// given templates of the given Template ID's.
	TemplateIDs []string `json:"templateids,omitempty"`

	// HostIDs filters search results to items belong to the
	// given Host ID's.
	HostIDs []string `json:"hostids,omitempty"`

	// ProxyIDs filters search results to items that are
	// monitored by the given Proxy ID's.
	ProxyIDs []string `json:"proxyids,omitempty"`

	// InterfaceIDs filters search results to items that use
	// the given host Interface ID's.
	InterfaceIDs []string `json:"interfaceids,omitempty"`

	// GraphIDs filters search results to items that are used
	// in the given graph ID's.
	GraphIDs []string `json:"graphids,omitempty"`

	// TriggerIDs filters search results to items that are used
	// in the given Trigger ID's.
	TriggerIDs []string `json:"triggerids,omitempty"`

	// ApplicationIDs filters search results to items that
	// belong to the given Applications ID's.
	ApplicationIDs []string `json:"applicationids,omitempty"`

	// WebItems flag includes web items in the result.
	WebItems bool `json:"webitems,omitempty"`

	// Inherited flag return only items inherited from a template
	// if set to 'true'.
	Inherited bool `json:"inherited,omitempty"`

	// Templated flag return only items that belong to templates
	// if set to 'true'.
	Templated bool `json:"templated,omitempty"`

	// Monitored flag return only enabled items that belong to
	// monitored hosts if set to 'true'.
	Monitored bool `json:"monitored,omitempty"`

	// Group filters search results to items belong to a group
	// with the given name.
	Group string `json:"group,omitempty"`

	// Host filters search results to items that belong to a host
	// with the given name.
	Host string `json:"host,omitempty"`

	// Application filters search results to items that belong to
	// an application with the given name.
	Application string `json:"application,omitempty"`

	// WithTriggers flag return only items that are used in triggers
	WithTriggers bool `json:"with_triggers,omitempty"`
}

type Maintenance

type Maintenance struct {
	MaintenanceID string
	Name          string
	ActiveSince   time.Time

	Description string
	// Service period in hours
	ServicePeriod       int
	Type                MaintenanceType
	ActionEvalTypeAndOr TagsEvaltype
	// contains filtered or unexported fields
}

func (*Maintenance) Delete

func (m *Maintenance) Delete(session *Session) error

type MaintenanceCreateParams

type MaintenanceCreateParams struct {
	Groupids []string `json:"groupids,omitempty"`
	// Hosts name
	HostNames   []string      `json:"-"`
	HostIDs     []string      `json:"hostids"`
	Timeperiods []Timeperiods `json:"timeperiods"`
	Tags        []string      `json:"tags,omitempty"`
	// contains filtered or unexported fields
}

func (*MaintenanceCreateParams) FillFields

func (*MaintenanceCreateParams) FillHostIDs

func (m *MaintenanceCreateParams) FillHostIDs(session *Session) error

func (*MaintenanceCreateParams) Maintenance

func (c *MaintenanceCreateParams) Maintenance() (result *Maintenance, err error)

JMaintenanceToObject returns a native Go Maintenance struct mapped from the given JSON Maintenance data.

type MaintenanceGetParams

type MaintenanceGetParams struct {
	GetParameters

	// Sort the result by the given properties.
	// Possible values are: maintenanceid, name and maintenance_type.
	SortField []string `json:"sortfield,omitempty"`

	// Return the maintenance's time periods in the timeperiods property.
	SelectTimeperiods SelectQuery `json:"selectTimeperiods,omitempty"`

	// Return hosts assigned to the maintenance in the hosts property.
	SelectHosts SelectQuery `json:"selectHosts,omitempty"`

	// Return host groups assigned to the maintenance in the groups property.
	SelectGroups SelectQuery `json:"selectGroups,omitempty"`

	// Return only maintenances with the given IDs.
	Maintenanceids []string `json:"maintenanceids,omitempty"`

	// Return only maintenances that are assigned to the given hosts.
	Hostids []string `json:"hostids,omitempty"`

	// Return only maintenances that are assigned to the given host groups.
	Groupids []string `json:"groupids,omitempty"`
}

type MaintenanceType

type MaintenanceType int

type Request

type Request struct {
	// JSONRPCVersion is the version string of the Zabbix API. This should
	// always be set to "2.0".
	JSONRPCVersion string `json:"jsonrpc"`

	// Method is the name of the Zabbix API method to be called.
	Method string `json:"method"`

	// Params is the request's body.
	Params interface{} `json:"params"`

	// RequestID is an abitrary identifier for the Request which is returned in
	// the corresponding API Response to assist with multi-threaded
	// applications. This value is automatically incremented for each new
	// Request by NewRequest.
	RequestID uint64 `json:"id"`

	// AuthToken is the Request's authentication token. When used in a Session,
	// this value is overwritten by the Session.
	AuthToken string `json:"auth,omitempty"`
}

A Request represents a JSON-RPC request to be sent by a client.

This struct maps to the JSON request body described in the Zabbix API documentation: https://www.zabbix.com/documentation/2.2/manual/api#authentication.

func NewRequest

func NewRequest(method string, params interface{}) *Request

NewRequest returns a new Request given an API method name, and optional request body parameters.

type Response

type Response struct {
	// HTTP status code of the API response e.g. 200
	StatusCode int `json:"-"`

	// JSONRPCVersion is the version string of the Zabbix API. This should
	// always be set to "2.0".
	JSONRPCVersion string `json:"jsonrpc"`

	// Body represents the response body as an array of bytes.
	//
	// The Body may be decoded later into a struct with Bind or json.Unmarshal.
	Body json.RawMessage `json:"result"`

	// RequestID is an abitrary identifier which matches the RequestID set in
	// the corresponding API Request.
	RequestID int `json:"id"`

	// Error is populated with error information if the JSON-RPC request
	// succeeded but there was an API error.
	//
	// This struct maps to the JSON response body described in the Zabbix API
	// documentation:
	// https://www.zabbix.com/documentation/2.2/manual/api#error_handling.
	Error APIError `json:"error"`
}

Response represents the response from a JSON-RPC API request.

This struct maps to the JSON response body described in the Zabbix API documentation: https://www.zabbix.com/documentation/2.2/manual/api#authentication.

func (*Response) Bind

func (c *Response) Bind(v interface{}) error

Bind unmarshals the JSON body of the Response into the given interface.

func (*Response) Err

func (c *Response) Err() error

Err returns an error if the Response includes any error information returned from the Zabbix API.

type SelectFields

type SelectFields []string

SelectFields may be given as a SelectQuery in search parameters where each member string is the name of a JSON field which should be returned for each search result.

For example, for a Host search query:

query := SelectFields{ "hostid", "host", "name" }

type SelectQuery

type SelectQuery interface{}

SelectQuery represents the query data type for a Zabbix API call. Wherever a SelectQuery is required, one of SelectFields, SelectExtendedOutput or SelectCount should be given.

See: https://www.zabbix.com/documentation/2.2/manual/api/reference_commentary#data_types

type Session

type Session struct {
	// URL of the Zabbix JSON-RPC API (ending in `/api_jsonrpc.php`).
	URL string `json:"url"`

	// Token is the cached authentication token returned by `user.login` and
	// used to authenticate all API calls in this Session.
	Token string `json:"token"`

	// ApiVersion is the software version string of the connected Zabbix API.
	APIVersion string `json:"apiVersion"`
	// contains filtered or unexported fields
}

A Session is an authenticated Zabbix JSON-RPC API client. It must be initialized and connected with NewSession.

func NewSession

func NewSession(url string, username string, password string) (session *Session, err error)

NewSession returns a new Session given an API connection URL and an API username and password.

An error is returned if there was an HTTP protocol error, the API credentials are incorrect or if the API version is indeterminable.

The authentication token returned by the Zabbix API server is cached to authenticate all subsequent requests in this Session.

func (*Session) AuthToken

func (c *Session) AuthToken() string

AuthToken returns the authentication token used by this session to authentication all API calls.

func (*Session) CreateMaintenance

func (s *Session) CreateMaintenance(params *MaintenanceCreateParams) (err error)

func (*Session) CreateUserMacros

func (c *Session) CreateUserMacros(macros ...HostMacro) (hostMacroIds []string, err error)

CreateUserMacros creates a single or multiple new user macros. Returns a list of macro id(s) of created macro(s).

Zabbix API docs: https://www.zabbix.com/documentation/3.0/manual/config/macros/usermacros

func (*Session) DeleteUserMacros

func (c *Session) DeleteUserMacros(hostMacroIDs ...string) (hostMacroIds []string, err error)

DeleteUserMacros method allows to delete host user macros. Returns a list of deleted macro id(s).

Zabbix API docs: https://www.zabbix.com/documentation/2.2/manual/api/reference/usermacro/delete

func (*Session) Do

func (c *Session) Do(req *Request) (resp *Response, err error)

Do sends a JSON-RPC request and returns an API Response, using connection configuration defined in the parent Session.

An error is returned if there was an HTTP protocol error, a non-200 response is received, or if an error code is set is the JSON response body.

When err is nil, resp always contains a non-nil resp.Body.

Generally Get or a wrapper function will be used instead of Do.

func (*Session) Get

func (c *Session) Get(method string, params interface{}, v interface{}) error

Get calls the given Zabbix API method with the given query parameters and unmarshals the JSON response body into the given interface.

An error is return if a transport, marshalling or API error happened.

func (*Session) GetActions

func (c *Session) GetActions(params ActionGetParams) ([]Action, error)

GetActions queries the Zabbix API for Actions matching the given search parameters.

ErrNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetAlerts

func (c *Session) GetAlerts(params AlertGetParams) ([]Alert, error)

GetAlerts queries the Zabbix API for Alerts matching the given search parameters.

ErrNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetEvents

func (c *Session) GetEvents(params EventGetParams) ([]Event, error)

GetEvents queries the Zabbix API for Events matching the given search parameters.

ErrEventNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetHistories

func (c *Session) GetHistories(params HistoryGetParams) ([]History, error)

GetHistories queries the Zabbix API for Histories matching the given search parameters.

ErrEventNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetHostgroups

func (c *Session) GetHostgroups(params HostgroupGetParams) ([]Hostgroup, error)

GetHostgroups queries the Zabbix API for Hostgroups matching the given search parameters.

ErrEventNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetHosts

func (c *Session) GetHosts(params HostGetParams) ([]Host, error)

GetHosts queries the Zabbix API for Hosts matching the given search parameters.

ErrEventNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetItems

func (c *Session) GetItems(params ItemGetParams) ([]Item, error)

GetItems queries the Zabbix API for Items matching the given search parameters.

ErrEventNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetMaintenance

func (s *Session) GetMaintenance(params *MaintenanceGetParams) ([]Maintenance, error)

GetMaintenance queries the Zabbix API for Maintenance matching the given search parameters.

func (*Session) GetTriggers

func (c *Session) GetTriggers(params TriggerGetParams) ([]Trigger, error)

GetTriggers queries the Zabbix API for Triggers matching the given search parameters.

ErrTriggerNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetUserMacro

func (c *Session) GetUserMacro(params UserMacroGetParams) ([]HostMacro, error)

GetUserMacro queries the Zabbix API for user macros matching the given search parameters.

ErrEventNotFound is returned if the search result set is empty. An error is returned if a transport, parsing or API error occurs.

func (*Session) GetVersion

func (c *Session) GetVersion() (string, error)

GetVersion returns the software version string of the connected Zabbix API.

func (*Session) UpdateUserMacros

func (c *Session) UpdateUserMacros(macros ...HostMacro) (hostMacroIds []string, err error)

UpdateUserMacros method allows to update host user macros. Returns a list of updated macro id(s).

Zabbix API docs: https://www.zabbix.com/documentation/2.2/manual/api/reference/usermacro/update

type SessionAbstractCache

type SessionAbstractCache interface {
	// SetSessionLifetime sets lifetime of cached Zabbix session
	SetSessionLifetime(d time.Duration)

	// SaveSession saves session to a cache
	SaveSession(session *Session) error

	// HasSession checks if any valid Zabbix session has been cached and available
	HasSession() bool

	// GetSession returns cached Zabbix session
	GetSession() (*Session, error)

	// Flush removes cached session
	Flush() error
}

SessionAbstractCache represents abstract Zabbix session cache backend

type SessionFileCache

type SessionFileCache struct {
	// contains filtered or unexported fields
}

SessionFileCache is Zabbix session filesystem cache.

func NewSessionFileCache

func NewSessionFileCache() *SessionFileCache

NewSessionFileCache creates a new instance of session file system cache

func (*SessionFileCache) Flush

func (c *SessionFileCache) Flush() error

Flush removes a cached session

func (*SessionFileCache) GetSession

func (c *SessionFileCache) GetSession() (*Session, error)

GetSession returns cached Zabbix session

func (*SessionFileCache) HasSession

func (c *SessionFileCache) HasSession() bool

HasSession checks if any valid Zabbix session has been cached and available

func (*SessionFileCache) SaveSession

func (c *SessionFileCache) SaveSession(session *Session) error

SaveSession saves session to a cache

func (*SessionFileCache) SetFilePath

func (c *SessionFileCache) SetFilePath(filePath string) *SessionFileCache

SetFilePath sets Zabbix session cache file path. Default value is "./zabbix_session"

func (*SessionFileCache) SetFilePermissions

func (c *SessionFileCache) SetFilePermissions(permissions uint32) *SessionFileCache

SetFilePermissions sets permissions for a session file. Default value is 0655.

func (*SessionFileCache) SetSessionLifetime

func (c *SessionFileCache) SetSessionLifetime(d time.Duration)

SetSessionLifetime sets lifetime in seconds of cached Zabbix session. Default value is 4 hours.

type TagsEvaltype

type TagsEvaltype int

type Timeperiods

type Timeperiods struct {
	TimeperiodType int `json:"timeperiod_type,int"`
	Every          int `json:"every,string"`
	Dayofweek      int `json:"dayofweek,string"`
	StartTime      int `json:"start_time,string"`
	Period         int `json:"period,string"`
}

jMaintenance is a private map for the Zabbix API Maintenance object. See: https://www.zabbix.com/documentation/2.2/manual/api/reference/maintenance/object

type Trigger

type Trigger struct {
	// TriggerID is the ID of the Trigger.
	TriggerID string

	// AlarmState shows whether the trigger is in OK or problem state.
	//
	// AlarmState must be one of the TriggerAlarmState constants.
	AlarmState int

	// Description is the name of the trigger.
	Description string

	// Enabled shows whether the trigger is enabled or disabled.
	Enabled bool

	// Expression is the trigger expression
	Expression string

	// Hosts is an array of Hosts that the trigger belongs.
	//
	// Hosts is only populated if TriggerGetParams.SelectHosts is given in the
	// query parameters that returned this Trigger.
	Hosts []Host

	// Groups is an array of Hostgroups that the trigger belongs.
	//
	// Groups is only populated if TriggerGetParams.SelectGroups is given in the
	// query parameters that returned this Trigger.
	Groups []Hostgroup

	// LastChange is the time when the trigger last changed its state.
	LastChange int

	// Severity of the trigger.
	//
	// Severity must be one of the TriggerSeverity constants.
	Severity int

	// State of the trigger.
	//
	// State must be one of the TriggerState constants.
	State int

	// Tags is an array of trigger tags
	//
	// Tags is only populated if TriggerGetParams.SelectTags is given in the
	// query parameters that returned this Trigger.
	Tags []TriggerTag

	// LastEvent is the latest event for the trigger
	//
	// LastEvent is only populated if TriggerGetParams.SelectLastEvent is set
	LastEvent *Event

	// URL is a link to the trigger graph in Zabbix
	URL string
}

Trigger represents a Zabbix Trigger returned from the Zabbix API.

See: https://www.zabbix.com/documentation/3.4/manual/config/triggers

type TriggerGetParams

type TriggerGetParams struct {
	GetParameters

	// TriggerIDs filters search results to Triggers that matched the given Trigger
	// IDs.
	TriggerIDs []string `json:"triggerids,omitempty"`

	// GroupIDs filters search results to triggers for hosts that are members of
	// the given Group IDs.
	GroupIDs []string `json:"groupids,omitempty"`

	TemplateIDs []string `json:"templateids,omitempty"`

	// HostIDs filters search results to triggers for hosts that matched the given
	// Host IDs.
	HostIDs []string `json:"hostids,omitempty"`

	ItemIDs []string `json:"itemids,omitempty"`

	ApplicationIDs []string `json:"applicationids,omitempty"`

	Functions []string `json:"functions,omitempty"`

	Group string `json:"group,omitempty"`

	Host string `json:"host,omitempty"`

	// InheritedOnly filters search results to triggers which have been
	// inherited from a template.
	InheritedOnly bool `json:"inherited,omitempty"`

	TemplatedOnly bool `json:"templated,omitempty"`

	MonitoredOnly bool `json:"monitored,omitempty"`

	ActiveOnly bool `json:"active,omitempty"`

	MaintenanceOnly bool `json:"maintenance,omitempty"`

	WithUnacknowledgedEventsOnly bool `json:"withUnacknowledgedEvents,omitempty"`

	WithAcknowledgedEventsOnly bool `json:"withAcknowledgedEvents,omitempty"`

	WithLastEventUnacknowledgedOnly bool `json:"withLastEventUnacknowledged,omitempty"`

	SkipDependent bool `json:"skipDependent,omitempty"`

	RecentProblemOnly bool `json:"only_true,omitempty"`

	MinSeverity int `json:"min_severity,omitempty"`

	ExpandComment bool `json:"expandComment,omitempty"`

	ExpandDescription bool `json:"expandDescription,omitempty"`

	ExpandExpression bool `json:"expandExpression,omitempty"`

	// SelectGroups causes all Hostgroups which contain the object that caused each
	// Trigger to be attached in the search results.
	SelectGroups SelectQuery `json:"selectGroups,omitempty"`

	// SelectHosts causes all Hosts which contain the object that caused each
	// Trigger to be attached in the search results.
	SelectHosts SelectQuery `json:"selectHosts,omitempty"`

	SelectItems SelectQuery `json:"selectItems,omitempty"`

	SelectFunctions SelectQuery `json:"selectFunctions,omitempty"`

	SelectDependencies SelectQuery `json:"selectDependencies,omitempty"`

	SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule,omitempty"`

	SelectLastEvent SelectQuery `json:"selectLastEvent,omitempty"`

	SelectTags SelectQuery `json:"selectTags,omitempty"`
}

TriggerGetParams is params for trigger.get query

type TriggerTag

type TriggerTag struct {
	Name  string
	Value string
}

TriggerTag is trigger tag

type UserMacroGetParams

type UserMacroGetParams struct {
	GetParameters

	// Return global macros instead of host macros.
	GlobalMacro bool `json:"globalmacro,omitempty"`

	// Return only global macros with the given IDs.
	GlobalMacroIDs []string `json:"globalmacroids,omitempty"`

	// Return only host macros that belong to hosts or templates from the given host groups.
	GroupIDs []string `json:"groupids,omitempty"`

	// Return only macros that belong to the given hosts or templates.
	HostIDs []string `json:"hostids,omitempty"`

	// Return only host macros with the given IDs.
	HostMacroIDs []string `json:"hostmacroids,omitempty"`

	// Return only host macros that belong to the given templates. (Zabbix 2.x only)
	TemplateIDs []string `json:"templateids,omitempty"`
}

UserMacroGetParams represent the parameters for a `usermacro.get` API call (see zabbix documentation).

type UserMacroResponse

type UserMacroResponse struct {
	HostMacroIDs []string `json:"hostmacroids"`
}

UserMacroResponse represent usermacro action response body

Jump to

Keyboard shortcuts

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