From: Stephen L Johnson Date: Wed, 15 Dec 1999 21:09:39 +0000 (+0000) Subject: Added server status plugin mechanism to allow outside access to data. X-Git-Tag: spong-2_6-beta8~3 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc49a284138c079b7db73c8e479e90e9acb7c83b;p=spong.git Added server status plugin mechanism to allow outside access to data. Added fix in message_user() to remove old np-xxx files when a service changes status. --- diff --git a/src/spong-server.pl b/src/spong-server.pl index 3962349..8b70417 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -38,9 +38,14 @@ $smessage = "@@BINDIR@@/spong-message"; $conf_file = $ARGV[0] || "@@ETCDIR@@/spong.conf"; $hosts_file = "@@ETCDIR@@/spong.hosts"; $groups_file = "@@ETCDIR@@/spong.groups"; +$datafunc_path = "@@LIBDIR@@/Spong/plugins"; ($HOST) = gethostbyname(&Sys::Hostname::hostname()); $HOST =~ tr/A-Z/a-z/; +%DATAFUNCS = (); +&load_data_funcs(); +&debug("Done loading data plugins"); + $upd_pid = 0; $bb_pid = 0; $shutdown = 0; @@ -323,8 +328,17 @@ sub save_status { $data = "timestamp $start $time\n$time $sum\n$message\n"; &save_data( ">>", "$SPONGDB/$host/services/$service-$color", $data ); -} + # Call of the data function modules in the registry + foreach my $df (keys %DATAFUNCS) { + &debug("[$$] Running data function $df"); + + &{$DATAFUNCS{$df}}($host, $service, $color, $start, $time, $sum, + $message ); + + } + +} # Take a BigBrother status message and convert it to a Spong status # message and send it to save_status for processing @@ -606,6 +620,12 @@ sub message_user { $SIG{'CHLD'} = 'IGNORE'; if ( $cmd eq "status" ) { + + # Remove current np files if event is a change in status (i.e. dur = 0) + if ( $duration == 0 ) { + &remove_np_files($host,$service); + } + if ($color eq 'red' && $duration != 0) { if ( -f $smessage ) { &debug("color is red, calling smessage for escalations"); @@ -656,6 +676,30 @@ sub message_user { } +# This function removes old np_files which are status information for +# notification delay and repeat notification processing + +sub remove_np_files { + my( $host, $service ) = @_; + my( @files, $file ); + + if (! opendir(NP,$SPONGTMP)) { + &error("remove_np_files: could not opendir $SPONGTMP"); + return; + } + @files = grep { /^np-/ } readdir(NP); + closedir(NP); + if (! @files) { return; } + + foreach $file (@files) { + if ( $file =~ m/^np-[^-]-$host-$service/ ) { + unlink "$SPONGWWW/$file"; + } + } + +} + + # This function just loads in all the configuration information from the # spong.conf, spong.hosts, and spong.groups files. @@ -843,3 +887,24 @@ sub chld_handler { } } +# --------------------------------------------------------------------------- +# Load all of the data functions into the DATAFUNCS registry +# --------------------------------------------------------------------------- + +sub load_data_funcs { + my($file,@files); + + if ( ! -d $datafunc_path) { return; } + opendir(MSG,$datafunc_path) or die "Could not opendir $datafunc_path: $!"; + @files = grep { /^data_/ } readdir(MSG); + closedir(MSG); + + foreach $file (@files) { + $file =~ /data_(.*)$/; $base = $1; + &debug("Loading data function $base"); + eval { require "$datafunc_path/$file"; }; + if ( $@ ) { &error("Could not load messaging function $base: $@"); } + } + +} +