From: Stephen L Johnson Date: Wed, 9 Feb 2000 20:17:03 +0000 (+0000) Subject: added 'event' message handling to update routines X-Git-Tag: spong-2_7-alpha5~84 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9972f4a4cead5d057fe05e294822ce82c4282ea3;p=spong.git added 'event' message handling to update routines --- diff --git a/src/spong-server.pl b/src/spong-server.pl index 3cb61c0..128517f 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -189,6 +189,7 @@ sub listen_for_updates { # "ack", "config", and "stat". if( $header =~ /^status\b/ ) { &save_status( $header, $message ); next; } + if( $header =~ /^event\b/ ) { &save_event( $header, $message ); next; } if( $header =~ /^ack-del\b/ ) { &del_ack( $header, $message ); next; } if( $header =~ /^ack\b/ ) { &save_ack( $header, $message ); next; } # if( $header =~ /^config\b/ ) { &save_config( $header, $message ); } @@ -417,6 +418,54 @@ sub save_status { } +# Take the incoming event, run it through some error checking, save it to +# the history database. + +sub save_event { + my( $header, $message ) = @_; + my( $cmd, $host, $service, $color, $time, $sum, $path ); + + # Do some checking on the message. If it appears bogus, then just + # log a message, and close the connection. + + if( $header =~ /^(\w+) (\S+) (\w+) (\w+) ([:0-9]+) (.*)$/ ) { + ($cmd, $host, $service, $color, $time, $sum) = ($1, $2, $3, $4, $5, $6); + + if( $host !~ m/^[a-z0-9_\-\.]+$/ ) { + &error( "save_event: invalid host [$host]" ); return; } + if( $service !~ m/^[a-z0-9_\-\.]+$/ ) { + &error( "save_event: invalid service [$service]" ); return; } + if( $color ne "red" && $color ne "yellow" && $color ne "green" ) { + &error( "save_event: invalid color [$color]" ); return;} + if ( $time =~ /(\d+):(\d+)/ ) { $time = $1; $ttl = $2; } + if( $time !~ m/^\d+$/ ) { + &error( "save_event: invalid time [$time]" ); return; } + } else { + &error( "save_event: invalid header [$header]" ); return; + } + + if ($main::HOSTS{$host} eq "") { + &error("save_status: undefined host [$host]"); + return; + } + + # Save the status information to the database, if there is a change in + # color, then update the history table and state file as well. + + # Update the history file + $data = "event $time $service $color $sum\n"; + &save_data( ">>", "$SPONGDB/$host/history/current", $data); + + # If status history is enabled, save status message for history event + if ( $STATUS_HISTORY ) { + # Save the status update information + $data = "timestamp $time $time\ncolor $color\n$time $sum\n$message\n"; + &save_data( ">>", "$SPONGDB/$host/history/status/$time-$service", + $data); + } + +} + # Take a BigBrother status message and convert it to a Spong status # message and send it to save_status for processing