zabgrab.model.zabbix

Zabbix objects as seen by zabgrab.

zabgrab.model.zabbix.TIME_UNITS

Seconds per Zabbix time suffix.

Type:

dict of str to int

Functions

parse_period(text)

Parse a Zabbix storage period, such as 31d or 3600.

Classes

HistoryRow(time, value[, log_time, source, ...])

One raw value of an item.

Host(hostid, host, name[, enabled, groups])

A monitored host.

Item(itemid, hostid, host, host_name, name, ...)

An item on a host.

TrendRow(time, count, min, avg, max)

Hourly statistics of a numeric item.

ValueType(*values)

Zabbix item value types (the value_type/history API values).

class zabgrab.model.zabbix.ValueType(*values)[source]

Bases: IntEnum

Zabbix item value types (the value_type/history API values).

FLOAT, UNSIGNED

Numbers, which have hourly trends and can be plotted.

CHAR, LOG, TEXT

Text. Log items also have a log time, source, severity and event ID.

BINARY

Binary data, which zabgrab doesn’t fetch.

property label: str

Short human-readable name.

property numeric: bool

Whether values are numbers (and so have trends and can be plotted).

class zabgrab.model.zabbix.Host(hostid, host, name, enabled=True, groups=())[source]

Bases: object

A monitored host.

Parameters:
hostid

The host’s ID.

Type:

int

host

The technical name.

Type:

str

name

The visible name.

Type:

str

enabled

Whether it’s monitored.

Type:

bool

groups

The names of its host groups.

Type:

tuple of str

class zabgrab.model.zabbix.Item(itemid, hostid, host, host_name, name, key, value_type, units='', enabled=True, last_value=None, last_clock=None, history=None, trends=None, tags=())[source]

Bases: object

An item on a host.

Parameters:
itemid, hostid

The item’s and its host’s IDs.

Type:

int

host, host_name

The host’s technical and visible names.

Type:

str

name, key

The item’s name and key.

Type:

str

value_type

The type of its values.

Type:

ValueType

units

The units of its values (may be empty).

Type:

str

enabled

Whether it’s monitored.

Type:

bool

last_value

The latest value, if any.

Type:

str or None

last_clock

When the latest value was collected.

Type:

datetime or None

history, trends

How long raw values and hourly trends are kept, in seconds (0 means they aren’t), or None if not known.

Type:

int or None

tags

The item’s tags, as (name, value) pairs (the value may be empty). A name can appear more than once.

Type:

tuple of (str, str)

class zabgrab.model.zabbix.HistoryRow(time, value, log_time=None, source='', severity=0, event_id=0)[source]

Bases: object

One raw value of an item.

Parameters:
time

When it was collected, in POSIX seconds including the nanosecond part.

Type:

float

value

The value, as Zabbix returns it.

Type:

str

log_time, source, severity, event_id

The log entry’s own time, source, severity and event ID (log items only).

class zabgrab.model.zabbix.TrendRow(time, count, min, avg, max)[source]

Bases: object

Hourly statistics of a numeric item.

Parameters:
time

The start of the hour, in POSIX seconds.

Type:

int

count

How many values the hour had.

Type:

int

min, avg, max

The hour’s minimum, average and maximum, as Zabbix returns them.

Type:

str

zabgrab.model.zabbix.parse_period(text)[source]

Parse a Zabbix storage period, such as 31d or 3600.

Parameters:

text (str) – The period, as item.get returns it: whole seconds, optionally with a time suffix (s, m, h, d or w), or a user macro.

Returns:

int or None – The period in seconds (0 means nothing is kept), or None if it isn’t known (e.g. a macro, which the API doesn’t resolve).

Return type:

int | None

Examples

>>> parse_period("2w"), parse_period("3600"), parse_period("{$HISTORY}")
(1209600, 3600, None)