Triggers and problems
A trigger is a small formula about values; a problem is the formula coming true. This is the chapter where the monitoring loop closes: the lab writes one rule about its gauge, commits the offence, watches the problem arrive in the API and on the web page, and watches it leave again the moment the offence stops.
A trigger is attached to a host and written as an expression over items:
find(/lab-server/lab.gauge,#1,"like","ALARM")=1
Read it as a sentence: the find
function, over the host lab-server's
item lab.gauge, taking the most
recent value (#1), says whether it
contains the text ALARM — and the
trigger fires when that equals 1. The
host's path inside the expression is
why a trigger can never be written
about a host that does not exist: it
names the items it watches by their
address. Triggers also carry a
severity — the lab's was priority
3, average — because a room full of
problems needs triaging, and a
recovery: by default a problem
ends when the expression stops being
true, which is what lets the lab
resolve its own problem below by
undoing the cause.
The first expression the lab tried
reached further — it asked find to
compare against a past window by
seconds — and the machinery pushed
back instructively: the time-shift
wanted a {$MACRO} in its place; the
revised expression above, comparing a
count of values, parsed and was
accepted at once. The lesson is
general: trigger functions have small
typed grammars, and the error text is
the manual for the line you are on.
(One more grammar note, because it
trips everyone: problems are looked
up by the trigger, not by the
item or the host — problem.get takes
the trigger's id as its objectid.)
Created, the trigger was triggerid 25287, description Gauge reports trouble — the name matters, because the name is the problem's title everywhere it appears. Then the lab committed the offence:
$ echo 'ALARM: the red valve is open' > var/gauge.txt
and polled the problems of trigger 25287 through the API, every second, asking for the current ones only:
after 8s: 1 current problem(s)
eventid: 46 | name: Gauge reports trouble | r_eventid: 0
r_eventid: 0 means unresolved, and
the one open problem, born eight
seconds after the file changed, was
the trigger keeping its promise. The
web page told the same story: the
problems view's HTML contained the
text "Gauge reports trouble", the
same words a person logging in would
read — the page and the API are two
windows on one problem table.
Then the file was put back:
$ echo 'all quiet' > var/gauge.txt
and the same polling found the
problem's r_eventid filled with
event 47, the recovery event: the
formula stopped being true and the
problem closed by itself, no human
required. Fire, see, recover — that
trip is the whole concept of a
monitoring system, and this is why the
lab built a gauge it could flip
instead of waiting for a real disk to
fill: a trigger you cannot fire on
purpose is a trigger you cannot
verify, and an unverifiable alarm is
a superstition, not a safeguard.
The inherited template triggers are
written the same way, only soberly:
a sustained condition (last()
averages over minutes instead of a
single answer), a five-minute window
of no data at all as its own alarm,
recoveries matched to their offences.
Read two of them before writing your
first production trigger; they encode
a decade of false-alarm avoidance —
in particular, the discipline that a
single bad answer proves nothing.
The check. A trigger is verified the way the lab verified it: cause the condition, count the seconds, read the problem in the API, read the same name on the web page, un-cause the condition, and read the recovery event beside it. Transcript t06 holds both directions. Chapter 8 takes the problem one step further — out of the system, to a person.