0

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 21: Alert fired

  • Count changes from 12: Alert fired

  • Count changes from 01: Alert fired

  • Count stays at 22: 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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.