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);
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)
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" }
}
}