$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;
$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
$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");
}
+# 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.
}
}
+# ---------------------------------------------------------------------------
+# 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: $@"); }
+ }
+
+}
+