From: Stephen L Johnson Date: Wed, 10 Jan 2001 16:29:41 +0000 (+0000) Subject: added new purple and clear statuses X-Git-Tag: spong-2_7_3~9 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cf9008578cad47c96cbe4078cb2a678ea8e7ffc;p=spong.git added new purple and clear statuses --- diff --git a/src/lib/Spong/HistoryList.pm b/src/lib/Spong/HistoryList.pm index 90d24bb..c421239 100755 --- a/src/lib/Spong/HistoryList.pm +++ b/src/lib/Spong/HistoryList.pm @@ -43,7 +43,7 @@ sub new { open( FILE, "$main::SPONGDB/$host/history/current" ); while( ) { chomp; - if( /^status (\d+) (\S+) (green|yellow|red) (.*)$/ ) { + if( /^status (\d+) (\S+) (green|yellow|red|purple|clear) (.*)$/ ) { push( @list, Spong::History->new( $host, "status", $1, $2, $3, $4 ) ); } elsif( /^ack (\d+) (\S+) (.*)$/ ) { diff --git a/src/lib/Spong/HostGroups.pm b/src/lib/Spong/HostGroups.pm index 3bd7cff..9a1b36c 100755 --- a/src/lib/Spong/HostGroups.pm +++ b/src/lib/Spong/HostGroups.pm @@ -18,14 +18,14 @@ # + add - adds a specific host group to the instance # -# $Id: HostGroups.pm,v 1.10 2000/12/14 21:18:40 sljohnson Exp $ +# $Id: HostGroups.pm,v 1.11 2001/01/10 16:29:41 sljohnson Exp $ use Spong::Host; use Spong::HostList; package Spong::HostGroups; -my %COLORS = ( 'blue', 4, 'red', 5, 'yellow', 3, 'green', 1, 'purple', 2 ); +my %COLORS = ( 'blue', 4, 'red', 5, 'yellow', 3, 'green', 1, 'purple', 2, 'clear', 0 ); # This constructor expects one of four different types of options. Either an # empty string specifying that no actual hostlist will be loaded, the string @@ -152,7 +152,7 @@ sub display_text { foreach my $cnt ( 0..5 ) { if( $cnt == 0 ) { print "Key: . = green, ? = purple "; } if( $cnt == 1 ) { print " Y = yellow, R = red "; } - if( $cnt == 2 ) { print " B = blue "; } + if( $cnt == 2 ) { print " B = blue, o = clear "; } if( $cnt == 3 ) { print " "x30; } if( $cnt == 4 ) { print " "x30; } if( $cnt == 5 ) { print "Group:", " "x24; } @@ -179,6 +179,7 @@ sub display_text { if( $color eq "yellow" ) { print "Y "; } if( $color eq "red" ) { print "R "; } if( $color eq "blue" ) { print "B "; } + if( $color eq "clear" ) { print "o "; } } else { print " "; } @@ -205,7 +206,7 @@ sub display_text { foreach my $cnt ( 0..4 ) { if( $cnt == 0 ) { print "Key: . = green, ? = purple "; } if( $cnt == 1 ) { print " Y = yellow, R = red "; } - if( $cnt == 2 ) { print " B = blue "; } + if( $cnt == 2 ) { print " B = blue, o = clear "; } if( $cnt == 3 ) { print " "x30; } if( $cnt == 4 ) { print "Group:", " "x24; } foreach $service ( @names ) { @@ -233,6 +234,7 @@ sub display_text { if( $color eq "yellow" ) { print "Y "; } if( $color eq "red" ) { print "R "; } if( $color eq "blue" ) { print "B "; } + if( $color eq "clear" ) { print "o "; } } else { print " "; } diff --git a/src/lib/Spong/HostList.pm b/src/lib/Spong/HostList.pm index 1e4a833..abb089f 100755 --- a/src/lib/Spong/HostList.pm +++ b/src/lib/Spong/HostList.pm @@ -25,7 +25,8 @@ use Spong::Host; package Spong::HostList; -my %COLORS = ( 'blue', 4, 'red', 5, 'yellow', 3, 'green', 1, 'purple', 2 ); +my %COLORS = ( 'red', 5, 'blue', 4, 'yellow', 3, 'purple', 2, 'green', 1, + 'clear', 0 ); # This constructor expects one of four different types of options. Either an # empty string specifying that no actual hosts will be loaded, the string @@ -178,7 +179,7 @@ sub display_text { foreach $cnt ( 0..4 ) { if( $cnt == 0 ) { print "Key: . = green, ? = purple "; } if( $cnt == 1 ) { print " Y = yellow, R = red "; } - if( $cnt == 2 ) { print " B = blue "; } + if( $cnt == 2 ) { print " B = blue, o = clear "; } if( $cnt == 3 ) { print " "x30; } if( $cnt == 4 ) { print "Host:", " "x25; } foreach $service ( @names ) { diff --git a/src/lib/Spong/Service.pm b/src/lib/Spong/Service.pm index dc35332..9c0216b 100755 --- a/src/lib/Spong/Service.pm +++ b/src/lib/Spong/Service.pm @@ -205,6 +205,7 @@ sub display_text { if( $self->color() eq "yellow" ) { print "Y "; } if( $self->color() eq "red" ) { print "R "; } if( $self->color() eq "blue" ) { print "B "; } + if( $self->color() eq "clear" ) { print "o "; } } elsif( $format eq "brief" ) { print $self->color(), "\n"; } elsif( $format eq "standard_table" ) { diff --git a/src/lib/Spong/ServiceList.pm b/src/lib/Spong/ServiceList.pm index c3f2a73..5cc0e2b 100755 --- a/src/lib/Spong/ServiceList.pm +++ b/src/lib/Spong/ServiceList.pm @@ -46,7 +46,7 @@ sub new { if ( ! $main::SERVICELISTFIX ) { opendir( DIR, "$main::SPONGDB/$host/services" ); while( defined( $_ = readdir( DIR ) ) ) { - next unless /^(.*)-(green|yellow|red)$/ ; + next unless /^(.*)-(green|yellow|red|purple|clear)$/ ; my( $name, $color ) = ($1, $2); # A hack to get around a local problem. @@ -73,7 +73,7 @@ sub new { } foreach ( @files ) { chomp; - next unless /^(.*)-(green|yellow|red)$/ ; + next unless /^(.*)-(green|yellow|red|purple|clear)$/ ; my( $name, $color ) = ($1, $2); # A hack to get around a local problem. @@ -89,6 +89,7 @@ sub new { } else { $service->rcolor( $color ); $service->color( $color ); } + $service_hash{$name} = $service; } } @@ -139,7 +140,7 @@ sub names { return keys %{$_[0]->{'service_hash'}}; } sub color { my $self = shift; - my( %state_hash ) = qw( blue 3 red 4 yellow 2 purple 1 green 0 ); + my( %state_hash ) = qw( red 5 blue 4 yellow 3 purple 2 green 1 clear 0); my $state = "green"; foreach $service ( $self->services() ) { diff --git a/src/spong-message.pl b/src/spong-message.pl index 1d17fe4..538e313 100755 --- a/src/spong-message.pl +++ b/src/spong-message.pl @@ -12,7 +12,7 @@ # (2) Added rules based paging (Stephen Johnson Nov 14, 1998) # (3) Added checks against Acks and downtime (Stephen Johnson Mar 17, 1999) # -# $Id: spong-message.pl,v 1.25 2000/12/31 22:59:58 sljohnson Exp $ +# $Id: spong-message.pl,v 1.26 2001/01/10 16:29:41 sljohnson Exp $ use lib "@@LIBDIR@@"; @@ -24,6 +24,7 @@ use FileHandle; use English; use POSIX qw(strftime); +local @con; my %opt; @options = ( "help", "host=s", "service=s", "time=i", "color|status=s", "summary=s", "duration=i", "message=s", "file=s", "debug", @@ -38,7 +39,7 @@ if( ! GetOptions( \%opt, @options ) ) { &error("Incorrect usage"); exit 1; } my($color, $host, $service, $time, $summary, $duration) = @ARGV; if ( ! $color && defined $opt{'color'} ) { $color = $opt{'color'}; } -if ( $color !~ /red|yellow|green/ ) { +if ( $color !~ /red|yellow|green|purple|clear/ ) { &error( "Invalid status color. Must be green, yellow, or red."); exit 1; } if ( ! $host && defined $opt{'host'} ) { $host = $opt{'host'}; } @@ -330,7 +331,7 @@ RULE: # If we got a match and rule match is first only, exit loop if ($match and $RULES_MATCH eq 'FIRST-MATCH') { - &debug("Matched a rule, exiting rules scan"); + &debug("Matched a rule, exiting rules scan\n\n\n\n\n"); last; } diff --git a/src/spong-server.pl b/src/spong-server.pl index fb214bf..68c1498 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -6,7 +6,7 @@ # There are one or more update processes that listen for status updates # from client programs. -# $Id: spong-server.pl,v 1.36 2000/12/19 22:50:01 sljohnson Exp $ +# $Id: spong-server.pl,v 1.37 2001/01/10 16:29:41 sljohnson Exp $ use lib "@@LIBDIR@@"; @@ -401,6 +401,7 @@ sub listen_for_queries { }; # Set up the socket to listen to + my( $localTimeOut ) = 15 ; my( $sock, $client ); $sock = IO::Socket::INET->new( Listen => SOMAXCONN, LocalPort => $main::SPONG_QUERY_PORT, @@ -410,17 +411,31 @@ sub listen_for_queries { ); if (! defined $sock ) { die "socket: $!"; } - my( $next_update ) = time() + (15 * 60); + my( $next_update ) = 0; &debug( "query server socket setup, listening for connections" ); while( 1 ) { # Update the service list from the database every 15 minutes - if ( $time >= $next_update ) { + if ( time() >= $next_update ) { + debug("Scanning for stale data to convert to purple status",5); foreach $host ( Spong::HostList->new( "all" )->hosts() ) { foreach $service ( $host->service_names() ) { - $main::SERVICES{$service}=1;}} - $next_update =+ 15 * 60; + $main::SERVICES{$service}=1; + my ($color )=($host->service($service))->color(); + my ($summary)=($host->service($service))->summary(); + my ($message)=($host->service($service))->message(); + my ($stime) = time(); + my ($hostname)=$host->name(); + if ( $color eq 'purple' ) { + &save_status("status $hostname $service $color $stime $summary" + ,"$message") ; + } + } + } + $next_update =+ $localTimeOut * 60; + } else { + &debug(time() . " < $next_update"); } @@ -564,7 +579,7 @@ sub save_status { &error( "save_status: invalid host [$host]" ); return; } if( $service !~ m/^[a-z0-9_\-\.]+$/ ) { &error( "save_status: invalid service [$service]" ); return; } - if( $color ne "red" && $color ne "yellow" && $color ne "green" ) { + if( $color !~ m/red|yellow|green|purple|clear/ ) { &error( "save_status: invalid color [$color]" ); return;} if ( $time =~ /(\d+):(\d+)/ ) { $time = $1; $ttl = $2; } if( $time !~ m/^\d+$/ ) { @@ -619,7 +634,8 @@ sub save_status { &debug( "[$$] updating status for $host/$service/$color", 3 ); $path = "$SPONGDB/$host/services"; - foreach( "red", "yellow", "green", "purple" ) { unlink "$path/$service-$_"; } + foreach( "red", "yellow", "green", "purple", "clear" ) + { unlink "$path/$service-$_"; } $data = "timestamp $start $time\n$time $sum\n$message\n"; my($expire) = ($ttl == 0) ? 0 : $time + $ttl; @@ -845,6 +861,15 @@ sub save_ack { $data = "$user $service\n$message\n"; $file = "$SPONGDB/$host/acks/" . int(rand($$)) . "-$now-$time"; &save_data( ">>", $file, $data ); + + if ( STATUS_HISTORY ) { + # Save the status update information + $untiltime = POSIX::strftime( "%H:%M, %D", localtime($time) ); + $data = "timestamp $now $time\ncolor blue\n$now $user ack $service Until $untiltime \nack: $service by $user \n$message\n"; + &save_data( ">>", "$SpongConf::SPONGDB/$host/history/status/$now-$service", $data); + + } + } # Take the incoming acknowledgment message, run it through some error checking @@ -1111,7 +1136,7 @@ sub message_user { } elsif ( $SEND_MESSAGE eq "CHANGE" ) { # If status has changed my $firstrun = 1; - foreach my $c ('red','yellow','green') { + foreach my $c ('red','yellow','green','clear','purple') { if( -f "$SPONGDB/$host/$service.$c" ) { $firstrun = 0; } } if ( ! -f "$SPONGDB/$host/services/$service.$color"