# "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 ); }
}
+# 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