zmMemVerify always false in script (see FAQ)

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

zmMemVerify always false in script (see FAQ)

Post by digitalm »

Hi All,

Just upgraded to ZoneMinder 1.25 and my perl script which checks if monitors have alarmed no longer works.

using the example from the 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 ( !zmMemVerify( $monitor ) );
      
        print( "Checking Monitor ".$monitor->{Name}."\n" );

        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 );
}
First issue is zmDbgInit no longer exists, I commented this out and all seems to be ok.

Second issue is zmMemVerify is always false so it never actually checks if its alarms, if I comment that line out I get the following error :

Code: Select all

Use of uninitialized value $state in numeric eq (==) at /usr/share/perl5/ZoneMinder/Memory.pm line 497.
Use of uninitialized value $state in numeric eq (==) at /usr/share/perl5/ZoneMinder/Memory.pm line 497.
Use of uninitialized value $last_event_id in numeric ne (!=) at /usr/share/perl5/ZoneMinder/Memory.pm line 501.
Use of uninitialized value $last_event in numeric ne (!=) at /usr/share/perl5/ZoneMinder/Memory.pm line 501.
Someone else asked this recently and didn't get an answer - http://www.zoneminder.com/forums/viewto ... mMemVerify

Any ideas?

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

Re: zmMemVerify always false in script (see FAQ)

Post by digitalm »

Just noticed in syslog there is

Code: Select all

Jan  9 17:17:23 video-server zm_watch[8723]: ERR [Shared data size conflict in shared_data for monitor FrontDrive, expected 328, got 316]
so i assume this is the cause?
digitalm
Posts: 27
Joined: Fri Nov 14, 2008 10:14 am
Location: Poole, UK

Re: zmMemVerify always false in script (see FAQ)

Post by digitalm »

Ok fixed it myself, first thing to fix Shared data size conflict I did the fix said here

http://lachlanmiskin.com/blog/2012/06/2 ... r-monitor/

then in the code I changed

Code: Select all

next if ( !zmMemVerify( $monitor ) );

Code: Select all

if ( zmMemVerify( $monitor ) && zmMemRead( $monitor, "shared_data:valid" ) )
{

blah..


}
Locked