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 ¶
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
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.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client for Zabbix JSON-RPC API.
func NewClient ¶
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 ¶
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.
type ClientOpt ¶ added in v0.2.0
type ClientOpt func(c *Client)
func WithAPIToken ¶ added in v0.5.0
func WithHTTPClient ¶ added in v0.2.0
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
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