Items — asking for numbers
An item is a question the system asks on a schedule, and its key is the question's name. Most keys are built in and you never think about them; the interesting ones are the keys you invent, because a key you invented is a thing you can make true or false with your own hands.
Every item has four things worth
remembering. A key, written like
a function — system.cpu.load[all,avg1]
means the average load over all
processors over the last minute, and
the brackets hold parameters. A
type, which says who answers:
type 0 is the Zabbix agent (the
agent answers on port 10050); type 19
waits for zabbix_sender to push a
value; type 20 waits for the HTTP
agent; others ask SNMP devices and web
pages. An update interval — how
often the question is asked; the
template's ordinary items ask every
minute, and values in between are
unknown, not zero. And a value
type: number, float, character,
log line, or plain text — the answer's
shape, which decides what rules can be
written about it later.
The stock template's 82 items cover
the machine's ordinary business, and
you read them in two places. The web
page Monitoring → Latest data shows
the most recent answer of each item
and its time, which is the view the
lab checked first; the API's
item.get shows the same facts in
text (key_, lastvalue, lastclock
— the clock as seconds since the
epoch, which any date tool converts).
Both are the same database row, and
the API's version is what scripts
consume.
But the lab's item of interest was invented: a user parameter. Agent 2 lets you teach it new keys by putting a line in its configuration:
UserParameter=lab.gauge,cat /home/hatch/workspace/zabbix-labwork/var/gauge.txt
From then on lab.gauge is a real
key: ask the agent, and it runs that
command and hands back the output.
The item this guide made for it was
deliberately simple — type 0, value
type text (value_type 4), interval
ten seconds, with the file's contents
as the answer:
{"hostid": "10683", "name": "Lab gauge reading", "key_": "lab.gauge",
"type": 0, "value_type": 4, "delay": "10s", "interfaceid": "31"}
and the server answered with itemid
50880. Two practicalities fell
out of making it, both worth knowing
before you make your first item of
your own. The first: an item must name
the interface it is asked through
— leave interfaceid off an agent
item and the API refuses it, naming
the missing field. The second is the
power of the thing: because the answer
is a file you control, you can choose
what the system sees, and that makes
the gauge the perfect trigger for
chapter 7 — the condition you can
switch on and off with a text editor,
without breaking anything.
A short note on how the other types
feel. SNMP items ask a device, not an
agent, for a counter under an OID —
the same polling, different language,
and the agent never appears. HTTP
agent items fetch a URL and treat the
body as a value, which is how a web
page or a JSON endpoint becomes a
monitored number with no agent at
all. Trapper items sit and wait for
zabbix_sender — useful for the
scripts that already know their own
state and want Zabbix to remember it.
All of them land in the same place: a
value with a time, waiting for a rule.
The check. An item works when its
latest value is current and true. The
lab's gauge read all quiet, which
was, at that moment, exactly what the
file said; the load average moved as
the machine worked; the agent's
hostname matched the host's technical
name. Items are where a monitoring
system earns its trust, and the trust
comes from checking one answer by
hand before believing the other
eighty-one.