Worked Walkthrough¶
Start to finish: a check, a threshold, and both event types.
-- 1. A check already exists with a threshold (built-in or your own — see
-- the Adding Your Own Checks book for creating your own from scratch).
-- Here, a built-in: PGHF11-009 (superuser login percentage), warn/crit
-- already seeded.
-- 2. Page on critical via a function event:
CREATE OR REPLACE FUNCTION pghf.page_oncall(p_evaluation_id bigint, p_args jsonb) RETURNS void
LANGUAGE plpgsql AS $$
BEGIN
-- swap in your real paging integration; this just demonstrates the shape
PERFORM pg_notify('oncall_bridge', jsonb_build_object(
'evaluation_id', p_evaluation_id,
'service', p_args ->> 'service'
)::text);
END;
$$;
SELECT pghf.create_event('PGHF11-009', 'function', 'critical',
p_routine => 'pghf.page_oncall(bigint, jsonb)'::regprocedure,
p_function_args => '{"service": "postgres-prod"}'::jsonb
);
-- 3. Log-only heads-up on warning via NOTIFY, staged inactive until the
-- listener is confirmed running:
SELECT pghf.create_event('PGHF11-009', 'notify', 'warning',
p_channel_name => 'pghf_heads_up', p_is_active => false);
-- 4. Confirm the listener, then activate it:
SELECT pghf.update_event(
(SELECT event_id FROM pghf.check_events WHERE channel_name = 'pghf_heads_up'),
'notify', 'warning', true, p_channel_name => 'pghf_heads_up'
);
-- 5. Run collection + evaluation as usual — events fire as part of this,
-- no separate step:
CALL pghf.run_and_evaluate(p_run_key => 'default');
-- 6. Later, if the noise level isn't right, adjust without losing the
-- registration:
SELECT pghf.update_event(
(SELECT event_id FROM pghf.check_events WHERE channel_name = 'pghf_heads_up'),
'notify', 'warning', false, p_channel_name => 'pghf_heads_up' -- pause it
);
-- 7. Or remove it outright once it's no longer needed:
SELECT pghf.delete_event((SELECT event_id FROM pghf.check_events WHERE channel_name = 'pghf_heads_up'));
That's the complete guide to events. From here, the Reference Guide documents every event function's exact parameters, and the User Guide covers the rest of the framework.