Delay "camera offline" email notification and suppress it if the camera comes back online within 5 minutes
Hi all,
I'm hoping someone here can point me in the right direction with an alerting issue.
Background
A customer has asked to receive an email notification whenever a camera goes offline. I've set this up using event rules --> When camera disconnected do send e-mail.
The problem
Some of the cameras briefly drop offline for around a minute, and then reconnect on their own. Every time this happens, an email is sent immediately. The customer is receiving a lot of notifications for what are effectively non-issues, which makes it harder to spot a camera that is genuinely down.
What I'd like to achieve
Instead of alerting on the first "offline" event, I'd like the system to:
Detect that the camera went offline.
Wait 5 minutes and check the camera's status again.
Send the email only if the camera is still offline.
Send nothing if the camera has come back online in the meantime.
My questions
Is this possible natively, for example with a delayed action, a "state persists for X minutes" condition, or a re-check?
If not, is there a workaround, such as a script, a scheduled task, or an internal HTTP request?
Has anyone else dealt with this kind of "flapping" behaviour and found a clean solution?
Any tips, examples, or pointers to the relevant documentation would be greatly appreciated. Thanks in advance!
-
Hi Bram Alert
Short answer: you can't do this with the built-in rules. The Rules Engine has no "condition persists for X minutes" option, no delayed action, and no re-check. When the Camera Disconnected event fires, the action runs right away.
Two things to know first:
- The Server already ignores very short interruptions. A brief drop in the stream is reported as a Network Issue event, not as Camera Disconnected. Camera Disconnected only fires once the Server has actually lost the device. So if these cameras show as disconnected for about a minute, that's a real loss of connection, not noise.
- Cameras that keep dropping offline and coming back aren't normal. The best fix is to find out why it happens.
If you need a delayed alert anyway, you can build one with a server-side script. Here's how it fits together:
- Put a non-interactive script (Batch, Bash, or Python) in the Server's scripts folder. The Server can run it through the REST API with
POST /rest/v4/servers/{id}/scripts/{name}/run. THIS article explains the folder locations and the API calls. - Change your current rule to: When Camera Disconnected, do Internal HTTPS request, and call the script's run endpoint, and pass the camera ID as an argument. Set "waitForFinished" to false so the rule doesn't sit and wait for 5 minutes.
- The script waits 5 minutes (or any time you set in the script) and then asks the Server for the camera's status. If the camera is still offline, the script sends a Generic Event to the Server. If it's back online, the script exits and does nothing.
- Add a second rule: When Generic Event (for example, caption contains "Camera still offline"), do Send email. The email still goes out through the VMS, using your existing SMTP settings and recipients. Generic Events are explained HERE.
Pseudocode for the script:
# Argument: camera ID passed in by the rule camera_id = args[0] lock_file = "/tmp/offline_check_" + camera_id # Skip if a check for this camera is already running # (stops duplicate checks when a camera drops several times in a row) if exists(lock_file): exit create(lock_file) sleep(300) # wait 5 minutes # Ask the Server for the camera's current status response = GET https://localhost:7001/rest/v4/devices/{camera_id}?_with=name,status status = response.status name = response.name if status not in ["Online", "Recording"]: # Still down: create a Generic Event so the email rule fires POST https://localhost:7001/rest/v4/events/generic { "source": "Offline monitor", "caption": "Camera still offline", "description": name + " has been offline for more than 5 minutes", "deviceIds": [camera_id] } delete(lock_file)Some tips:
- Make a dedicated local user for the script. Give it access to the cameras and the "Generate events" permission, and don't use an administrator account. The script runs on the Server, so keep it locked down.
- You can also add a "camera back online" email. Run the same check from a Camera Connected rule, or send a second Generic Event after recovery. This depends on what the customer wants.
- Test it by unplugging a camera for 1 minute, then for 6 minutes, and confirm you get an email only for the second test.
Best regards.
0
Please sign in to leave a comment.
Comments
1 comment