Welcome to It-Slav.Net blog
Peter Andersson
peter@it-slav.net

I've already got a female to worry about. Her name is the Enterprise.
-- Kirk, "The Corbomite Maneuver", stardate 1514.0

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

Share

7 Responses to “Using a webcamera to detect motions and send an alarm to Nagios or op5 Monitor”

  1. Warning! Do not buy a Philips Webcam | An It-Slave in the digital saltmine Says:

    […] 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 […]

  2. Toni Says:

    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

  3. peter Says:

    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

  4. Toni Says:

    Ok thanks for the update. I’ve managed to set it up.

    Thanks for the tip! Toni

  5. Randy Says:

    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

  6. peter Says:

    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.

  7. depósito insuficiente | EcoHorta Says:

    […] certo, que motios é quen de pasarlle alertas a nagios… This entry was posted in Sen clasificar and tagged depósito, nagios, […]

Leave a Reply


− two = 6





Book reviews
FreePBX 2.5
Powerful Telephony Solutions






Asterisk 1.6
Build a feature rich telephony system with Asterisk






Learning NAGIOS 3.0





Cacti 0.8 Network Monitoring,
Monitor your network with ease!