2005-12-16 18:05:29 +08:00
|
|
|
#!/usr/bin/perl -wT
|
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# ZoneMinder External Trigger Script, $Date$, $Revision$
|
2006-01-17 19:32:47 +08:00
|
|
|
# Copyright (C) 2003, 2004, 2005, 2006 Philip Coombes
|
2005-12-16 18:05:29 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
2005-12-23 19:34:54 +08:00
|
|
|
# This script is used to trigger and cancel alarms from external connections
|
2005-12-16 18:05:29 +08:00
|
|
|
# using an arbitrary text based format
|
|
|
|
#
|
|
|
|
use strict;
|
|
|
|
use bytes;
|
|
|
|
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# User config
|
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
|
2005-12-16 21:16:37 +08:00
|
|
|
use constant DBG_ID => "zmtrigger"; # Tag that appears in debug to identify source
|
2008-01-14 02:17:42 +08:00
|
|
|
use constant DBG_LEVEL => 0; # 0 is errors, warnings and info only, > 0 for debug
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2005-12-16 21:16:37 +08:00
|
|
|
use constant MAX_CONNECT_DELAY => 10;
|
2005-12-23 19:34:54 +08:00
|
|
|
use constant MONITOR_RELOAD_INTERVAL => 300;
|
2005-12-27 06:46:03 +08:00
|
|
|
use constant SELECT_TIMEOUT => 0.25;
|
2005-12-16 21:16:37 +08:00
|
|
|
|
2005-12-27 07:11:27 +08:00
|
|
|
use ZoneMinder::Trigger::Channel::Inet;
|
|
|
|
use ZoneMinder::Trigger::Channel::Unix;
|
|
|
|
use ZoneMinder::Trigger::Channel::Serial;
|
|
|
|
use ZoneMinder::Trigger::Connection;
|
2005-12-27 06:46:03 +08:00
|
|
|
|
|
|
|
my @connections;
|
2005-12-27 07:11:27 +08:00
|
|
|
push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan1", channel=>ZoneMinder::Trigger::Channel::Inet->new( port=>6802 ), mode=>"rw" ) );
|
|
|
|
push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan2", channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>'/tmp/test.sock' ), mode=>"rw" ) );
|
|
|
|
#push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan3", channel=>ZoneMinder::Trigger::Channel::File->new( path=>'/tmp/zmtrigger.out' ), mode=>"w" ) );
|
|
|
|
push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan4", channel=>ZoneMinder::Trigger::Channel::Serial->new( path=>'/dev/ttyS0' ), mode=>"rw" ) );
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# Don't change anything from here on down
|
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
|
|
|
|
use ZoneMinder;
|
|
|
|
use DBI;
|
2005-12-27 07:11:27 +08:00
|
|
|
#use Socket;
|
2005-12-16 18:05:29 +08:00
|
|
|
use Data::Dumper;
|
2006-11-17 03:08:04 +08:00
|
|
|
use POSIX qw( EINTR );
|
2006-11-16 19:32:56 +08:00
|
|
|
use Time::HiRes qw( usleep );
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
$ENV{PATH} = '/bin:/usr/bin';
|
|
|
|
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
|
|
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
|
|
|
|
2006-01-12 07:55:22 +08:00
|
|
|
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
2006-07-04 18:34:21 +08:00
|
|
|
zmDbgSetSignal();
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2005-12-16 21:36:24 +08:00
|
|
|
Info( "Trigger daemon starting\n" );
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2007-09-07 23:39:44 +08:00
|
|
|
my $dbh = zmDbConnect();
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
my $base_rin = '';
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $connection ( @connections )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
Info( "Opening connection '$connection->{name}'\n" );
|
|
|
|
$connection->open();
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
|
2005-12-27 06:46:03 +08:00
|
|
|
my @in_select_connections = grep { $_->input() && $_->selectable() } @connections;
|
|
|
|
my @in_poll_connections = grep { $_->input() && !$_->selectable() } @connections;
|
|
|
|
my @out_connections = grep { $_->output() } @connections;
|
2005-12-23 19:34:54 +08:00
|
|
|
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $connection ( @in_select_connections )
|
2005-12-23 19:34:54 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
vec( $base_rin, $connection->fileno(), 1 ) = 1;
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
|
|
|
|
2005-12-27 06:46:03 +08:00
|
|
|
my %spawned_connections;
|
2005-12-23 19:34:54 +08:00
|
|
|
my %monitors;
|
|
|
|
|
|
|
|
my $monitor_reload_time = 0;
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
$! = undef;
|
|
|
|
my $rin = '';
|
|
|
|
my $win = $rin;
|
|
|
|
my $ein = $win;
|
2005-12-27 06:46:03 +08:00
|
|
|
my $timeout = SELECT_TIMEOUT;
|
2005-12-16 18:05:29 +08:00
|
|
|
my %actions;
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
$rin = $base_rin;
|
2005-12-27 06:46:03 +08:00
|
|
|
# Add the file descriptors of any spawned connections
|
|
|
|
foreach my $fileno ( keys(%spawned_connections) )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
vec( $rin, $fileno, 1 ) = 1;
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
|
2005-12-16 18:05:29 +08:00
|
|
|
my $nfound = select( my $rout = $rin, undef, my $eout = $ein, $timeout );
|
|
|
|
if ( $nfound > 0 )
|
|
|
|
{
|
2005-12-23 19:34:54 +08:00
|
|
|
Debug( "Got input from $nfound connections\n" );
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $connection ( @in_select_connections )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
if ( vec( $rout, $connection->fileno(), 1 ) )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
Debug( "Got input from connection ".$connection->name()." (".$connection->fileno().")\n" );
|
|
|
|
if ( $connection->spawns() )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
my $new_connection = $connection->accept();
|
|
|
|
$spawned_connections{$new_connection->fileno()} = $new_connection;
|
|
|
|
Debug( "Added new spawned connection (".$new_connection->fileno()."), ".int(keys(%spawned_connections))." spawned connections\n" );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
my $messages = $connection->getMessages();
|
|
|
|
if ( defined($messages) )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $message ( @$messages )
|
|
|
|
{
|
|
|
|
handleMessage( $connection, $message );
|
|
|
|
}
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $connection ( values(%spawned_connections) )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
if ( vec( $rout, $connection->fileno(), 1 ) )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
Debug( "Got input from spawned connection ".$connection->name()." (".$connection->fileno().")\n" );
|
|
|
|
my $messages = $connection->getMessages();
|
|
|
|
if ( defined($messages) )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $message ( @$messages )
|
|
|
|
{
|
|
|
|
handleMessage( $connection, $message );
|
|
|
|
}
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
delete( $spawned_connections{$connection->fileno()} );
|
|
|
|
Debug( "Removed spawned connection (".$connection->fileno()."), ".int(keys(%spawned_connections))." spawned connections\n" );
|
|
|
|
$connection->close();
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ( $nfound < 0 )
|
|
|
|
{
|
|
|
|
if ( $! == EINTR )
|
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
# Do nothing
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-04 18:34:21 +08:00
|
|
|
Fatal( "Can't select: $!" );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
|
|
|
|
# Check polled connections
|
|
|
|
foreach my $connection ( @in_poll_connections )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
my $messages = $connection->getMessages();
|
|
|
|
if ( defined($messages) )
|
2005-12-23 19:34:54 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
foreach my $message ( @$messages )
|
|
|
|
{
|
|
|
|
handleMessage( $connection, $message );
|
|
|
|
}
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
}
|
2005-12-23 19:34:54 +08:00
|
|
|
|
2005-12-27 06:46:03 +08:00
|
|
|
# Check for alarms that might have happened
|
|
|
|
my @out_messages;
|
|
|
|
foreach my $monitor ( values(%monitors) )
|
|
|
|
{
|
|
|
|
my ( $state, $last_event ) = zmShmRead( $monitor, [ "shared_data:state", "shared_data:last_event" ] );
|
2005-12-23 19:34:54 +08:00
|
|
|
|
2005-12-27 06:46:03 +08:00
|
|
|
#print( "$monitor->{Id}: S:$state, LE:$last_event\n" );
|
|
|
|
#print( "$monitor->{Id}: mS:$monitor->{LastState}, mLE:$monitor->{LastEvent}\n" );
|
|
|
|
if ( $state == STATE_ALARM || $state == STATE_ALERT ) # In alarm state
|
|
|
|
{
|
|
|
|
if ( !defined($monitor->{LastEvent}) || ($last_event != $monitor->{LastEvent}) ) # A new event
|
2005-12-23 19:34:54 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
else # The same one as last time, so ignore it
|
2005-12-23 19:34:54 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
# Do nothing
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
elsif ( $state == STATE_IDLE && $monitor->{LastState} > STATE_IDLE ) # Out of alarm state
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
|
|
|
|
}
|
|
|
|
elsif ( defined($monitor->{LastEvent}) && ($last_event != $monitor->{LastEvent}) ) # We've missed a whole event
|
|
|
|
{
|
|
|
|
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
|
|
|
|
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
|
|
|
|
}
|
|
|
|
$monitor->{LastState} = $state;
|
|
|
|
$monitor->{LastEvent} = $last_event;
|
|
|
|
}
|
|
|
|
foreach my $connection ( @out_connections )
|
|
|
|
{
|
|
|
|
if ( $connection->canWrite() )
|
|
|
|
{
|
|
|
|
$connection->putMessages( \@out_messages );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $connection ( values(%spawned_connections) )
|
|
|
|
{
|
|
|
|
if ( $connection->canWrite() )
|
|
|
|
{
|
|
|
|
$connection->putMessages( \@out_messages );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( "Checking for timed actions\n" ) if ( int(keys(%actions)) );
|
|
|
|
my $now = time();
|
|
|
|
foreach my $action_time ( sort( grep { $_ < $now } keys( %actions ) ) )
|
|
|
|
{
|
|
|
|
Info( "Found actions expiring at $action_time\n" );
|
|
|
|
foreach my $action ( @{$actions{$action_time}} )
|
|
|
|
{
|
|
|
|
my $connection = $action->{connection};
|
|
|
|
my $message = $action->{message};
|
|
|
|
Info( "Found action '$message'\n" );
|
|
|
|
handleMessage( $connection, $message );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
delete( $actions{$action_time} );
|
|
|
|
}
|
|
|
|
|
2006-11-16 19:32:56 +08:00
|
|
|
# Allow connections to do their own timed actions
|
|
|
|
foreach my $connection ( @connections )
|
|
|
|
{
|
|
|
|
my $messages = $connection->timedActions();
|
|
|
|
if ( defined($messages) )
|
|
|
|
{
|
|
|
|
foreach my $message ( @$messages )
|
|
|
|
{
|
|
|
|
handleMessage( $connection, $message );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $connection ( values(%spawned_connections) )
|
|
|
|
{
|
|
|
|
my $messages = $connection->timedActions();
|
|
|
|
if ( defined($messages) )
|
|
|
|
{
|
|
|
|
foreach my $message ( @$messages )
|
|
|
|
{
|
|
|
|
handleMessage( $connection, $message );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-27 06:46:03 +08:00
|
|
|
# If necessary reload monitors
|
|
|
|
if ( (time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL )
|
|
|
|
{
|
|
|
|
loadMonitors();
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
}
|
2005-12-16 20:17:10 +08:00
|
|
|
Info( "Trigger daemon exiting\n" );
|
2005-12-23 19:34:54 +08:00
|
|
|
exit;
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2005-12-23 19:34:54 +08:00
|
|
|
sub loadMonitors
|
|
|
|
{
|
|
|
|
Debug( "Loading monitors\n" );
|
2005-12-27 06:46:03 +08:00
|
|
|
$monitor_reload_time = time();
|
|
|
|
|
2005-12-23 19:34:54 +08:00
|
|
|
my %new_monitors = ();
|
|
|
|
|
|
|
|
my $sql = "select * from Monitors where find_in_set( Function, 'Modect,Mocord,Nodect' )";
|
|
|
|
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
|
|
|
my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() );
|
|
|
|
while( my $monitor = $sth->fetchrow_hashref() )
|
|
|
|
{
|
2006-01-12 07:55:22 +08:00
|
|
|
next if ( !zmShmVerify( $monitor ) ); # Check shared memory ok
|
2005-12-23 19:34:54 +08:00
|
|
|
|
|
|
|
if ( defined($monitors{$monitor->{Id}}->{LastState}) )
|
|
|
|
{
|
|
|
|
$monitor->{LastState} = $monitors{$monitor->{Id}}->{LastState};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$monitor->{LastState} = zmGetMonitorState( $monitor );
|
|
|
|
}
|
|
|
|
if ( defined($monitors{$monitor->{Id}}->{LastEvent}) )
|
|
|
|
{
|
|
|
|
$monitor->{LastEvent} = $monitors{$monitor->{Id}}->{LastEvent};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$monitor->{LastEvent} = zmGetLastEvent( $monitor );
|
|
|
|
}
|
|
|
|
$new_monitors{$monitor->{Id}} = $monitor;
|
|
|
|
}
|
|
|
|
%monitors = %new_monitors;
|
|
|
|
}
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2005-12-23 19:34:54 +08:00
|
|
|
sub handleMessage
|
|
|
|
{
|
2005-12-27 06:46:03 +08:00
|
|
|
my $connection = shift;
|
2005-12-23 19:34:54 +08:00
|
|
|
my $message = shift;
|
|
|
|
|
|
|
|
my ( $id, $action, $score, $cause, $text, $showtext ) = split( /\|/, $message );
|
|
|
|
$score = 0 if ( !defined($score) );
|
|
|
|
$cause = "" if ( !defined($cause) );
|
|
|
|
$text = "" if ( !defined($text) );
|
|
|
|
|
|
|
|
my $monitor = $monitors{$id};
|
|
|
|
if ( !$monitor )
|
|
|
|
{
|
|
|
|
Warning( "Can't find monitor '$id' for message '$message'\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Debug( "Found monitor for id '$id'\n" );
|
|
|
|
|
2006-01-12 07:55:22 +08:00
|
|
|
next if ( !zmShmVerify( $monitor ) );
|
2005-12-23 19:34:54 +08:00
|
|
|
|
|
|
|
Debug( "Handling action '$action'\n" );
|
|
|
|
if ( $action =~ /^(enable|disable)(?:\+(\d+))?$/ )
|
|
|
|
{
|
|
|
|
my $state = $1;
|
|
|
|
my $delay = $2;
|
|
|
|
if ( $state eq "enable" )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-23 19:34:54 +08:00
|
|
|
zmMonitorEnable( $monitor );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2005-12-23 19:34:54 +08:00
|
|
|
else
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-23 19:34:54 +08:00
|
|
|
zmMonitorDisable( $monitor );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2005-12-23 19:34:54 +08:00
|
|
|
# Force a reload
|
|
|
|
$monitor_reload_time = 0;
|
|
|
|
Info( "Set monitor to $state\n" );
|
|
|
|
if ( $delay )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-23 19:34:54 +08:00
|
|
|
my $action_time = time()+$delay;
|
|
|
|
my $action_text = $id."|".(($state eq "enable")?"disable":"enable");
|
|
|
|
my $action_array = $actions{$action_time};
|
|
|
|
if ( !$action_array )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-23 19:34:54 +08:00
|
|
|
$action_array = $actions{$action_time} = [];
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
push( @$action_array, { connection=>$connection, message=>$action_text } );
|
2005-12-23 19:34:54 +08:00
|
|
|
Debug( "Added timed event '$action_text', expires at $action_time (+$delay secs)\n" );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
|
|
|
elsif ( $action =~ /^(on|off)(?:\+(\d+))?$/ )
|
|
|
|
{
|
|
|
|
next if ( !$monitor->{Enabled} );
|
|
|
|
|
|
|
|
my $trigger = $1;
|
|
|
|
my $delay = $2;
|
|
|
|
my $trigger_data;
|
|
|
|
if ( $trigger eq "on" )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2005-12-23 19:34:54 +08:00
|
|
|
zmTriggerEventOn( $monitor, $score, $cause, $text );
|
2006-11-16 19:32:56 +08:00
|
|
|
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
|
|
|
Info( "Trigger '$trigger' '$cause'\n" );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
2006-11-16 19:32:56 +08:00
|
|
|
elsif ( $trigger eq "off" )
|
2005-12-16 18:05:29 +08:00
|
|
|
{
|
2006-11-16 19:32:56 +08:00
|
|
|
my $last_event = zmGetLastEvent( $monitor );
|
2005-12-23 19:34:54 +08:00
|
|
|
zmTriggerEventOff( $monitor );
|
2006-11-16 19:32:56 +08:00
|
|
|
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
|
|
|
Info( "Trigger '$trigger'\n" );
|
|
|
|
# Wait til it's finished
|
|
|
|
while( zmInAlarm( $monitor ) && ($last_event == zmGetLastEvent( $monitor )) )
|
|
|
|
{
|
|
|
|
# Tenth of a second
|
|
|
|
usleep( 100000 );
|
|
|
|
}
|
|
|
|
zmTriggerEventCancel( $monitor );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info( "Trigger '$trigger'\n" );
|
|
|
|
zmTriggerEventCancel( $monitor );
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
|
|
|
if ( $delay )
|
|
|
|
{
|
|
|
|
my $action_time = time()+$delay;
|
2005-12-27 06:46:03 +08:00
|
|
|
#my $action_text = $id."|cancel|0|".$cause."|".$text;
|
|
|
|
my $action_text = $id."|cancel";
|
2005-12-23 19:34:54 +08:00
|
|
|
my $action_array = $actions{$action_time};
|
|
|
|
if ( !$action_array )
|
|
|
|
{
|
|
|
|
$action_array = $actions{$action_time} = [];
|
|
|
|
}
|
2005-12-27 06:46:03 +08:00
|
|
|
push( @$action_array, { connection=>$connection, message=>$action_text } );
|
2005-12-23 19:34:54 +08:00
|
|
|
Debug( "Added timed event '$action_text', expires at $action_time (+$delay secs)\n" );
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
}
|
2005-12-23 19:34:54 +08:00
|
|
|
elsif( $action eq "cancel" )
|
|
|
|
{
|
|
|
|
zmTriggerEventCancel( $monitor );
|
2006-05-23 00:02:03 +08:00
|
|
|
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
2006-11-16 19:32:56 +08:00
|
|
|
Info( "Cancelled event\n" );
|
2005-12-23 19:34:54 +08:00
|
|
|
}
|
|
|
|
elsif( $action eq "show" )
|
|
|
|
{
|
2006-05-23 00:02:03 +08:00
|
|
|
zmTriggerShowtext( $monitor, $showtext );
|
2005-12-23 19:34:54 +08:00
|
|
|
Info( "Updated show text to '$showtext'\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Error( "Unrecognised action '$action' in message '$message'\n" );
|
|
|
|
}
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|