Page 1 of 1
REST API call on Event
Posted: Sat Mar 06, 2021 11:54 pm
by SirLouen
I was wondering if it is possible by any means, to execute a custom REST API call sending some parameters from the Event (like the name or the start_time/end_time) when a new Event is generated.
Re: REST API call on Event
Posted: Sun Mar 07, 2021 7:51 am
by Magic919
Have a look at this
https://zmeventnotification.readthedocs.io/en/latest/ It might do what you want, or something similar.
Re: REST API call on Event
Posted: Sun Mar 07, 2021 3:01 pm
by SirLouen
Magic919 already digged into it, but I feel I won't be able any soon to make it this way
The problem is that i'm not sure i will be able to create a full script just to parse a simple response to my REST API
Also I see that it only handles a couple of meaningless data for me (this piece of software was mostly designed for notification) like Monitor ID and Event and the alarm cause, but no dates for example:
Code: Select all
# This is the script that will send the notification
# Some sample scripts are provided, write your own
# Each script gets:
# arg1 - event ID
# arg2 - Monitor ID
# arg3 - Monitor Name
# arg4 - alarm cause
# arg5 - Type of event (event_start or event_end)
# arg6 (optional) - image path
I simply needed to do a simple POST to my REST API URL sending the Monitor_ID and the Creation date of the Event, nothing more

Re: REST API call on Event
Posted: Sun Mar 07, 2021 4:19 pm
by Magic919
Mine sends alerts using Pushover. It has the monitor ID and seems to assume the time of the event is 'now', which works.
You can see the detail in
Code: Select all
/var/lib/zmeventnotification/bin/pushapi_pushover.py
Re: REST API call on Event
Posted: Sun Mar 07, 2021 4:25 pm
by SirLouen
Yeah Magic919 that is the big issue
For pushover, the creator has integrated a fully featured pushover plugin integration
But for custom API one has to develop a custom plugin which seems not straight forward.
And the docs about how to implement this are completely missing. Personally I only know PHP and SQL, and both the monitor (Pearl) and this script (Python) are outside my scope...
It would be great if I could run a PHP script intead of the python option, but I'm not 100% sure what I should be doing. A simple example would be amazing.
Re: REST API call on Event
Posted: Mon Mar 08, 2021 2:39 am
by asker
Have you read the comments in zmeventnotification.ini?
event_start_hook_notify_userscript
Not sure how much simpler it can get.
Re: REST API call on Event
Posted: Mon Mar 08, 2021 2:43 am
by SirLouen
But I don't understand when you talk about "script", what kind of script are you expecting?
Anything that could be run? Either a bash script, a py script, or a php script?
Or needs something specific?
Also, how can I pass the Event parameters to the script? (monitor ID, event start datetime, etc.)
Re: REST API call on Event
Posted: Mon Mar 08, 2021 12:06 pm
by asker
SirLouen wrote: ↑Mon Mar 08, 2021 2:43 am
But I don't understand when you talk about "script", what kind of script are you expecting?
Anything that could be run? Either a bash script, a py script, or a php script?
Or needs something specific?
Also, how can I pass the Event parameters to the script? (monitor ID, event start datetime, etc.)
A script is a script - as long as it can be run. Shell script, Python script, PHP script whatever. ES invokes whatever you point it to.
What is in it is upto you. In your case, it would likely be a one line shell script that invokes your curl statement with the arguments passed below ($1 $2 $3 etc.)
Take a look at
https://github.com/pliablepixels/zmeven ... er/contrib for examples - it will show you the parameters that are passed.
https://github.com/pliablepixels/zmeven ... py#L17-L29
Code: Select all
# Arguments:
# All scripts invoked with the xxx_userscript tags
# get the following args passed
# ARG1: Hook result - 0 if object was detected, 1 if not.
# Always check this FIRST as the json/text string
# will be empty if this is 1
#
# ARG2: Event ID
# ARG3: Monitor ID
# ARG4: Monitor Name
# ARG5: object detection string
# ARG6: object detection JSON string
# ARG7: event path (if hook_pass_image_path is yes)
So just read the comments, and write your own.
Re: REST API call on Event
Posted: Sat Mar 13, 2021 6:20 pm
by SirLouen
asker wrote: ↑Mon Mar 08, 2021 12:06 pm
A script is a script - as long as it can be run. Shell script, Python script, PHP script whatever. ES invokes whatever you point it to.
What is in it is upto you. In your case, it would likely be a one line shell script that invokes your curl statement with the arguments passed below ($1 $2 $3 etc.)
Take a look at
https://github.com/pliablepixels/zmeven ... er/contrib for examples - it will show you the parameters that are passed.
https://github.com/pliablepixels/zmeven ... py#L17-L29
Code: Select all
# Arguments:
# All scripts invoked with the xxx_userscript tags
# get the following args passed
# ARG1: Hook result - 0 if object was detected, 1 if not.
# Always check this FIRST as the json/text string
# will be empty if this is 1
#
# ARG2: Event ID
# ARG3: Monitor ID
# ARG4: Monitor Name
# ARG5: object detection string
# ARG6: object detection JSON string
# ARG7: event path (if hook_pass_image_path is yes)
So just read the comments, and write your own.
Thanks for the info!
How can I retrieve the start_time and the end_time of the event? Or I shall just consider the "start time" as the time that the script was invoked (
now())
Re: REST API call on Event
Posted: Sat Mar 13, 2021 10:04 pm
by asker
That is not passed as a parameter, so best to go with now()
More details:
1. If you use the start hook, you may not even have an end time (event still recording). If you use the end hook, you can look for the start time and end time
2. As far getting the real values are concerned, read the ZM API documentation - you'll find details on how to get data for a specific event.