New Lightweight ZM Instant Event Notify daemon project published

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

New Lightweight ZM Instant Event Notify daemon project published

Post by mp_inch »

Hi,

Just upgraded my zoneminder box for the third time in 15 years, added some cameras, etc. It was time to get some notifications to my phone.

There are some apps out there, but I really just wanted the notification.

Thus was born https://github.com/tarheele/zminstantnotify

For many years I desired a simple event notification script and pliablepixels published just the skeleton that I needed to build upon.

The result is a light weight event notification daemon which can be easily changed to call or do whatever you want. The provided sample actions script calls pushover to send instant notifications to your phone. You can alter it to call ifttt to turn on lights or voip call you. Or you could use it to send emails.

Almost out of the box you can get instant notifications via the pushover smartphone app with one of many selectable sounds. Pushover also provides VERY COOL option to have an emergency notification that will bug you until you confirm receipt. The pushover app has its own in-app snooze in case you have a windy day that blows up your phone with notifications. Obviously you have to create your own pushover account if you go this route.

Please let me know what you think.

Mark
Last edited by mp_inch on Thu Feb 13, 2020 8:02 pm, edited 1 time in total.
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

Re: New ZM Instant Event Notify daemon project published

Post by snake »

On your readme at the end, the second gist link is broken.

I'm not sure how much cpu time is used in polling, but seems better approach is like viewtopic.php?f=9&t=26758&start=15

But, talk is cheap, so you can ignore what I say. I haven't built anything like this. Good job.
User avatar
iconnor
Posts: 2879
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: New ZM Instant Event Notify daemon project published

Post by iconnor »

Looks cool!

My thoughts on this are: since this does some of what zmeventserver.pl does, it would have been nicer to sorta enhance zmES instead of writing another service to maintain. Maybe we can work towards that goal.

We developers decided a while back to use http://google.github.io/styleguide/ Google's style guide for code style. I know pliablepixel doesn't follow it, but it will help with inclusion and getting help if you do (my mind isn't as flexible at reading other styles anymore... damn this aging thing).

Another thought... there is an issue with reading from shm files in that if you have the shm file open and zmc restarts, it will create a new shm file. Your's won't get updated and it will consume space in /dev/shm.

In zmwatch.pl and other daemons we actually close and re-open the shm file regularly to prevent this.
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

Re: New ZM Instant Event Notify daemon project published

Post by mp_inch »

Thanks for taking a look!
snake wrote: Thu Feb 13, 2020 2:39 pm On your readme at the end, the second gist link is broken.
I am planning to create my own gist that have the correct filenames inside which will fix that. Thanks for pointing that bad link out!
snake wrote: Thu Feb 13, 2020 2:39 pm I'm not sure how much cpu time is used in polling, but seems better approach is like viewtopic.php?f=9&t=26758&start=15
The polling is all shared memory and the shared memory polling script stays loaded. Since no db i/o and no disk i/o, no major CPU impact.

Just for grins, I set EVENT_CHECK_INTERVAL_IN_MILLISECONDS to poll every 5 milliseconds and saw no change in CPU.

You can modify the polling interval by changing EVENT_CHECK_INTERVAL_IN_MILLISECONDS

I agree that polling is usually a bad thing, but it seems to work pretty well in this situation.

Thanks
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

Re: New ZM Instant Event Notify daemon project published

Post by mp_inch »

iconnor wrote: Thu Feb 13, 2020 2:44 pm Looks cool!
Thanks! And thanks for taking the time to look and comment.
iconnor wrote: Thu Feb 13, 2020 2:44 pm My thoughts on this are: since this does some of what zmeventserver.pl does, it would have been nicer to sorta enhance zmES instead of writing another service to maintain. Maybe we can work towards that goal.
I did look at https://github.com/pliablepixels/zmeventnotification (that project?) and at the code before publishing this. In the README, the project looks image detection focused, despite the title. In the code, I did not see a clear place to plug in what I am trying to do. It looks like some beautiful code, but I was overwhelmed, quite frankly. It is a LOT of code.

I can't seem to find the code I originally based mine after, but I suspect it may have been some early experimental version of zmeventnotification.

KISS was my goal here. I wanted the least dependencies possible. I think my module requires no perl additions, no db, no crypto, not much of anything except zoneminder.
iconnor wrote: Thu Feb 13, 2020 2:44 pm We developers decided a while back to use http://google.github.io/styleguide/ Google's style guide for code style. I know pliablepixel doesn't follow it, but it will help with inclusion and getting help if you do (my mind isn't as flexible at reading other styles anymore... damn this aging thing).
Are you aware of a VS Code plugin which will prettify according to this style? I get the aging thing, we are probably in the same boat.
iconnor wrote: Thu Feb 13, 2020 2:44 pm Another thought... there is an issue with reading from shm files in that if you have the shm file open and zmc restarts, it will create a new shm file. Your's won't get updated and it will consume space in /dev/shm.

In zmwatch.pl and other daemons we actually close and re-open the shm file regularly to prevent this.
That advice is gold. I will research how to do that.

Should I check to see if zmc has stopped running and then die to be respawned by zm? I will look at the code you referenced.

Thanks!
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

Re: New ZM Instant Event Notify daemon project published

Post by mp_inch »

iconnor wrote: Thu Feb 13, 2020 2:44 pm My thoughts on this are: since this does some of what zmeventserver.pl does, it would have been nicer to sorta enhance zmES instead of writing another service to maintain. Maybe we can work towards that goal.
@iconnor, I meant to say in my other post that I plan to take a look at this and see where I would plug it in.

Stream of consciousness...

"sub sendEvent" seems to be where the channels are invoked. So I would add an elsif for my "pushover" channel. It looks like my action script would be a new channel in addition to the existing ones of web,fcm,mqtt

I see another thread on zmeventserver, so I will read that.

It looks like zm_event_start.sh is merely an event screener hook. That hook is not intended to be a subscriber/consumer of the events because that what the channels are for, I think.

Okay, this seems do-able. Have to bone up on my python.

In addition to my pushover channel would also add a "user" channel and leave an empty invocation lying around for users to pick up and add their own implementation. That would have made my new integration more clear.

Do you re-read the ini every so often? I think for simplicity, I would still call my script externally so it would pick up fresh changes.
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: New Lightweight ZM Instant Event Notify daemon project published

Post by asker »

I don't think this needs to be integrated to the event server as it stands today. TBH, the ES already does everything this script does and more. My guess is the OP isn't very familiar with the ES functionality - a deeper read will probably clear up various incorrect assumptions about the ES above, but more importantly, I don't think this needs to be plugged in.

The ES doesn't use pushover, but its trivial to add (I don't plan to add it however at least now, as FCM exists and is free).
There is however a place for this script for folks who only want an alarm pushed to their phone and nothing more. I see it as an extension to zm-alarm.pl.

My suggestion to the OP is to continue extending it for his/her needs and in future, if there is a need to merge, we can look into it. As of now, there isn't any additional functionality that I think warrants all the effort to make this a plugin into ES. The ES is indeed more complex, because it does a lot more. If one needs to connect the two simply using event_start_hook to be invoke some action in this script should suffice.

I would note that the GitHub repo seems to have inherited parts of my repo, both code blocks and documents (like the readme that refers to how it should be installed/zmdc edits etc which are direct copy paste from my instructions and link to my gists, including a typo at a place calling this zmeventnotification.pl as that's what the original instructions said) - please re-do the docs (code is fine) so there is no confusion between this and zmeventnofication.pl.
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
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

Re: New Lightweight ZM Instant Event Notify daemon project published

Post by mp_inch »

Hi asker,
asker wrote: Fri Feb 14, 2020 12:54 am The ES doesn't use pushover, but its trivial to add (I don't plan to add it however at least now, as FCM exists and is free).
Does FCM have a standalone client? I have used FCM and GCM to develop apps, but I don't plan to develop my own client for this use case. I may check out zmNinja, but I was mainly looking a notification for a game camera. That was my motivation for pushover.
asker wrote: Fri Feb 14, 2020 12:54 am There is however a place for this script for folks who only want an alarm pushed to their phone and nothing more. I see it as an extension to zm-alarm.pl.
I searched for a simple alarm plugin and had not found zm-alarm.pl yet, so thanks for the pointer! It does not appear to have logic to handle Isaac's note about the case where you "have the shm file open and zmc restarts", correct?

asker wrote: Fri Feb 14, 2020 12:54 am If one needs to connect the two simply using event_start_hook to be invoke some action in this script should suffice.
I may integrate into ES because it is probably more robust and has solved Isaac's shm file open issues described above.

Are you receptive to contributions for pushover, ifttt, and other integrations?

Also, I notice that my script misses some events because they are maybe firing quicker than the polling loop. So ES may fix this. For example, I have a monitor with 3 zones. I am interested in one particular zone, but I suspect that another zone on that monitor fires first and the one I am interested in may missed by the polling. ES looks like it may handle this case better.
asker wrote: Fri Feb 14, 2020 12:54 am I would note that the GitHub repo seems to have inherited parts of my repo, both code blocks and documents (like the readme that refers to how it should be installed/zmdc edits etc which are direct copy paste from my instructions and link to my gists, including a typo at a place calling this zmeventnotification.pl as that's what the original instructions said) - please re-do the docs (code is fine) so there is no confusion between this and zmeventnofication.pl.
Yes, the beauty of open source. As noted above, I do intend to clean that up and add my own gists. I did give a shout out to pliablepixels in the docs and code. I haven't been on this forum in a while because zoneminder has just been running and doing its thing in my house without me having to do much for the past 7+ years (v1.23 was my last upgrade after getting burned by some upgrade issues in the past) so I have not needed to be on the forums. It appears from the avatars that asker==pliablepixels. Thanks for all you do for zoneminder.
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: New Lightweight ZM Instant Event Notify daemon project published

Post by asker »

Does FCM have a standalone client? I have used FCM and GCM to develop apps, but I don't plan to develop my own client for this use case. I may check out zmNinja, but I was mainly looking a notification for a game camera. That was my motivation for pushover.
FCM is the "core" of Google's Push library, that does both Google and Apple notifications. Pushover is likely be using FCM internally. The ES uses an API key to send notifications. That API key maps to zmNinja at the moment. If you want to change it to push to another app, you'll need its push notification key and change the API token in the ES. But that only applies to apps you know the key of, which usually apps you register with Firebase. So in short, if you have no intention to develop any form of client, continue using Pushover because it has its own client with the key.
I searched for a simple alarm plugin and had not found zm-alarm.pl yet, so thanks for the pointer! It does not appear to have logic to handle Isaac's note about the case where you "have the shm file open and zmc restarts", correct?
Not zm-alarm. zmeventnotification.pl does.


Are you receptive to contributions for pushover, ifttt, and other integrations?
In general, contributions are welcome. Note however that I have several hooks you can invoke just after an alarm start, after an alarm ends etc. These can also easily be chained. They can also decide if the ES proceeds with the alarm further or not. So a lot of integrations can simply be done with these hooks instead of changing the core. The core of the ES supports 3 key protocols: web sockets (because its a general control channel), FCM (push notifications to zmNinja) and MQTT (an extremely popular protocol for 3rd party IoT Hub integrations). One would need to deliberate if other delivery mechanisms become part of the core, or part of the hooks.
Also, I notice that my script misses some events because they are maybe firing quicker than the polling loop. So ES may fix this. For example, I have a monitor with 3 zones. I am interested in one particular zone, but I suspect that another zone on that monitor fires first and the one I am interested in may missed by the polling. ES looks like it may handle this case better.
Yes, that is a general problem with SHM as it can get overwritten quickly. That is why the ES also catches alarm end events incase it misses a start.
Yes, the beauty of open source. As noted above, I do intend to clean that up and add my own gists. I did give a shout out to pliablepixels in the docs and code.
It's beautiful when the spirit is carried on properly. It is pretty obvious, at least to me, from your code flow, variable names, comments and function names that you are well aware of the zmeventserver project and have stripped its code down but chose not to attribute that project, instead offering a generic ack towards SHM and alarm guts to the author. A better approach, imho, would simply be to note that you found the ES too much for your needs and you decided to write a stripped down version. Nothing wrong with that and it doesn't decrease the value of your own work. At least that is my interpretation which you may not agree with. I don't plan to address this further, but I felt it was necessary to bring this up the way your repo/comments in this thread were made.
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
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

Re: New Lightweight ZM Instant Event Notify daemon project published

Post by mp_inch »

asker,

My hope was that I could become a contributing member of the zm community of which I had reaped rewards over so many years. I contributed money to the author a long, long time ago, but I have always wanted to contribute code.

Apologies if I am not familiar with the best way to attribute source projects. You can see that I have made public exactly one project, so I am learning the ways of opensource. And I did thank zoneminder and pliable pixels in several places, so I thought I was doing the right thing.
asker wrote: Fri Feb 14, 2020 1:57 pm It's beautiful when the spirit is carried on properly. It is pretty obvious, at least to me, from your code flow, variable names, comments and function names that you are well aware of the zmeventserver project and have stripped its code down but chose not to attribute that project, instead offering a generic ack towards SHM and alarm guts to the author. A better approach, imho, would simply be to note that you found the ES too much for your needs and you decided to write a stripped down version. Nothing wrong with that and it doesn't decrease the value of your own work. At least that is my interpretation which you may not agree with. I don't plan to address this further, but I felt it was necessary to bring this up the way your repo/comments in this thread were made.
Please let me explain why it may be obvious to you that it is the same project, but was not obvious to me.

I did not start with the current code of zmeventserver project. I could not find the exact source or exact link after I hacked on it and decided to use it as my codebase because I downloaded many things to play with.

I remember doing a wget from my Linux box to download a zip from github called zmeventnotification-experimental.zip which contained two files - a README.md and a single zmeventnotification.pl which appeared to only support APNS and websockets and had 880 lines.

When I went back to the readme to find the source project, it did not have a reference to the source project. I looked because I did want to attribute exactly where I got it. I can send you the zip if you want. I was not certain these were the same project because when I was doing google searches trying to find the source project, I recall quickly scanning zmeventnotification and thinking it was different because it was huge and appeared focused the detection side of things.

In hindsight, maybe the convention on github for the zip file is that it was some old experimental branch of zmeventnotification. Maybe it is obvious to more experienced folks, but was not to me.

I appreciate your explanations and will try to learn from them.

I am concerned that you may be judging me as if I was an experienced opensource contributor who should know better, but I am not.

I will try to correct the items you mentioned over the weekend.

Hopefully I can make amends. I definitely did not want to start off on the wrong foot and I am a bit discouraged by this.
asker wrote: Fri Feb 14, 2020 1:57 pm So in short, if you have no intention to develop any form of client, continue using Pushover because it has its own client with the key.
Yes, that was simply my point (that FCM is great for app developers to use but does not not solve the notification needs of a typical end user who wants ifttt or pushover to be triggered). Perhaps there could be a configurable webhook plugin that would meet general needs. I dunno. I will look at the other hooks you mentioned and try to find the best spot. I have already quickened my polling frequency to hopefully catch the misses in the short term.

Thanks,
Mark
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: New Lightweight ZM Instant Event Notify daemon project published

Post by asker »

Fair enough, like I said, I need to say this based on what I saw, as I saw it.
Given I put my thoughts forward, it is your right to respond.

I'm fine with your response (and it was nicely balanced).
I like to speak my mind and move on when both parties have the right intent, which I think is the case there.

Welcome aboard. ZM always has need for good contributions/contributors. Look forward to your work.
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
mp_inch
Posts: 8
Joined: Fri Feb 07, 2020 6:01 pm

Re: New Lightweight ZM Instant Event Notify daemon project published

Post by mp_inch »

I was cleaning up tabs on my browser just now and found the source I originally used...

viewtopic.php?t=23516#p89992

Which points to (as shown in post)

Code: Select all

"https://github.com/pliablepixels/zmeven ... perimental"
It looked like the top level of a project when I visited it. (I can see now it was the experimental tree)

Anyway, mystery solved as for why I thought it was a different project.
===
2005 - 5 crappy BW cameras via coax & capture cards
2012 - 10 USB and IP cameras doing 3-5 fps on slow, overworked system
2019 - 12+ USB/IP/PoE cameras doing 5-20 fps in realtime. AMD 3700X/MSI Meg X570 Unify/Ubuntu 18.04
Post Reply