I have a widget that shows with the number of gateways that haven't been seen (not been online) for >= 2 days (The output is basically the most recent refreshed date and the value, aka the count of hubs not seen, as two columns).
I want to set up an alert rule that will notify me if that count number changes. E.g. current count is 2 (2 gateways haven't been seen for >= 2 days) and now it changes to 1 (e.g. because on gateway has come back online, so only one hub hasn't been seen for >=2 days) and that change I want to be notified about (and also in the other direction, when more gateways are added to the count as they haven't been seen for >= 2 days).
CREATE TABLE gateway_status (
gateway_id VARCHAR(50),
last_seen TIMESTAMP,
status VARCHAR(20)
);
INSERT INTO gateway_status VALUES
('gateway_001', '2024-06-09 10:00:00', 'offline'),
('gateway_002', '2024-06-09 10:00:00', 'offline'),
('gateway_003', '2024-06-11 09:00:00', 'online');
--Current Query
sqlSELECT
NOW() as "time",
COUNT(*) as "value"
FROM gateway_status
WHERE last_seen <= NOW() - INTERVAL '2 days';
Desired alert behavior:
Count changes from
2→1: Alert firedCount changes from
1→2: Alert firedCount changes from
0→1: Alert firedCount stays at
2→2: No alert
How best to approach this?
I tried a lot with ChatGPT which always suggests adding a new query and using diff() function, however the diff option doesn't show up for me. I know how to set it up so it alerts me when it becomes more than 2 but I can't figure out how to set it up so it also alerts it when it changes in the other direction.