#!/usr/bin/perl -w # -*- perl -*- # # ========================================================================== # # ZoneMinder Monitoring Plugin for Munin # Copyright (C) 2008 Christophe Nowicki # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ========================================================================== # =head1 NAME zm_hourly_events - Munin plugin to monitor the number of events per hour on an Zondminder CCTV system. =head1 APPLICABLE SYSTEMS Zondminder =head1 CONFIGURATION The plugin needs read access on zm.conf file. This configuration section shows the defaults of the plugin: [zm_*] user www-data group www-data To monitor a camera, link zm_hourly_events_ to this file. E.g. ln -s /usr/share/munin/plugins/zm_hourly_events /etc/munin/node.d/zm_hourly_events_1 ...will monitor camera with id 1. =head1 INTERPRETATION The plugin shows the number of frames per seconds on every camera. =head1 MAGIC MARKERS #%# family=auto #%# capabilities=autoconf suggest =head1 BUGS =head1 VERSION $Id$ =head1 AUTHOR Christophe 'CSCMEU' Nowicki =head1 LICENSE GPLv2 =cut use strict; # Autoconf, in BEGIN in order to avoid use ZoneMinder BEGIN { use constant CONFIG_FILE => "/etc/zm.conf"; if ($ARGV[0] and $ARGV[0] eq "autoconf") { if (-e CONFIG_FILE) { print "yes\n"; exit 0; } else { print "no (no " . CONFIG_FILE . ")\n"; exit 1; } } } use ZoneMinder::Database qw(:all); $0 =~ /zm_hourly_events_(.+)*$/; my $monitor_id = $1; my $dbh = zmDbConnect(); # Config if ($ARGV[0] and $ARGV[0] eq "config") { my $sql1 = "select Id,Name from Monitors"; $sql1 .= ' where Id=' . $monitor_id if ($monitor_id); my $sth1 = $dbh->prepare_cached( $sql1 ) or Fatal( "Can't prepare '$sql1': ".$dbh->errstr() ); my $res = $sth1->execute() or Fatal( "Can't execute: ".$sth1->errstr() ); if (!$monitor_id) { print "graph_title Zoneminder events\n"; print "graph_info The number of events catched by your CCTV system.\n"; } print "graph_scale no\n"; print "graph_vlabel events/\${graph_period}\n"; print "graph_category zoneminder\n"; while( my $monitor = $sth1->fetchrow_hashref() ) { if ($monitor_id) { print "graph_title Zoneminder events on Monitor '" . $monitor->{Name} . "'.\n"; print "graph_info The number of events catched on Monitor '" . $monitor->{Name} . "'.\n"; } print $monitor->{Id} . ".label " . $monitor->{Name} . "\n"; print $monitor->{Id} . ".info The number of events catched on Monitor '" . $monitor->{Name} . "'.\n"; print $monitor->{Id} . ".type DERIVE\n"; print $monitor->{Id} . ".min 0\n"; } exit 0; } # Suggest if ($ARGV[0] and $ARGV[0] eq "suggest") { my $sql1 = "select Name from Monitors order by Id"; my $sth1 = $dbh->prepare_cached( $sql1 ) or Fatal( "Can't prepare '$sql1': ".$dbh->errstr() ); my $res = $sth1->execute() or Fatal( "Can't execute: ".$sth1->errstr() ); while( my $monitor = $sth1->fetchrow_hashref() ) { print $monitor->{Id} . "\n"; } exit 0; } # Update my $sql1 = "SELECT Monitors.Id AS MonitorId,COUNT(Events.Id) AS Count FROM Monitors LEFT JOIN Events ON Monitors.Id=Events.MonitorId WHERE StartTime >= DATE_SUB(NOW(), INTERVAL 1 HOUR)"; $sql1 .= ' AND Monitors.Id=' . $monitor_id if ($monitor_id); $sql1 .= ' GROUP BY Monitors.Id'; my $sth1 = $dbh->prepare_cached( $sql1 ) or Fatal( "Can't prepare '$sql1': ".$dbh->errstr() ); my $res = $sth1->execute() or Fatal( "Can't execute: ".$sth1->errstr() ); while( my $monitor = $sth1->fetchrow_hashref() ) { print $monitor->{MonitorId} . ".value " . $monitor->{Count} . "\n"; } # vim:syntax=perl