zabgrab.adapters.zabbix.api

Zabbix 7 JSON-RPC API client.

zabgrab.adapters.zabbix.api.MIN_VERSION

The oldest Zabbix version supported.

Type:

tuple of int

Classes

ZabbixAPI(transport)

A client for one Zabbix server.

class zabgrab.adapters.zabbix.api.ZabbixAPI(transport)[source]

Bases: object

A client for one Zabbix server.

Patterns passed to the search methods use the API’s wildcard search (searchWildcardsEnabled): they match the whole value, ignoring case, and * matches any text.

Parameters:

transport (zabgrab.adapters.zabbix.transport.Transport) – Sends the requests (HTTP in normal use; a fake in tests).

async call(method, params, *, auth=True)[source]

Call an API method and return its result.

Parameters:
  • method (str) – The API method, e.g. "item.get".

  • params (Any) – The method’s parameters.

  • auth (bool, optional) – Whether to send the token or session (if logged in).

Returns:

Any – The result of the response.

Raises:
Return type:

Any

async version()[source]

Get the server’s API version (e.g. "7.0.5").

Return type:

str

async check_version()[source]

Get the server’s version, checking zabgrab supports it.

Returns:

str – The version, e.g. "7.0.5".

Raises:

UnsupportedServer – If the server is older than MIN_VERSION.

Return type:

str

async login_token(token)[source]

Authenticate with an API token, checking it’s valid.

Parameters:

token (str) – The API token.

Raises:

AuthenticationFailed – If the server rejects the token.

Return type:

None

async login_password(username, password)[source]

Authenticate with a username and password.

The session is logged out again when the client is closed.

Parameters:
  • username (str) – The credentials.

  • password (str) – The credentials.

Raises:

AuthenticationFailed – If the server rejects them.

Return type:

None

async close()[source]

End any password session and close the connection.

Return type:

None

async hosts(*, pattern=None, group=None, limit=None)[source]

Find hosts.

Parameters:
  • pattern (str, optional) – A pattern for the technical or visible name (all hosts if not given).

  • group (str, optional) – Only hosts in a host group matching this pattern.

  • limit (int, optional) – The most hosts to return.

Returns:

list of Host – The hosts, sorted by visible name.

Return type:

list[Host]

async items(*, itemids=None, hostids=None, name=None, key=None, tag=None, limit=None)[source]

Find items on hosts (not templates) matching all of the given filters.

Parameters:
  • itemids (sequence of int, optional) – Only these items, or items on these hosts. Empty matches nothing.

  • hostids (sequence of int, optional) – Only these items, or items on these hosts. Empty matches nothing.

  • name (str, optional) – Patterns for the item’s name and key.

  • key (str, optional) – Patterns for the item’s name and key.

  • tag (str, optional) – "name" (the tag exists) or "name:value" (with exactly that value).

  • limit (int, optional) – The most items to return.

Returns:

list of Item – The items, sorted by name.

Return type:

list[Item]

async history(item, start, end)[source]

Get an item’s raw values.

Parameters:
  • item (Item) – The item.

  • start (int) – The time range in POSIX seconds (inclusive).

  • end (int) – The time range in POSIX seconds (inclusive).

Returns:

list of HistoryRow – The values, oldest first.

Return type:

list[HistoryRow]

async trends(item, start, end)[source]

Get an item’s hourly trends.

Parameters:
  • item (Item) – The item (numeric).

  • start (int) – The range of hour starts, in POSIX seconds (inclusive).

  • end (int) – The range of hour starts, in POSIX seconds (inclusive).

Returns:

list of TrendRow – The hours, oldest first.

Return type:

list[TrendRow]