Is the Nx Cloud up? Visit our Status Page for the current health and performance of the Nx Cloud.

Status Page

Delay "camera offline" email notification and suppress it if the camera comes back online within 5 minutes

Comments

1 comment

  • Norman
    • Network Optix team

    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:

    1. 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.
    2. 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:

    1. 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. 
    2. 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.
    3. 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.
    4. 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.