# There are one or more update processes that listen for status updates
# from client programs.
-# $Id: spong-server.pl,v 1.47 2001/11/14 17:05:24 sljohnson Exp $
+# $Id: spong-server.pl,v 1.48 2002/01/11 19:28:44 sljohnson Exp $
use lib "@@LIBDIR@@";
%DATAFUNCS = ();
+%PREDATAFUNCS = ();
+%POSTDATAFUNCS = ();
&load_data_funcs();
+&load_predata_funcs();
+&load_postdata_funcs();
&debug("Done loading data plugins");
%PROCS = (); # All of the procs that we will be monitoring in the main process
if ($header =~ /^timestamp (\d+) (\d+)/) { $start = $1; }
close FILE;
}
+ $duration = $time - $start;
- # Before we change the state of the database, call message_user()...
+ # Build message hash for data plugin calls
+ my $msg = { 'header' => $header,
+ 'message' => $message,
+ 'cmd' => $cmd,
+ 'host' => $host,
+ 'service' => $service,
+ 'color' => $color,
+ 'time' => $time,
+ 'duration' => $duration,
+ };
- $duration = $time - $start;
- &message_user( "status", $host, $service, $color, $time, $sum, $duration,
- $message );
+ # Call of the data function modules in the registry
+ foreach my $df (sort(keys %PREDATAFUNCS)) {
+ &debug("[$$] Running pre data function $df",4);
+ &{$PREDATAFUNCS{$df}}( $msg );
+ }
- # Make sure that this service is registered in our master service list.
+ # If a Predata plugin says to drop the message, drop it
+ if ( $msg->{'drop_msg'} ) {
+ debug( "[$$] signal from pre data func module, dropping message",5);
+ return;
+ }
- $main::SERVICES{$service} = 1;
+ # Before we change the state of the database, call message_user()...
+ &message_user( "status", $host, $service, $color, $time, $sum, $duration,
+ $message );
# Save the status information to the database, if there is a change in
# color, then update the history table and state file as well.
$expire );
# Call of the data function modules in the registry
- foreach my $df (keys %DATAFUNCS) {
+ foreach my $df (sort(keys %POSTFUNCS)) {
+ &debug("[$$] Running post data function $df",4);
+ &{$POSTFUNCS{$df}}( $msg );
+ }
+
+ # Call of the data function modules in the registry
+ foreach my $df (sort(keys %DATAFUNCS)) {
&debug("[$$] Running data function $df",4);
&{$DATAFUNCS{$df}}($host, $service, $color, $start, $time, $sum,
&error( "save_ack: invalid header [$header]" ); return;
}
- return if $main::HOSTS{$host} eq "";
+ if ($main::HOSTS{$host} eq "") {
+ &error("save_ack: undefined host [$host]");
+ return;
+ }
+
+ # Build message hash for the ack
+ my $msg = { 'header' => $header,
+ 'message' => $message,
+ 'cmd' => $cmd,
+ 'host' => $host,
+ 'service' => $service,
+ 'start_time' => $now,
+ 'end_time' => $time,
+ 'user' => $user,
+ };
- # Before we change the state of the database, call message_user()...
+ # Call of the data function modules in the registry
+ foreach my $df (sort(keys %PREDATAFUNCS)) {
+ &debug("[$$] Running pre data function $df",4);
+ &{$PREDATAFUNCS{$df}}( $msg );
+ }
-# &message_user( "ack", $host, $service, $color, $summ);
+ # If a Predata plugin says to drop the message, drop it
+ if ( $msg->{'drop_msg'} ) {
+ debug( "[$$] signal from pre data func module, dropping message",5);
+ return;
+ }
# Clean up expired acknowledgments.
# 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);
+ &save_data( ">>", "$SPONGDB/$host/history/status/$now-$service", $data);
}
+ # Call of the data function modules in the registry
+ foreach my $df (sort(keys %POSTDATAFUNCS)) {
+ &debug("[$$] Running post data function $df",4);
+ &{$POSTDATAFUNCS{$df}}( $msg );
+ }
+
}
# Take the incoming acknowledgment message, run it through some error checking
if( $main::HOSTS{$host} eq "" ) {
&error( "del_ack: invalid host [$host]" ); return; }
+ # Build a hash of the del_ack message for data plugin runs
+ my $msg = { 'header' => $header,
+ 'message' => $message,
+ 'cmd' => $cmd,
+ 'host' => $host,
+ 'service' => $service,
+ 'end_time' => $end,
+ };
+
+ # Call of the data function modules in the registry
+ foreach my $df (keys %PREDATAFUNCS) {
+ &debug("[$$] Running pre data function $df",4);
+ &{$PREDATAFUNCS{$df}}( $msg );
+ }
+
+ # If a Predata plugin says to drop the message, drop it
+ if ( $msg->{'drop_msg'} ) {
+ debug( "[$$] signal from pre data func module, dropping message",5);
+ return;
+ }
+
# Remove the acknowledgement that the user specified.
opendir( DIR, "$main::SPONGDB/$host/acks" );
# I don't updated the history when an ack is deleted, I suppose I should
# but it makes things a little messing (since an update is just a delete
# and a re-add).
+
+ # Call of the data function modules in the registry
+ foreach my $df (sort(keys %POSTDATAFUNCS)) {
+ &debug("[$$] Running post data function $df",4);
+ &{$POSTDATAFUNCS{$df}}( $msg );
+ }
+
}
# ===========================================================================
$file =~ /data_(.*)$/; $base = $1;
&debug("Loading data function $base", 3 );
eval { require "$datafunc_path/$file"; };
- if ( $@ ) { &error("Could not load messaging function $base: $@"); }
+ if ( $@ ) { &error("Could not load data function $base: $@"); }
+ }
+
+}
+
+# ---------------------------------------------------------------------------
+# Load all of the data functions into the POSTDATAFUNCS registry
+# ---------------------------------------------------------------------------
+
+sub load_postdata_funcs {
+ my($file,@files);
+
+ if ( ! -d $datafunc_path) { return; }
+ opendir(MSG,$datafunc_path) or die "Could not opendir $datafunc_path: $!";
+ @files = grep { /^post_/ } readdir(MSG);
+ closedir(MSG);
+
+ foreach $file (@files) {
+ $file =~ /post_(.*)$/; $base = $1;
+ &debug("Loading post data function $base", 3 );
+ eval { require "$datafunc_path/$file"; };
+ if ( $@ ) { &error("Could not load post data function $base: $@"); }
+ }
+
+}
+
+# ---------------------------------------------------------------------------
+# Load all of the predata functions into the PREDATAFUNCS registry
+# ---------------------------------------------------------------------------
+
+sub load_predata_funcs {
+ my($file,@files);
+
+ if ( ! -d $datafunc_path) { return; }
+ opendir(MSG,$datafunc_path) or die "Could not opendir $datafunc_path: $!";
+ @files = grep { /^pre_/ } readdir(MSG);
+ closedir(MSG);
+
+ foreach $file (@files) {
+ $file =~ /pre_(.*)$/; $base = $1;
+ &debug("Loading pre data function $base", 3 );
+ eval { require "$datafunc_path/$file"; };
+ if ( $@ ) { &error("Could not load pre data function $base: $@"); }
}
}