Zone alarms vs monitor alarms via websocket JSON output
Zone alarms vs monitor alarms via websocket JSON output
Hello;
Using Websockets, is it possible to ascertain which zone within a monitor had an alarm?
I need to know which zone had the alarm within a monitor. Is that possible based on the documentation below?https://zmeventnotification.readthedocs ... opers.html
Thank you!
Using Websockets, is it possible to ascertain which zone within a monitor had an alarm?
I need to know which zone had the alarm within a monitor. Is that possible based on the documentation below?https://zmeventnotification.readthedocs ... opers.html
Thank you!
Re: Zone alarms vs monitor alarms via websocket JSON output
From what I am seeing in the documents, it seems that alarms are associated with monitors generally and no zones specifically. I hope to be proven wrong.
Re: Zone alarms vs monitor alarms via websocket JSON output
In : https://zmeventnotification.readthedocs ... opers.html I am trying to get this JSON to work:
{"event":"control","data":{"type":"filter","monlist":"1,2,4,5,6", "intlist":"0,0,3600,60,0"}}
I only have one monitor up and running now. By mousing over it on the console, the number 4 comes up. So my code reflects that:
When I run the above code it gets stuck at the 3rd send.
Output:
{"reason":"","status":"Success","version":"6.1.27","type":"","event":"auth"}
{"status":"Success","reason":"","event":"control","type":"version","version":"6.1.27"}
ES running in debug mode:
When I hit ctrl C, I get the following errors:
Thank you!
{"event":"control","data":{"type":"filter","monlist":"1,2,4,5,6", "intlist":"0,0,3600,60,0"}}
I only have one monitor up and running now. By mousing over it on the console, the number 4 comes up. So my code reflects that:
Code: Select all
import json
from websocket import create_connection
ws = create_connection("ws://127.0.0.1:9000")
ws.send(json.dumps({"event":"auth","data":{"user":"admin","password":"admin"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"control","data":{"type":"version"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4","intlist":"0"}}))
#ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"1,2,4,5,6", "intlist":"0,0,3600,60,0">
result = ws.recv()
print (result)
ws.close()
Output:
{"reason":"","status":"Success","version":"6.1.27","type":"","event":"auth"}
{"status":"Success","reason":"","event":"control","type":"version","version":"6.1.27"}
ES running in debug mode:
Code: Select all
DBG-2:2021-12-01,15:52:59 PARENT: ----------> Tick START (active forks:0, total forks:2, active hooks: 0 running for:24 min)<--------------
DBG-2:2021-12-01,15:52:59 PARENT: After tick: TOTAL: 1, ES_CONTROL: 1, FCM+WEB: 0, FCM: 0, WEB: 1, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-12-01,15:52:59 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2021-12-01,15:52:59 PARENT: checkEvents() new events found=0
DBG-2:2021-12-01,15:52:59 PARENT: There are 0 new Events to process
DBG-2:2021-12-01,15:52:59 PARENT: ---------->Tick END (active forks:0, total forks:2, active hooks: 0)<--------------
Code: Select all
^CTraceback (most recent call last):
File "soxz.py", line 12, in <module>
result = ws.recv()
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 354, in recv
opcode, data = self.recv_data()
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 377, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 396, in recv_data_frame
frame = self.recv_frame()
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 435, in recv_frame
return self.frame_buffer.recv_frame()
File "/usr/local/lib/python3.8/dist-packages/websocket/_abnf.py", line 337, in recv_frame
self.recv_header()
File "/usr/local/lib/python3.8/dist-packages/websocket/_abnf.py", line 293, in recv_header
header = self.recv_strict(2)
File "/usr/local/lib/python3.8/dist-packages/websocket/_abnf.py", line 372, in recv_strict
bytes_ = self.recv(min(16384, shortage))
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 519, in _recv
return recv(self.sock, bufsize)
File "/usr/local/lib/python3.8/dist-packages/websocket/_socket.py", line 113, in recv
bytes_ = _recv()
File "/usr/local/lib/python3.8/dist-packages/websocket/_socket.py", line 90, in _recv
return sock.recv(bufsize)
KeyboardInterrupt
Re: Zone alarms vs monitor alarms via websocket JSON output
Are you waiting for a reply that will never come?
"There is no response for this request, unless the payload did not have either monlist or intlist."
"There is no response for this request, unless the payload did not have either monlist or intlist."
Re: Zone alarms vs monitor alarms via websocket JSON output
Yes, there is no reply to this json request:
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4","intlist":"0"}}))
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4","intlist":"0"}}))
Code: Select all
import json
from websocket import create_connection
ws = create_connection("ws://127.0.0.1:9000")
ws.send(json.dumps({"event":"auth","data":{"user":"admin","password":"admin"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"control","data":{"type":"version"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4","intlist":"0"}}))
#ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"1,2,4,5,6", "intlist":"0,0,3600,60,0">
result = ws.recv()
print (result)
ws.close()
Re: Zone alarms vs monitor alarms via websocket JSON output
It just hangs.
Re: Zone alarms vs monitor alarms via websocket JSON output
I just thought it might be waiting forever in result = ws.recv() after doing ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4","intlist":"0"}})), and the traceback suggests it was in ws.recv when it was interrupted.
Re: Zone alarms vs monitor alarms via websocket JSON output
@Kitkat Thanks for your input. It is much appreciated. The first two seem to work fine. Just getting monitor information seems to be the problem.
Re: Zone alarms vs monitor alarms via websocket JSON output
@kitkat Interrupted by what I wonder?
I run the following code:
Output:
I only have one monitor running and it is called 4.
I run the following code:
Code: Select all
import json
from websocket import create_connection
ws = create_connection("ws://127.0.0.1:9000")
ws.send(json.dumps({"event":"auth","data":{"user":"admin","password":"admin"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"control","data":{"type":"version"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"escontrol", "data":{"command":"unmute","monitors":[4]}}))
result = ws.recv()
print (result)
ws.close()
Output:
Code: Select all
{"version":"6.1.27","event":"auth","type":"","reason":"","status":"Success"}
{"type":"version","status":"Success","reason":"","version":"6.1.27","event":"control"}
{"request":{"data":{"monitors":[4],"command":"unmute"},"event":"escontrol"},"type":"command","status":"Fail","reason":"NOTCONTROL","event":"escontrol"}
Re: Zone alarms vs monitor alarms via websocket JSON output
You pressing Ctrl+C

I'm kind of shooting in the dark here (not used ws or zme) but it looks in the first case like you're sending a command that doesn't elicit a response ("There is no response for this request.." is from the docs) and then calling ws.recv() which sits there waiting for something to be sent:
Code: Select all
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4","intlist":"0"}}))
#ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"1,2,4,5,6", "intlist":"0,0,3600,60,0">
result = ws.recv()
Code: Select all
^CTraceback (most recent call last):
File "soxz.py", line 12, in <module>
result = ws.recv()
Code: Select all
KeyboardInterrupt
Code: Select all
ws.send(json.dumps({"event":"escontrol", "data":{"command":"unmute","monitors":[4]}}))
result = ws.recv()
print (result)
I'm not really sure what else you'd be expecting to see unless the server sends an alarm or some other self-initiated event whilst it's waiting.
What happens if you send the non-responsive filter message and then, without waiting for a reply to filter and omitting the call to ws.recv(), send another message that does get a response, such as version? If that works then I reckon just drop the call to ws.recv() after the filter command and carry on

The other difference is the #-commented line in the first one, but that'd be a really wild error!
Re: Zone alarms vs monitor alarms via websocket JSON output
Code: Select all
DBG-2:2021-12-02,10:44:29 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:47 min)<--------------
DBG-2:2021-12-02,10:44:29 PARENT: After tick: TOTAL: 1, ES_CONTROL: 1, FCM+WEB: 0, FCM: 0, WEB: 1, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-12-02,10:44:29 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2021-12-02,10:44:29 PARENT: checkEvents() new events found=0
DBG-2:2021-12-02,10:44:29 PARENT: There are 0 new Events to process
DBG-2:2021-12-02,10:44:29 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------
Code: Select all
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4", "intlist":"30"}}))
Code: Select all
ws.send(json.dumps({"event":"escontrol", "data":{"command":"unmute","monitors":[4]}}))
Code: Select all
{"type":"command","status":"Fail","event":"escontrol","request":{"event":"escontrol","data":{"command":"get"}},"reason":"NOTCONTROL"}
Re: Zone alarms vs monitor alarms via websocket JSON output
Code: Select all
harry@harry-HP-Compaq-Pro-4300-SFF-PC:~$ sudo python3 soxx.py
{"event":"auth","reason":"","version":"6.1.27","type":"","status":"Success"}
{"reason":"","event":"control","type":"version","status":"Success","version":"6.1.27"}
--{"event":"alarm","status":"Success","type":"","events":[{"DetectionJson":[],"RulesObject":{},"Name":"1","Cause":"","EventId":"4549","MonitorId":"4"}]}--
{"request":{"event":"escontrol","data":{"command":"get"}},"reason":"NOTCONTROL","event":"escontrol","type":"command","status":"Fail"}

Re: Zone alarms vs monitor alarms via websocket JSON output
Output:
The above output takes several minutes to be triggered. It does not reflect the zone but it does show the monitor ID, which might be enough. If I can get it work faster, that would be huge progress.
Code: Select all
{"status":"Success","type":"","events":[{"MonitorId":"4","EventId":"4560","Cause":"","Name":"1","RulesObject":{},"DetectionJson":[]}],"event":"alarm"}
Code: Select all
import json
from websocket import create_connection
ws = create_connection("ws://127.0.0.1:9000")
ws.send(json.dumps({"event":"auth","data":{"user":"admin","password":"admin"}}))
result = ws.recv()
print (result)
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4", "intlist":"0"}}))
result = ws.recv()
print (result)
ws.close()
Re: Zone alarms vs monitor alarms via websocket JSON output
If I'm right about recv() waiting for a reply that will never come after issuing the filter command then the hang-up is to be expected.The above hangs The below failsCode: Select all
ws.send(json.dumps({"event":"control","data":{"type":"filter","monlist":"4", "intlist":"30"}}))
Output:Code: Select all
ws.send(json.dumps({"event":"escontrol", "data":{"command":"unmute","monitors":[4]}}))
Code: Select all
{"type":"command","status":"Fail","event":"escontrol","request":{"event":"escontrol","data":{"command":"get"}},"reason":"NOTCONTROL"}
As for the Fail response to the unmute command, I wonder... Is the monitor muted and if not, will trying to unmute a not-muted monitor throw an error? Perhaps try muting it first/instead?
When you say "takes several minutes to be triggered," do you mean after the alarm is triggered in ZM?Output:The above output takes several minutes to be triggered. It does not reflect the zone but it does show the monitor ID, which might be enough. If I can get it work faster, that would be huge progress.Code: Select all
{"status":"Success","type":"","events":[{"MonitorId":"4","EventId":"4560","Cause":"","Name":"1","RulesObject":{},"DetectionJson":[]}],"event":"alarm"}
It's not a reply to the filter command, or at least I don't think it is anyway, but an alarm message which could appear at any random time (or never).
Re: Zone alarms vs monitor alarms via websocket JSON output
@Kitkat Zoneminder's web GUI shows an alarm within a reasonable time, and so does the ES, but the websocket output seems to randomly output the alarm.