Skip to content

Firing an Event on a Severity Change

Everything so far gets you a severity recorded against a run — reading it back out (through the reporting functions, or a scheduled poll) is still up to you. The events layer is the other option: register a notification channel, or a function call, against a check, and the evaluation engine fires it automatically, with no polling needed.

-- NOTIFY a channel the moment X01-001 first reaches warning or worse
SELECT pghf.create_event('X01-001', 'notify', 'warning', p_channel_name => 'x01_alerts');

-- or call your own function instead — signature (bigint, jsonb) RETURNS void,
-- with whatever config it needs passed through as p_function_args
SELECT pghf.create_event('X01-001', 'function', 'critical',
    p_routine       => 'pghf.notify_slack(bigint, jsonb)'::regprocedure,
    p_function_args => '{"webhook_url": "https://hooks.example.com/..."}'::jsonb
);

An event needs a threshold or evaluator already in place to have anything to react to — a check with neither always evaluates as "not evaluable," which no event ever fires on. Firing itself is transition-only: an event fires once when severity crosses into the floor you chose, then stays quiet on later runs while it remains at or above that level, firing again only after a recovery and a later re-breach — never once per qualifying run.

That's enough to get one running. For the full picture — every parameter, the exact firing rule with worked examples, updating/activating/inactivating/deleting an event, the permission model, and a troubleshooting checklist for "why didn't my event fire" — see the dedicated Events book.

Continue to Inactivating a Check.