perl function zmHasAlarmed

Forum for questions and support relating to the 1.24.x releases only.
Locked
digitalm
Posts: 27
Joined: Fri Nov 14, 2008 10:14 am
Location: Poole, UK

perl function zmHasAlarmed

Post by digitalm »

Hi,

I have a script that is based on the example in the FAQ (
http://www.zoneminder.com/wiki/index.php/FAQ )

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 ( !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 );
}
My script is a bit more advanced, so that multiple clients can monitor the status over the network, It used to work fine, but after updating ubuntu on my machine it now works for a while, but then starts getting the error

Use of uninitialized value $last_event_id in numeric ne (!=) at /usr/share/perl5/ZoneMinder/Memory.pm line 497.

The normal script (above) does not seem to have the same problem.

Any ideas why the above error is refering to?

thanks
digitalm
Posts: 27
Joined: Fri Nov 14, 2008 10:14 am
Location: Poole, UK

Post by digitalm »

Looks like this problem has been referenced before :

see

http://www.zoneminder.com/forums/viewto ... 9cdbe8cca6
digitalm
Posts: 27
Joined: Fri Nov 14, 2008 10:14 am
Location: Poole, UK

Post by digitalm »

from looking at

http://www.zoneminder.com/forums/viewto ... hasalarmed

and doing a bit of testing, I think I have fixed it.

where there was

Code: Select all

if ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) )

I have put additional checks in :

Code: Select all

  if ( defined( zmMemRead( $monitor, "shared_data:last_event" )) ) {
                if ( defined( $monitor->{LastEventId} ))
                {
                if ( ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) ) )
                    {
which has fixed the problem.
Locked