t push origin masterMerge branch 'knnniggett-zmtrigger2' into storageareas
This commit is contained in:
commit
e12152602b
|
@ -197,6 +197,7 @@ my %spawned_connections;
|
||||||
my %monitors;
|
my %monitors;
|
||||||
|
|
||||||
my $monitor_reload_time = 0;
|
my $monitor_reload_time = 0;
|
||||||
|
my $needsReload = 0;
|
||||||
|
|
||||||
$! = undef;
|
$! = undef;
|
||||||
my $rin = '';
|
my $rin = '';
|
||||||
|
@ -217,8 +218,8 @@ while( 1 )
|
||||||
if ( $nfound > 0 )
|
if ( $nfound > 0 )
|
||||||
{
|
{
|
||||||
Debug( "Got input from $nfound connections\n" );
|
Debug( "Got input from $nfound connections\n" );
|
||||||
foreach my $connection ( @in_select_connections )
|
foreach my $connection ( @in_select_connections ) {
|
||||||
{
|
|
||||||
if ( vec( $rout, $connection->fileno(), 1 ) )
|
if ( vec( $rout, $connection->fileno(), 1 ) )
|
||||||
{
|
{
|
||||||
Debug( "Got input from connection "
|
Debug( "Got input from connection "
|
||||||
|
@ -310,8 +311,15 @@ while( 1 )
|
||||||
|
|
||||||
# Check for alarms that might have happened
|
# Check for alarms that might have happened
|
||||||
my @out_messages;
|
my @out_messages;
|
||||||
foreach my $monitor ( values(%monitors) )
|
foreach my $monitor ( values(%monitors) ) {
|
||||||
{
|
|
||||||
|
my $memVerified = 1;
|
||||||
|
if ( !zmMemRead($monitor, "shared_data:valid") ) {
|
||||||
|
zmMemInvalidate($monitor);
|
||||||
|
$memVerified = zmMemVerify($monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($memVerified) {
|
||||||
my ( $state, $last_event )
|
my ( $state, $last_event )
|
||||||
= zmMemRead( $monitor,
|
= zmMemRead( $monitor,
|
||||||
[ "shared_data:state",
|
[ "shared_data:state",
|
||||||
|
@ -323,39 +331,36 @@ while( 1 )
|
||||||
#print( "$monitor->{Id}: mS:$monitor->{LastState}, mLE:$monitor->{LastEvent}\n" );
|
#print( "$monitor->{Id}: mS:$monitor->{LastState}, mLE:$monitor->{LastEvent}\n" );
|
||||||
if ( $state == STATE_ALARM
|
if ( $state == STATE_ALARM
|
||||||
|| $state == STATE_ALERT
|
|| $state == STATE_ALERT
|
||||||
) # In alarm state
|
) { # In alarm state
|
||||||
{
|
|
||||||
if ( !defined($monitor->{LastEvent})
|
if ( !defined($monitor->{LastEvent})
|
||||||
|| ($last_event != $monitor->{LastEvent})
|
|| ($last_event != $monitor->{LastEvent})
|
||||||
) # A new event
|
) { # A new event
|
||||||
{
|
|
||||||
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
|
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
|
||||||
}
|
} else { # The same one as last time, so ignore it
|
||||||
else # The same one as last time, so ignore it
|
|
||||||
{
|
|
||||||
# Do nothing
|
# Do nothing
|
||||||
}
|
}
|
||||||
}
|
} elsif ( ($state == STATE_IDLE
|
||||||
elsif ( ($state == STATE_IDLE
|
|
||||||
&& $monitor->{LastState} != STATE_IDLE
|
&& $monitor->{LastState} != STATE_IDLE
|
||||||
)
|
)
|
||||||
|| ($state == STATE_TAPE
|
|| ($state == STATE_TAPE
|
||||||
&& $monitor->{LastState} != STATE_TAPE
|
&& $monitor->{LastState} != STATE_TAPE
|
||||||
)
|
)
|
||||||
) # Out of alarm state
|
) { # Out of alarm state
|
||||||
{
|
|
||||||
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
|
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
|
||||||
}
|
}
|
||||||
elsif ( defined($monitor->{LastEvent})
|
elsif ( defined($monitor->{LastEvent})
|
||||||
&& ($last_event != $monitor->{LastEvent})
|
&& ($last_event != $monitor->{LastEvent})
|
||||||
) # We've missed a whole event
|
) { # We've missed a whole event
|
||||||
{
|
|
||||||
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
|
push( @out_messages, $monitor->{Id}."|on|".time()."|".$last_event );
|
||||||
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
|
push( @out_messages, $monitor->{Id}."|off|".time()."|".$last_event );
|
||||||
}
|
}
|
||||||
$monitor->{LastState} = $state;
|
$monitor->{LastState} = $state;
|
||||||
$monitor->{LastEvent} = $last_event;
|
$monitor->{LastEvent} = $last_event;
|
||||||
|
} else { # Our attempt to verify the memory handle failed. We should reload the monitors.
|
||||||
|
$needsReload = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $connection ( @out_connections )
|
foreach my $connection ( @out_connections )
|
||||||
{
|
{
|
||||||
if ( $connection->canWrite() )
|
if ( $connection->canWrite() )
|
||||||
|
@ -412,7 +417,7 @@ while( 1 )
|
||||||
}
|
}
|
||||||
|
|
||||||
# If necessary reload monitors
|
# If necessary reload monitors
|
||||||
if ( (time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL )
|
if ( $needsReload || ((time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL ))
|
||||||
{
|
{
|
||||||
foreach my $monitor ( values(%monitors) )
|
foreach my $monitor ( values(%monitors) )
|
||||||
{
|
{
|
||||||
|
@ -420,6 +425,7 @@ while( 1 )
|
||||||
zmMemInvalidate( $monitor );
|
zmMemInvalidate( $monitor );
|
||||||
}
|
}
|
||||||
loadMonitors();
|
loadMonitors();
|
||||||
|
$needsReload = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info( "Trigger daemon exiting\n" );
|
Info( "Trigger daemon exiting\n" );
|
||||||
|
|
|
@ -1128,7 +1128,7 @@ void EventStream::processCommand( const CmdMsg *msg )
|
||||||
|
|
||||||
DataMsg status_msg;
|
DataMsg status_msg;
|
||||||
status_msg.msg_type = MSG_DATA_EVENT;
|
status_msg.msg_type = MSG_DATA_EVENT;
|
||||||
memcpy( &status_msg.msg_data, &status_data, sizeof(status_msg.msg_data) );
|
memcpy( &status_msg.msg_data, &status_data, sizeof(status_data) );
|
||||||
if ( sendto( sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr) ) < 0 )
|
if ( sendto( sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr) ) < 0 )
|
||||||
{
|
{
|
||||||
//if ( errno != EAGAIN )
|
//if ( errno != EAGAIN )
|
||||||
|
|
Loading…
Reference in New Issue