I'd like to try and do a few things using the "perl API" starting with the sample script shown in the FAQ at the Wiki, but don't know how to get started with it.
I'm not a Perl person but hope I can quickly learn enough about the shared memory layout to access it in "C" although I suspect I can do what I want in Perl too once I go up its learning curve a bit.
Assume I've cut and pasted the sample script into an xxx.pl file and made it executable by the www-data user, how do I get it to run when the desired "run state" is in effect? Where do I put it?
Its very frustrating that the Wiki is not accurate for the 1.24.2 release, for example "perldoc ZoneMinder::SharedMem" is incorrect now and gives an error. Doing "perldoc ZoneMinder::Memory" appears to be what does it now.
Using the sample perl script from the FAQ?
Using the sample perl script from the FAQ?
Your commitment to Freedom is measured by your tolerance of others doing things you disapprove.
If we are talking about the same Perl script, I have had to change "zmShmVerify" and add am additional line. So the new script looks like this
I don't know much about Perl, I have found these changes searching the forum. to run it "sudo perl script.pl. I'm currently trying to figure out how to narrow this script down to a particular monitor. Hope this helps.
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 (E.MonitorId)";
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 ( defined( zmMemRead( $monitor, "shared_data:last_event" )) ) {
if ( !defined( $monitor->{LastEventId} ) || ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) ) )
{
$monitor->{LastEventId} = $last_event_id;
print( "Monitor ".$monitor->{Name}." has alarmed\n" );
#
# Do your stuff here
#
system("x10cmd rf b2 on")
}
}
}
sleep( 1 );
}
different script actions per monitor
have you figured out how to launch different script actions based on which monitor was tripped?