Page 1 of 4

ES 6.0: Rules engine for notifications

Posted: Mon Sep 07, 2020 10:02 pm
by asker
In ES 6.0 (about to be released), I've started working on a rules file. Right now, on a per monitor basis, you can select mute times for alarms as well as send out alarms for only specific causes.

I'd love for folks to test. This is quite new.
Read more HERE

Example of rules:

Code: Select all

{
    "notifications": {
        "monitors":{
            "6": {
                "comment1": "Deck",
                "rules": [{
                    "time_format":"%I:%M %p",
                    "from":"9 pm",
                    "to":"6 am",
                    "comment2": "this means if it is not person, don't send (perl regex)",
                    "cause_has":"^(?!.*(person)).*$",
                    "action":"mute"

                }]
            },
            "10": {
                "comment1": "Front Door",
                "rules": [{
                    "time_format":"%I:%M %p",
                    "from":"9 pm",
                    "to":"6 am",
                    "comment2": "This means if it is a cat or dog, don't send",
                    "cause_has":"(cat|dog)",
                    "action":"mute"

                }]
            }

        }
    }


}

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 9:59 am
by Magic919
Can I please clarify whether this should work for me. I don't have normal set-up, but it currently works for me. I use filters and notify on just one monitor.

However, I'd like to use Pushover.

Monitor 12 I'd like to mute and not get Pushover alerts.

Monitor 9 I'd like to get Pushover alerts.

If I switch on Pushover alerts and then monitor 12 to the JSON file with all-day mute I should just see alerts from monitor 9.

It's fine if it doesn't match my use case.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 12:21 pm
by asker
Yes, you can do this via rules as you outlined. You could also just disable Monitor 12 in zmNinja in the list of monitors to send notifications (Menu->Settings->Event Server->deselect monitor 12)

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 12:43 pm
by Magic919
Ok, thanks.

I'll concentrate on the rules engine json method as that's what you want tested.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 12:50 pm
by asker
Sounds good, thanks.

1. Please make sure ES is restarted after you change rules.
2. when testing, do a "tail -F /var/log/zm/zmeventnotification.log | grep 'rules:'" so you can see how rules are being processed for an event.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 1:47 pm
by Magic919
This is interested. It's not working as I expected, but probably could.

It's sending me a Pushover notification for start of event. I have end event notifications off.

Further down the logs I see matching the mute rule.

Code: Select all

CONSOLE DBG-1:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 API push script returned : 0
CONSOLE DBG-1:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 Matching alarm to connection rules...
CONSOLE DBG-1:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules: (eid: ) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules: parsing rule 6:30 am/10 pm using format:%I:%M %p
CONSOLE DBG-2:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules: parsed time from: Thu Jan  1 06:30:00 1970 and to:Thu Jan  1 22:00:00 1970
CONSOLE DBG-2:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules:(eid: )  seeing if now:02:39 pm is between:06:30 am and 10:00 pm
CONSOLE DBG-1:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules: (eid: $eid) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 Rules Check disallowed further processing for this alarm
CONSOLE DBG-1:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules: (eid: ) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules:(eid: )  seeing if now:02:39 pm is between:06:30 am and 10:00 pm
CONSOLE DBG-1:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 rules: (eid: $eid) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-09,14:39:43 |----> FORK:Shed2 (12), eid:222772 Rules Check disallowed further processing for this alarm
CONSOLE DBG-2:2020-09-09,14:39:45 |----> FORK:Shed2 (12), eid:222772 DB Event notes contain detection text, all good
CONSOLE DBG-2:2020-09-09,14:39:45 |----> FORK:Shed2 (12), eid:222772 Adding event path:/video/zoneminder/12/2020-09-09/222772 to hook for image storage
CONSOLE DBG-1:2020-09-09,14:39:45 |----> FORK:Shed2 (12), eid:222772 Invoking hook on event end:'/var/lib/zmeventnotification/bin/zm_event_end.sh' 222772 12 "Shed2" "[a] detected:car:100%  Motion: All" "/video/zoneminder/12/2020-09-09/222772"
CONSOLE DBG-2:2020-09-09,14:39:45 |----> FORK:Shed2 (12), eid:222772 parse of hook:[a] detected:car:100%  Motion: All and []
CONSOLE DBG-1:2020-09-09,14:39:45 |----> FORK:Shed2 (12), eid:222772 hook end returned with text:[a] detected:car:100%  Motion: All  json:[] exit:0
CONSOLE DBG-1:2020-09-09,14:39:47 |----> FORK:Shed2 (12), eid:222772 rules: (eid: ) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-09,14:39:47 |----> FORK:Shed2 (12), eid:222772 rules:(eid: )  seeing if now:02:39 pm is between:06:30 am and 10:00 pm
CONSOLE DBG-1:2020-09-09,14:39:47 |----> FORK:Shed2 (12), eid:222772 rules: (eid: $eid) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-09,14:39:47 |----> FORK:Shed2 (12), eid:222772 Not processing end notifications as rules checks failed for start notification


Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 1:48 pm
by Magic919
PS. I've stopped ES via ZMDC and I'm just running in a console and watching the output.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 2:12 pm
by asker
Ah yes. Pushover is an API. So far the rules engine will block native pushes (i.e. FCM). Let me look into extending it for API based invocations too.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 2:27 pm
by asker
Could you update and try again?

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 2:30 pm
by Magic919
Thanks for your reply. I appreciate your efforts and I'll watch with interest. If it's worthwhile in your opinion I'll welcome the alteration.

Meanwhile I'll take a better look at ZMNinja/ES notifcations, since that was the point of this.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 2:30 pm
by Magic919
Just seen that reply. Yes, in a few minutes I'll try it.

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 2:41 pm
by Magic919
Ok, that seems to do the trick. Just got it installed before a van appeared and no Pushover notification on that monitor.

I'll watch it for a bit longer.

Thanks again!

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 3:03 pm
by asker
Sounds good, but please test the reverse as well (i/e it sends out when it should)

Re: ES 6.0: Rules engine for notifications

Posted: Wed Sep 09, 2020 5:24 pm
by Magic919
I’m getting Pushover alerts from the required monitor and none from the muted one.

When I have a bit more time I’ll check ZMNinja/ES alerts and see how they behave whilst muted.

Thank you.

Re: ES 6.0: Rules engine for notifications

Posted: Thu Sep 10, 2020 7:58 am
by Magic919
This alert got muted, but it shouldn't have.

I presume this is the second part of the json that mutes 3-6 am. I'll have a go at removing that, but I'm not a json expert.

Would prefer 24 hour clock if that's an option :-)