Webhooks or calling scripts upon alarm (like X10 Output Alarm)

Anything you want added or changed in future versions of ZoneMinder? Post here and there's a chance it will get in! Search to make sure it hasn't already been requested.
Post Reply
MartinGoodwell
Posts: 6
Joined: Mon Sep 11, 2017 7:40 am

Webhooks or calling scripts upon alarm (like X10 Output Alarm)

Post by MartinGoodwell »

In case of an alarm, I'd love ZM to call a pre-defined webhook.
Once the alarm is over, another webhook is called.

I browsed the code-base real quick but I didn't find, where X10 actions are actually triggered, based on alarms.
So, if someone could point me into the right direction, I'd be perfectly fine with doing a Pull-Request.

From a configuration perspective, this should be pretty similar to X10 actions:
In monitor settings, you can provide two webhooks.
One for alarm start and one for alarm end.

To make this even more generic, calling a script upon entering and leaving alarm states would also be an option.
The script can then do the according requests (ie calling the webhook) or whatever you see fit.

My main concern of interest is actively pushing alarm state changes to FHEM (https://fhem.de/).
While there are workarounds, they are all based on polling ZM, which is not my favorite approach, especially given that pushing alarm states seems to be already implemented for X10.

In the docs, this could look similar to this:
This option controls how ZoneMinder emits webhook calls when the current monitor goes into the alarm state.
Examples:
http://localhost/alarm_on.php
http://localhost/alarm.php?state=on

Thanks anyone for pointing me into the right direction!
MartinGoodwell
Posts: 6
Joined: Mon Sep 11, 2017 7:40 am

Re: Webhooks or calling scripts upon alarm (like X10 Output Alarm)

Post by MartinGoodwell »

I digged through the source code at GitHub, and found the method createEvent
https://github.com/ZoneMinder/ZoneMinde ... al.pm#L313

That seems to be the method that actually writes the database entry when a new event happens (ie an alarm is triggered)
So, instead of permanently querying the Event table, I think it would be better from a performance perspective to actively trigger a shell command or webhook after this method has been executed.
That would allow to hand over an eventId and any other event information to the shell/hook.

Here's the catch:
I wasn't able to find the place where createEvent is called.

So, again, if anyone was able to give some hints, I'd really appreciate it!

Thanks,
Martin
Post Reply