2014-01-28 21:13:44 +08:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
# While this script is running, it will print out the state of each alarm on the system.
|
|
|
|
# This script is an example of calling external scripts in reaction to a
|
|
|
|
# monitor changing state. Simply replace the print() commands with system(),
|
|
|
|
# for example, to call external scripts.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use ZoneMinder;
|
|
|
|
use Switch;
|
|
|
|
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
my @monitors;
|
2014-04-09 22:34:58 +08:00
|
|
|
my $dbh = zmDbConnect();
|
2018-09-20 01:06:09 +08:00
|
|
|
|
|
|
|
my $sql = "SELECT * FROM Monitors
|
2020-07-11 05:10:33 +08:00
|
|
|
WHERE find_in_set( `Function`, 'Modect,Mocord,Nodect' )".
|
2018-09-20 01:06:09 +08:00
|
|
|
( $Config{ZM_SERVER_ID} ? 'AND ServerId=?' : '' )
|
|
|
|
;
|
|
|
|
|
|
|
|
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() );
|
2014-01-28 21:13:44 +08:00
|
|
|
|
|
|
|
while ( my $monitor = $sth->fetchrow_hashref() ) {
|
|
|
|
push( @monitors, $monitor );
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
foreach my $monitor (@monitors) {
|
2018-09-20 01:06:09 +08:00
|
|
|
# Check shared memory ok
|
|
|
|
if ( !zmMemVerify( $monitor ) ) {
|
|
|
|
zmMemInvalidate( $monitor );
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2014-01-28 21:13:44 +08:00
|
|
|
my $monitorState = zmGetMonitorState($monitor);
|
|
|
|
printState($monitor->{Id}, $monitor->{Name}, $monitorState);
|
|
|
|
}
|
|
|
|
sleep 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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" }
|
|
|
|
}
|
|
|
|
}
|