forked from ZoneMinder/zoneminder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzm-alarm.pl
executable file
·43 lines (35 loc) · 1.31 KB
/
zm-alarm.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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;
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);
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" }
}
}