Apr
Background
This article describe howto use a USB camera (also known as webcam) to detect motions and send an alarm to Nagios or op5 Monitor. It can be used in datacenters to send an alert if someone or something is moving or at home to detect if someone is in your house. I will place the camera just inside the door so everybody passing my front door will be filmed and an alert will be sent to me.
The software used:
- Motion, to detect movement and create a movie of the relevant time, pictures is also taken.
- Nagios or op5 Monitor to create the alarm.
The hardware used is an old Logitech webcam I found in my fathers drawer 😉 Motion supports alot of different devices but must simple is to use a video4linux supported device.
The pre req. for this article is a working Nagios or op5 Monitor system.
Installation
I have an Ubuntu system where I attach the webcamera, dmesg gives me:
[634581.861029] usb 1-2: new full speed USB device using uhci_hcd and address 3 [634582.032251] usb 1-2: configuration #1 chosen from 1 choice [634582.034125] quickcam: QuickCam USB camera found (driver version QuickCam USB 0.6.6 $Date: 2006/11/04 08:38:14 $) [634582.034144] quickcam: Kernel:2.6.27-11-generic bus:1 class:FF subclass:FF vendor:046D product:0870 [634582.048202] quickcam: Sensor HDCS-1020 detected [634582.050173] quickcam: Registered device: /dev/video0
Installing motion is simple, just run:
sudo apt-get install motion
I will use passive checks to let motion send in alerts to Nagios, the best way of doing that is by using NSCA, for theory refer to an earlier article.
sudo apt-get install nsca
Test motion
The first thing to test is that motion works, for me to get it to work I needed no configuration, run:
sudo motion
and dance in front of your camera.
Now motion should inform that it has created pictures and a movie.
Configuration
Configure Nagios or op5 Monitor to accept alerts sent from motion:
# service 'Camera Motion Detection' define service{ use default-service host_name lala service_description Camera Motion Detection check_command check_dummy!0 "No motion detected" max_check_attempts 1 active_checks_enabled 0 flap_detection_options n contact_groups it-slav_msn,it-slav_mail,call_it-slav stalking_options n check_freshness 1 freshness_threshold 3600 }
If nothing has been sent within an hour (3600 seconds), the state is set to OK by using freshness and check_dummy.
Create /home/motion/scripts/check_camera_motion/send_nsca.cfg
encryption_method=0
Create /home/motion/scripts/check_camera_motion/passive_camera_warning
lala Camera Motion Detection 1 WARNING: Motion detected
The separator must be TAB
In /etc/motion/motion.conf, find the parameter on_event_start and change it to:
on_event_start cd /home/motion/scripts/check_camera&&send_nsca -H op5.mynet -c send_nsca.cfg < passive_camera_warning
And an alert will be sent to Nagios everytime motion detects a motion.
Start motion with:
sudo motion
And do the dancing again, now you should have an Nagios alarm with status WARNING.
Hint
A good idea could be to change the parameters target_dir and snapshot_filename to a directory where you can point apache websever, so you can use a webbrowser to browse your images and movies.
Links
- Motion, the software used to detect motions
- Nagios
- op5 Monitor, a supported version of Nagios
May 14th, 2009 at 7:34 pm
[…] SNMP on Ubuntu (1051)Create Cacti or op5 Statistics graphs with op5 VmWare ESX3 plugin (906)Using a webcamera to detect motions and send an alarm to Nagios or op5 Monitor (596)HowTo using passive checks with Nagios or op5 Monitor (544)Send Nagios or op5 Monitor […]
March 1st, 2010 at 10:43 pm
Hi there,
I’ve tried to setup motion and a nagios service as described.
It seems you uses /home/motion/scripts/check_camera. I don’t have it and can’t find it. What’s the code inside this file? Is it your own brew or something that comes with motion?
Thanks
Toni
March 1st, 2010 at 10:59 pm
I will update my article:
on_event_start /home/motion/scripts/check_camera&&send_nsca -H op5.mynet -c send_nsca.cfg < passive_camera_warning should be: on_event_start cd /home/motion/scripts/check_camera&&send_nsca -H op5.mynet -c send_nsca.cfg < passive_camera_warning
March 2nd, 2010 at 2:01 pm
Ok thanks for the update. I’ve managed to set it up.
Thanks for the tip! Toni
September 11th, 2010 at 2:04 pm
I had a few questions. I’m new to Nagios and Centos..
In
“on_event_start cd /home/motion/scripts/check_camera&&send_nsca -H op5.mynet -c send_nsca.cfg < passive_camera_warning"
What is op5.mynet? I am using Nagios 3.x
Also if you happen to know how would I configure the snaps/video to work with apache under Centos 5.5. I want to be able to see the snaps through the nagios portal as you mentioned in your tip.
Thanks
September 11th, 2010 at 6:14 pm
op5.mynet is the host that runs op5 Monitor or Nagios.
No I did not write that you could see the snaps through the Nagios portal, that means that you must change the cgi’s and that is horrible in Nagios. Read the documentation for Motion is my hint.
April 9th, 2011 at 1:29 pm
[…] certo, que motios é quen de pasarlle alertas a nagios… This entry was posted in Sen clasificar and tagged depósito, nagios, […]