Need Help with Command Line Script

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
jsylvia007
Posts: 116
Joined: Wed Mar 11, 2009 8:32 pm

Need Help with Command Line Script

Post by jsylvia007 »

I have a script (below) that I use to get the status of all the cameras and grep values to insert into Zabbix.

The script has stopped working in 1.32.1, and I believe it has to do with this line:

Code: Select all

my $monitorState = zmGetMonitorState($monitor);
I did a print to see what was contained in $monitor, and the value at that point in the script is:

Code: Select all

HASH(0x56072d4282f0)HASH(0x56072d428bc0)HASH(0x56072d42a8f8)HASH(0x56072d42d9d0)HASH(0x56072d42e2a0)HASH(0x56072d4319d8)HASH(0x56072d4322a8)HASH(0x56072d4352f0)HASH(0x56072d435bc0)HASH(0x56072d438128)HASH(0x56072d4389f8)HASH(0x56072d43bc70)HASH(0x56072d43f178)HASH(0x56072d43fa48)
I'm not sure what that all means... I'm hoping that someone who understands the codebase can tell me what's changed.

Executing the script results in these outputs:

Code: Select all

2018-10-07 14:55:32	getstate	10085	ERR	Can't read from mapped memory for monitor '1', gone away?	getstate.pl	
2018-10-07 14:55:32	getstate	10085	ERR	Unable to read 'shared_data:state' from memory for monitor 1	getstate.pl	
2018-10-07 14:55:31	getstate	10069	ERR	Can't read from mapped memory for monitor '1', gone away?	getstate.pl	
2018-10-07 14:55:31	getstate	10069	ERR	Unable to read 'shared_data:state' from memory for monitor 1	getstate.pl	
2018-10-07 14:55:30	getstate	10053	ERR	Can't read from mapped memory for monitor '1', gone away?	getstate.pl	
2018-10-07 14:55:30	getstate	10053	ERR	Unable to read 'shared_data:state' from memory for monitor 1	getstate.pl

Code: Select all

#!/usr/bin/env perl

use strict;
use warnings;
use ZoneMinder;
use Switch;

$| = 1;

my @monitors;
my $dbh = zmDbConnect();
my $sql = "SELECT * FROM Monitors";
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() );

while ( my $monitor = $sth->fetchrow_hashref() ) {
    push( @monitors, $monitor );
}

while (1) {
        foreach my $monitor (@monitors) {
                my $monitorState = zmGetMonitorState($monitor);
                printStateSimple($monitor->{Id}, $monitor->{Name}, $monitorState);
        }
#        sleep 1;
         exit
}

sub printState {
        my ($monitor_id, $monitor_name, $state) = @_;
        my $time = localtime();

        switch ($state) {
                case 0 { print "$time - $monitor_name:\t Idle!\n" }
                case 1 { print "$time - $monitor_name:\t Prealarm!\n" }
                case 2 { print "$time - $monitor_name:\t Alarm!\n" }
                case 3 { print "$time - $monitor_name:\t Alert!\n" }
        }
}

sub printStateSimple {
        my ($monitor_id, $monitor_name, $state) = @_;
        my $time = localtime();

        switch ($state) {
                case 0 { print "$monitor_name ($monitor_id):\t Idle\n" }
                case 1 { print "$monitor_name ($monitor_id):\t Prealarm\n" }
                case 2 { print "$monitor_name ($monitor_id):\t Alarm\n" }
                case 3 { print "$monitor_name ($monitor_id):\t Alert\n" }
        }
}
Last edited by jsylvia007 on Sun Oct 07, 2018 10:23 pm, edited 2 times in total.
Post Reply