ES 6.0: Rules engine for notifications

Discussion topics related to mobile applications for ZoneMinder
User avatar
asker
Posts: 1410
Joined: Sun Mar 01, 2015 12:12 pm

ES 6.0: Rules engine for notifications

Post by asker » Mon Sep 07, 2020 10:02 pm

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"

                }]
            }

        }
    }


}
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

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

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 9:59 am

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: 1410
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker » Wed Sep 09, 2020 12:21 pm

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)
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

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

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 12:43 pm

Ok, thanks.

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

User avatar
asker
Posts: 1410
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker » Wed Sep 09, 2020 12:50 pm

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.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

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

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 1:47 pm

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: 142
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 1:48 pm

PS. I've stopped ES via ZMDC and I'm just running in a console and watching the output.

User avatar
asker
Posts: 1410
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker » Wed Sep 09, 2020 2:12 pm

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.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

User avatar
asker
Posts: 1410
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker » Wed Sep 09, 2020 2:27 pm

Could you update and try again?
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

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

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 2:30 pm

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: 142
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 2:30 pm

Just seen that reply. Yes, in a few minutes I'll try it.

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

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 2:41 pm

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: 1410
Joined: Sun Mar 01, 2015 12:12 pm

Re: ES 6.0: Rules engine for notifications

Post by asker » Wed Sep 09, 2020 3:03 pm

Sounds good, but please test the reverse as well (i/e it sends out when it should)
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

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

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Wed Sep 09, 2020 5:24 pm

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: 142
Joined: Wed Sep 18, 2013 6:56 am

Re: ES 6.0: Rules engine for notifications

Post by Magic919 » Thu Sep 10, 2020 7:58 am

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

Who is online

Users browsing this forum: No registered users and 4 guests