zabbix

package module
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 14 Imported by: 0

README

go-zabbix

A minimal Zabbix API client for Go. See https://www.zabbix.com/documentation/6.0/en/manual/api for the Zabbix API.

This library is in very early stage of development. The API is not frozen yet.

Install

You can download a static-linked executable for Linux from https://github.com/hnakamur/go-zabbix/releases.

Or you can install from the source with the following command:

go install -trimpath -tags netgo github.com/hnakamur/go-zabbix/cmd/zbx@latest

License

MIT

Documentation

Overview

Package zabbix is a minimal Zabbix API client library.

This library is provides the only minimal lower level APIs.

Users can refer to https://www.zabbix.com/documentation/6.0/en/manual/api and create functions for their use cases.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidZabbixVer = errors.New("invalid Zabbix version")

Functions

This section is empty.

Types

type APIError added in v0.2.0

type APIError struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
	Data    string    `json:"data"`
}

APIError is an error object in responses from Zabbix JSON-RPC API. https://www.zabbix.com/documentation/current/en/manual/api#error-handling

func (*APIError) Error added in v0.2.0

func (e *APIError) Error() string

type APIVersion added in v0.2.0

type APIVersion struct {
	Major      int
	Minor      int
	Patch      int
	PreRelType PreRelType
	PreRelVer  int
}

func MustParseAPIVersion added in v0.2.0

func MustParseAPIVersion(ver string) APIVersion

func ParseAPIVersion added in v0.2.0

func ParseAPIVersion(ver string) (APIVersion, error)

func (APIVersion) Compare added in v0.2.0

func (v APIVersion) Compare(w APIVersion) int

func (APIVersion) String added in v0.2.0

func (v APIVersion) String() string

type CallError added in v0.2.0

type CallError struct {
	ID     uint64 `json:"id"`
	Method string `json:"method"`
	Params any    `json:"params"`
	Err    error  `json:"error"`
}

CallError is the error type returned by Client.Call method. The concret type of the Err field is APIError or other error.

func (*CallError) Error added in v0.2.0

func (e *CallError) Error() string

func (*CallError) Unwrap added in v0.2.0

func (e *CallError) Unwrap() error

type Client

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

Client represents a client for Zabbix JSON-RPC API.

func NewClient

func NewClient(zabbixURL string, opts ...ClientOpt) (*Client, error)

NewClient creates a client for Zabbix JSON-RPC API. zabbixURL is something like http://example.com/zabbix/, and not like http://example.com/zabbix/index.php.

func (*Client) APIVersion added in v0.2.0

func (c *Client) APIVersion(ctx context.Context) (APIVersion, error)

APIVersion returns APIVersion. For the first call of this method, a request is sent to the server and the result will be cached. For subsequent call of this method, it returns the cached value.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params, result any) error

Call sends a JSON-RPC request to the server. The caller of this method must pass a pointer to the appropriate type of result. The appropriate type is different for method and params.

func (*Client) Login

func (c *Client) Login(ctx context.Context, username, password string) error

Login sends a "user.login" request to the server. If the login is successful, the session ID will be returned from the server. It is kept in the Client and it will be set to requests created with Call method called after this call of Login method.

type ClientOpt added in v0.2.0

type ClientOpt func(c *Client)

func WithAPIToken added in v0.5.0

func WithAPIToken(token string) ClientOpt

func WithDebug added in v0.3.0

func WithDebug(debug bool) ClientOpt

func WithHTTPClient added in v0.2.0

func WithHTTPClient(httpClient *http.Client) ClientOpt

func WithHost added in v0.2.0

func WithHost(host string) ClientOpt

type ErrorCode added in v0.2.0

type ErrorCode int
const (
	// ErrorCodeNone represents the error which is not an error object from
	// Zabbix JSON-RPC API but some other error occurred in the client side.
	ErrorCodeNone ErrorCode = 0

	ErrorCodeParse          ErrorCode = -32700
	ErrorCodeInvalidRequest ErrorCode = -32600
	ErrorCodeMethodNotFound ErrorCode = -32601
	ErrorCodeInvalidParams  ErrorCode = -32602
	ErrorCodeInternal       ErrorCode = -32603
	ErrorCodeApplication    ErrorCode = -32500
	ErrorCodeSystem         ErrorCode = -32400
	ErrorCodeTransport      ErrorCode = -32300
)

func GetErrorCode added in v0.2.0

func GetErrorCode(err error) ErrorCode

GetErrorCode returns the Code field if err or a unwrapped error is APIError or ErrorCodeNone otherwise.

type PreRelType added in v0.2.0

type PreRelType int
const (
	Alpha PreRelType = iota - 3
	Beta
	RC // Release Candidate
	Release
)

func (PreRelType) String added in v0.2.0

func (t PreRelType) String() string

Directories

Path Synopsis
cmd
zbx
internal
rpc

Jump to

Keyboard shortcuts

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