Changes

Talk:ZoneMinder CCTV Camera Monitoring Software

1,933 bytes added, 01:26, 28 April 2008
variables and arrays
The following lines were added (+) and removed (-):
mplayer /usr/share/zoneminder/www/sounds/redalert.wav== How can I use ZoneMinder to trigger something else when there is an alarm? ==ZoneMinder includes a perl API which means you can create a script to interact with the ZM shared memory data and use it in your own scripts to react to ZM alarms or to trigger ZM to generate new alarms. Full details are in the README or by doing 'perdoc ZoneMinder', 'perldoc ZoneMinder::SharedMem' etc.Below is an example script that checks all monitors for alarms and when one occurs, prints a message to the screen. You can add in your own code to make this reaction a little more useful.<pre>#!/usr/bin/perl -wuse strict;use ZoneMinder;$| = 1;zmDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );my @monitors;while ( my $monitor = $sth->fetchrow_hashref() ){    push( @monitors, $monitor );}while( 1 ){    foreach my $monitor ( @monitors )    {        next if ( !zmShmVerify( $monitor ) );         if ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) )        {            $monitor->{LastEventId} = $last_event_id;            print( "Monitor ".$monitor->{Name}." has alarmed\n" );            #            # Do your stuff here            #        }    }    sleep( 1 );}</pre>== variables and arrays == $monitor->{Id} $monitor->{Device} $monitor->{Name} $monitor->{MaxFPS} $monitor->{Function} $event->{Id} $event->{MonitorId} $event->{MonitorHeight} $event->{MonitorWidth}
Bureaucrat, administrator
16,195
edits