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" );
|
Info( "Set monitor to $state\n" );
|
||||||
if ( $delay )
|
if ( $delay )
|
||||||
{
|
{
|
||||||
my $action_time = time()+$delay;
|
|
||||||
my $action_text = $id."|".( ($state eq "enable")
|
my $action_text = $id."|".( ($state eq "enable")
|
||||||
? "disable"
|
? "disable"
|
||||||
: "enable"
|
: "enable"
|
||||||
)
|
);
|
||||||
;
|
handleDelay($delay, $connection, $action_text);
|
||||||
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 =~ /^(on|off)(?:[ \+](\d+))?$/ )
|
elsif ( $action =~ /^(on|off)(?:[ \+](\d+))?$/ )
|
||||||
|
@ -534,43 +523,33 @@ sub handleMessage
|
||||||
zmTriggerEventOn( $monitor, $score, $cause, $text );
|
zmTriggerEventOn( $monitor, $score, $cause, $text );
|
||||||
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
zmTriggerShowtext( $monitor, $showtext ) if defined($showtext);
|
||||||
Info( "Trigger '$trigger' '$cause'\n" );
|
Info( "Trigger '$trigger' '$cause'\n" );
|
||||||
|
if ( $delay )
|
||||||
|
{
|
||||||
|
my $action_text = $id."|cancel";
|
||||||
|
handleDelay($delay, $connection, $action_text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif ( $trigger eq "off" )
|
elsif ( $trigger eq "off" )
|
||||||
{
|
{
|
||||||
my $last_event = zmGetLastEvent( $monitor );
|
if ( $delay )
|
||||||
zmTriggerEventOff( $monitor );
|
|
||||||
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
|
my $action_text = $id."|off|0|".$cause."|".$text;
|
||||||
usleep( 100000 );
|
handleDelay($delay, $connection, $action_text);
|
||||||
}
|
} else {
|
||||||
|
my $last_event = zmGetLastEvent( $monitor );
|
||||||
|
zmTriggerEventOff( $monitor );
|
||||||
|
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 );
|
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" )
|
elsif( $action eq "cancel" )
|
||||||
|
@ -590,5 +569,23 @@ sub handleMessage
|
||||||
}
|
}
|
||||||
} # end 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;
|
1;
|
||||||
__END__
|
__END__
|
||||||
|
|
Loading…
Reference in New Issue