how to call other programs from zoneminder

Forum for questions and support relating to the 1.24.x releases only.
Locked
babuenir
Posts: 1
Joined: Mon Oct 04, 2010 11:42 am
Location: India

how to call other programs from zoneminder

Post by babuenir »

Hello everyone,
I am a newbie to zoneminder and perl. Please help me on calling other programs from the zoneminder. Can I use the following code on this.

Code: Select all

#!/usr/bin/perl -w

use 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 ( !zmMemVerify( $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 );
}
Babu
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

Post by jondecker76 »

Yes, you can modify that example pretty easily. There are a few ways to do this in perl, but the simplest example is

Code: Select all

system("command",  "arg1", "arg 2",...,argN");
For example, if I wanted to call a shell script named "send_email.sh", with the arguments "--subject", "--body" and "--address", it may look like this:

Code: Select all

my $subject="An alarm has triggered!";
my $body="This is ZonMinder. An alarm has triggered and you should check your cameras!";
my $address="whoever@wherever.com";
system("sh send_email.sh",$subject,$body,$address);
Locked