From: Stephen L Johnson Date: Tue, 8 Feb 2000 19:03:33 +0000 (+0000) Subject: added optional time-to-live parameter to spong client<=>server protocol X-Git-Tag: spong-2_7-alpha5~96 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6263a8b27fbeb05f85d8225524b4453ca3497acd;p=spong.git added optional time-to-live parameter to spong client<=>server protocol (cmd host service color time[:ttl] summary) --- diff --git a/src/spong-server.pl b/src/spong-server.pl index 816371a..3cb61c0 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -333,11 +333,12 @@ sub listen_for_queries { sub save_status { my( $header, $message ) = @_; my( $cmd, $host, $service, $color, $time, $sum, $path, $start, $duration ); + my( $ttl ) = 0; # 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+) (\d+) (.*)$/ ) { + 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_\-\.]+$/ ) { @@ -346,8 +347,11 @@ sub save_status { &error( "save_status: invalid service [$service]" ); return; } if( $color ne "red" && $color ne "yellow" && $color ne "green" ) { &error( "save_status: invalid color [$color]" ); return;} + if ( $time =~ /(\d+):(\d+)/ ) { $time = $1; $ttl = $2; } if( $time !~ m/^\d+$/ ) { &error( "save_status: invalid time [$time]" ); return; } + if( $ttl !~ m/^\d+$/ ) { + &error( "save_status: invalid time to live [$ttl]" ); return; } } else { &error( "save_status: invalid header [$header]" ); return; } @@ -357,7 +361,6 @@ sub save_status { return; } - $start = $time; # Default start time to event time # Try to read start time from the status file @@ -385,6 +388,7 @@ sub save_status { $data = "status $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 $start $time\ncolor $color\n$time $sum\n$message\n"; @@ -398,7 +402,9 @@ sub save_status { foreach( "red", "yellow", "green", "purple" ) { unlink "$path/$service-$_"; } $data = "timestamp $start $time\n$time $sum\n$message\n"; - &save_data( ">>", "$SPONGDB/$host/services/$service-$color", $data ); + my($expire) = ($ttl == 0) ? 0 : $time + $ttl; + &save_data( ">>", "$SPONGDB/$host/services/$service-$color", $data, + $expire ); # Call of the data function modules in the registry foreach my $df (keys %DATAFUNCS) { @@ -924,9 +930,10 @@ sub hostlist { # the way... sub save_data { - my( $mode, $file, $data ) = @_; + my( $mode, $file, $data, $expire ) = @_; my( $dir ) = ( $file =~ /^(.*)\/[^\/]+$/ ); my $umask; + $expire = 0 if ! defined $expire; $umask = umask(); umask 022; @@ -938,6 +945,12 @@ sub save_data { close( DATA ); chmod 0644, $file; umask $umask; + if ( $expire != 0 ) { + my( $s, $m, $h, $D, $M, $Y ) = (localtime($expire)); + $Y += 1900; + my( $timestamp) = "$Y$M$D$h$m.$s"; + utime( time(), $expire, $file); + } }