Accessing Even Server via websockets

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Accessing Even Server via websockets

Post by hahobson »

Reading this page: https://zmeventnotification.readthedocs ... opers.html I am trying to log on to the Event Server using websockets:

Code: Select all

import json
from websocket import create_connection
ws = create_connection("ws://localhost:9000")
#ws.send(json.dumps({"event":"auth","data":{"user":"www-data","password":"23scadoo"}}))
ws.send(json.dumps({"event":"auth","data":{"user":"<www-data>","password":"<23scadoo>"}}))
result =  ws.recv()
print (result)
ws.close()
When running the code, I get:
File "soxw.py", line 3, in <module>
ws = create_connection("ws://192.168.0.104:9000")
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 596, in create_connection
websock.connect(url, **options)
File "/usr/local/lib/python3.8/dist-packages/websocket/_core.py", line 249, in connect
self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
File "/usr/local/lib/python3.8/dist-packages/websocket/_http.py", line 130, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File "/usr/local/lib/python3.8/dist-packages/websocket/_http.py", line 208, in _open_socket
raise err
File "/usr/local/lib/python3.8/dist-packages/websocket/_http.py", line 185, in _open_socket
sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

I have turned off SSL in zmeventnotification.pl
DEFAULT_SSL_ENABLE => 'no',

And in zmeventnotification.ini , I added a password
# the password for accepting control interfaces
#######escontrol_interface_password=!ESCONTROL_INTERFACE_PASSWORD
escontrol_interface_password="23scadoo"

If anyone has any trouble shooting ideas, please let me know. Thank you!
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Accessing Even Server via websockets

Post by kitkat »

Refused typically means that there's either nothing listening or the connection is being otherwise rejected before negotiating SSL and subsequent client authentication.

Is the event server actually running?

Code: Select all

ps -Af | grep zmeventnotification
pgrep -af zm
Is the listening socket open on the local machine?

Code: Select all

netstat -nlutp | grep :9000
netstat -nlutp | grep zm
Firewall blocking the connection?

Code: Select all

iptables -L INPUT -nv
This will allow TCP loopback (localhost) connections to port 9000:

Code: Select all

iptables -I INPUT -s 127.0.0.1/24 -p tcp --dport 9000 -j ACCEPT
This will allow inbound TCP connections to port 9000 from anywhere:

Code: Select all

iptables -I INPUT -p tcp --dport 9000 -j ACCEPT
The docs do say, "You need to open a secure web socket connection to that port from your client" but your changes to the .conf look like they should cover that, although if it didn't work for some reason then maybe you'll have to use SSL and check the cert against a local or self-installed one, or perhaps there's something similar to wget's --no-check-certificate option, but Refused is usually encountered before reaching this point so I'd investigate that first.
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Re: Accessing Even Server via websockets

Post by hahobson »

@kitkat Thanks for your reply.

When I run : ps -Af | grep zmeventnotification
I get:
harry 7357 1407 0 07:02 pts/0 00:00:00 grep --color=auto zmeventnotification

When I run: pgrep -af zm
I get:
1181 /usr/bin/perl -wT /usr/bin/zmdc.pl startup
1214 /usr/bin/zmc -d /dev/video0
1233 /usr/bin/perl -wT /usr/bin/zmwatch.pl
1238 /usr/bin/perl -w /usr/bin/zmtelemetry.pl
1244 /usr/bin/perl -wT /usr/bin/zmstats.pl
1263 /usr/bin/zma -m 4

There is no firewall.

iptables -L INPUT -nv
Output:
0 0 ACCEPT tcp -- * * 127.0.0.0/24 0.0.0.0/0 tcp dpt:9000

I appreciate your input.
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Accessing Even Server via websockets

Post by kitkat »

hahobson wrote: Mon Nov 29, 2021 12:14 am @kitkat Thanks for your reply.

When I run : ps -Af | grep zmeventnotification
I get:
harry 7357 1407 0 07:02 pts/0 00:00:00 grep --color=auto zmeventnotification

When I run: pgrep -af zm
I get:
1181 /usr/bin/perl -wT /usr/bin/zmdc.pl startup
1214 /usr/bin/zmc -d /dev/video0
1233 /usr/bin/perl -wT /usr/bin/zmwatch.pl
1238 /usr/bin/perl -w /usr/bin/zmtelemetry.pl
1244 /usr/bin/perl -wT /usr/bin/zmstats.pl
1263 /usr/bin/zma -m 4

There is no firewall.

iptables -L INPUT -nv
Output:
0 0 ACCEPT tcp -- * * 127.0.0.0/24 0.0.0.0/0 tcp dpt:9000

I appreciate your input.
It doesn't look like it's running - I'd have expected pgrep or ps to have shown the process name and ID of of the zmeventnotification server, and the rest of the zm* processes look like the normal stuff. It might be worth running the commands again with sudo in front if you weren't root or didn't have privileges, just to make sure.

Did the netstat commands show anything listening on port 9000? (And maybe try with sudo)

Have a go at running it manually before trying to start it as a daemon: https://zmeventnotification.readthedocs ... anual-mode

Once it's running you should be able to telnet ip.add.re.ss 9000 and connect, although any commands will fail if SSL is enabled.
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Re: Accessing Even Server via websockets

Post by hahobson »

What I am trying to achieve is the monitoring of individual zones. When there is an event, a streaming is then pointed at that zone. Each monitor can have several zones. Is that achievable? Thank you!
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

Re: Accessing Even Server via websockets

Post by kitkat »

hahobson wrote: Mon Nov 29, 2021 1:25 am What I am trying to achieve is the monitoring of individual zones. When there is an event, a streaming is then pointed at that zone. Each monitor can have several zones. Is that achievable? Thank you!
I've not used the event server and I'm not conversant with its functionality so I don't know - sorry - but I do know that it has to be running and connectable before a client can talk to it.
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Re: Accessing Even Server via websockets

Post by hahobson »

@kitkat, WELL, you were right. It wasn't running. I thought it was. Anyway, I am now getting : {"status":"Fail","event":"auth","type":"","reason":"BADAUTH"}

So I guess it does not like something in this line:
ws.send(json.dumps({"event":"auth","data":{"user":"<www-data>","password":"<23scadoo>"}}))


sudo netstat -nlutp | grep zm output:
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 9415/perl

sudo netstat -nlutp | grep zm No output.

Thank you!
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Re: Accessing Even Server via websockets

Post by hahobson »

@kitkat, I get this from the ES notification output running in debug

Code: Select all

DBG-2:2021-11-29,12:21:47 PARENT: ---------->onConnect msg START<--------------
DBG-3:2021-11-29,12:21:47 PARENT: Raw incoming message: {"event": "auth", "data": {"user": "<www=data>", "password": "<23scadoo>"}}
DBG-1:2021-11-29,12:21:47 PARENT: marking for deletion - bad authentication provided by 127.0.0.1
DBG-2:2021-11-29,12:21:47 PARENT: ---------->onConnect msg END<--------------
DBG-2:2021-11-29,12:21:47 PARENT: ---------->onConnect:disconnect START<--------------
DBG-1:2021-11-29,12:21:47 PARENT: Websocket remotely disconnected from 127.0.0.1
DBG-1:2021-11-29,12:21:47 PARENT: Marking 127.0.0.1 for deletion as websocket closed remotely

DBG-2:2021-11-29,12:21:47 PARENT: ---------->onConnect:disconnect END<--------------
hahobson
Posts: 34
Joined: Mon Jul 19, 2021 8:00 am

Re: Accessing Even Server via websockets

Post by hahobson »

harry@harry-HP-Compaq-Pro-4300-SFF-PC:~$ sudo python3 soxw.py
{"type":"","version":"6.1.27","status":"Success","reason":"","event":"auth"}

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.close()
:roll:

Done
Post Reply