Merge pull request #1240 from knnniggett/zmtrigger
zmtrigger - process off+time delay condition
This commit is contained in:
commit
74c0d40b19
|
@ -504,22 +504,11 @@ sub handleMessage
|
|||
Info( "Set monitor to $state\n" );
|
||||
if ( $delay )
|
||||
{
|
||||
my $action_time = time()+$delay;
|
||||
my $action_text = $id."|".( ($state eq "enable")
|
||||
? "disable"
|
||||
: "enable"
|
||||
)
|
||||
;
|
||||
my $action_array = $actions{$action_time};
|
||||
if ( !$action_array )
|
||||
{
|
||||
$action_array = $actions{$action_time} = [];
|
||||
}
|
||||
push( @$action_array, { connection=>$connection,
|
||||
message=>$action_text
|
||||
}
|
||||
);
|
||||
Debug( "Added timed event '$action_text', expires at $action_time (+$delay secs)\n" );
|
||||
handleDelay($delay, $connection, $action_text);
|
||||
}
|
||||
}
|
||||
elsif ( $action =~ /^(on|off)(?:[ \+](\d+))?$/ )
|
||||
|
@ -534,9 +523,19 @@ sub handleMessage
|
|||
zmTriggerEventOn( $monitor, $score, $cause, $text );
|
||||
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
||||
Info( "Trigger '$trigger' '$cause'\n" );
|
||||
if ( $delay )
|
||||
{
|
||||
my $action_text = $id."|cancel";
|
||||
handleDelay($delay, $connection, $action_text);
|
||||
}
|
||||
}
|
||||
elsif ( $trigger eq "off" )
|
||||
{
|
||||
if ( $delay )
|
||||
{
|
||||
my $action_text = $id."|off|0|".$cause."|".$text;
|
||||
handleDelay($delay, $connection, $action_text);
|
||||
} else {
|
||||
my $last_event = zmGetLastEvent( $monitor );
|
||||
zmTriggerEventOff( $monitor );
|
||||
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
||||
|
@ -551,26 +550,6 @@ sub handleMessage
|
|||
}
|
||||
zmTriggerEventCancel( $monitor );
|
||||
}
|
||||
else
|
||||
{
|
||||
Info( "Trigger '$trigger'\n" );
|
||||
zmTriggerEventCancel( $monitor );
|
||||
}
|
||||
if ( $delay )
|
||||
{
|
||||
my $action_time = time()+$delay;
|
||||
#my $action_text = $id."|cancel|0|".$cause."|".$text;
|
||||
my $action_text = $id."|cancel";
|
||||
my $action_array = $actions{$action_time};
|
||||
if ( !$action_array )
|
||||
{
|
||||
$action_array = $actions{$action_time} = [];
|
||||
}
|
||||
push( @$action_array, { connection=>$connection,
|
||||
message=>$action_text
|
||||
}
|
||||
);
|
||||
Debug( "Added timed event '$action_text', expires at $action_time (+$delay secs)\n" );
|
||||
}
|
||||
}
|
||||
elsif( $action eq "cancel" )
|
||||
|
@ -590,5 +569,23 @@ sub handleMessage
|
|||
}
|
||||
} # end sub handleMessage
|
||||
|
||||
sub handleDelay
|
||||
{
|
||||
my $delay = shift;
|
||||
my $connection = shift;
|
||||
my $action_text = shift;
|
||||
|
||||
my $action_time = time()+$delay;
|
||||
my $action_array = $actions{$action_time};
|
||||
if ( !$action_array )
|
||||
{
|
||||
$action_array = $actions{$action_time} = [];
|
||||
}
|
||||
push( @$action_array, { connection=>$connection,
|
||||
message=>$action_text
|
||||
}
|
||||
);
|
||||
Debug( "Added timed event '$action_text', expires at $action_time (+$delay secs)\n" );
|
||||
}
|
||||
1;
|
||||
__END__
|
||||
|
|
Loading…
Reference in New Issue