ES 6.0: Rules engine for notifications

Discussion topics related to mobile applications and ZoneMinder Event Server (including machine learning)
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

ES 6.0: Rules engine for notifications

Post 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"

                }]
            }

        }
    }


}
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post 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.
-
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post 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)
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post by Magic919 »

Ok, thanks.

I'll concentrate on the rules engine json method as that's what you want tested.
-
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post 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.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post 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

-
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post by Magic919 »

PS. I've stopped ES via ZMDC and I'm just running in a console and watching the output.
-
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post 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.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker »

Could you update and try again?
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post 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.
-
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post by Magic919 »

Just seen that reply. Yes, in a few minutes I'll try it.
-
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post 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!
-
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker »

Sounds good, but please test the reverse as well (i/e it sends out when it should)
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post 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.
-
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post 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 :-)
-
Post Reply