Can you make sure your video streams are up with Zabbix? Of course you can! By day, I am a monitoring technical lead in a global cyber security company. By night, I monitor my home with Zabbix & Grafana Labs and do some weird experiments with them. Welcome to my weekly blog about the project.
You might have a surveillance camera at home to record suspicious activities at your yard while you are away or so. Most of the time the cameras do work just fine, but might require a hard reboot from time to time, for example due harsh weather, or not coming back after a network outage. A networked camera responding to ping does not 100% mean the camera is actually functional. I have seen our camera to go black and refusing to connect to its stream even though it thinks it's working just fine.
Zabbix to the rescue!
Connecting to your camera
My post for this week is mostly to maybe give you a new approach for monitoring your cameras, not so much a functional solution as I'm still figuring out how to do this properly.
For example, I can connect to our camera via RTSP protocol and passing some credentials with it, so rtsp://myusername:mypassword@my.camera.address:443/myAddress
To figure out a connection address for your camera model, iSpyConnect has a nice camera database.
Playing the stream
To test if the video stream works, VLC and mplayer are nice options; for visually verifying the stream works, try something like
mplayer 'rtsp://myusername:mypassword@my.camera.address:443/myAddress'
or for those who like to use a GUI, in VLC, File --> Open Network --> enter your camera address
For obvious reasons, I am not pasting here an image from our camera. Anyway, trust me, this method should work if you have a compatible camera.
Let's go next for the neat tricks part, which I'm still figuring out myself, too.
Making sure the stream works
To make sure the video stream is up and running, make your Zabbix server, Zabbix proxy, or a dedicated media server to continuously stream your video feed with for example
mplayer -vo null 'rtsp://myusername:mypassword@my.camera.address:443/myAddress'
Above would make mplayer to play the stream with null video driver; thus, the stream will be continuously played, but just with no visual video output generated. In other words, under perfect conditions, the mplayer process should be running on server all the time. If anything goes wrong with the stream, mplayer quits itself, and the process goes away from the process list, too.
Using Zabbix to check the player status
Now that you have some server continuously playing the stream, it's time to check the status with Zabbix.
From here checking the stream status with Zabbix is simple: just
- create a new item to check if for example mplayer process is around with Zabbix Agent item type and proc.num[,mplayer] key and
- make your Zabbix alert about it if number of mplayer processes is <1
Camera screenshots to your Zabbix user interface
Both mplayer and VLC can be controlled remotely, so here's an idea which I have not yet implemented but testing out.
If a motion sensor, either external unit or camera's built-in sensor, detects movement, make Zabbix to send a command to camera to record a screenshot of the camera stream, or possibly a short video. Then just make the script to save the photo or video in a directory which Zabbix can access and then show with its URL widget type.
mplayer has a slave mode for receiving commands from external programs, which together with a FIFO pipe might just work.
Real-time video stream in your Zabbix user interface
At least VLC can transcode RTSP to HTTP stream in real-time, so in theory then embedding the resulting stream to your Zabbix user interface should very much be doable with a short HTML file and Zabbix URL widget type. This one I did not yet even start to try out, though.
So, that's for my this weeks' blog post. I'm still building this thing out, but if you have successfully done something similar, please let me know!
I have been working at Forcepoint since 2014 and am a true fan of functional testing.
Add new comment