# (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.17 2000/12/15 21:55:04 sljohnson Exp $
+# $Id: spong-message.pl,v 1.18 2000/12/19 21:13:46 sljohnson Exp $
use lib "@@LIBDIR@@";
# exit(-1);
#}
+my $ETCDIR = "@@ETCDIR@@";
+my $LIBDIR = "@@LIBDIR@@":
-$conf_file = "@@ETCDIR@@/spong.conf";
-$hosts_file = "@@ETCDIR@@/spong.hosts";
-$groups_file = "@@ETCDIR@@/spong.groups";
-$summary_file = "@@ETCDIR@@/spong.message";
-$msgfunc_path = "@@LIBDIR@@/Spong/Message/plugins";
+$conf_file = "$ETCDIR/spong.conf";
+$hosts_file = "$ETCDIR/spong.hosts";
+$groups_file = "$ETCDIR/spong.groups";
+$summary_file = "$ETCDIR/spong.message";
+$msgfunc_path = "$LIBDIR/Spong/Message/plugins";
($HOST) = gethostbyname(&Sys::Hostname::hostname());
$HOST =~ tr/A-Z/a-z/;
$ok = 1;
&debug("Rule match on rule $c, adding contacts to recipient list");
$match = 1;
- foreach $contact ( @{$rule->{contacts}} ) { push @con,$contact; }
+ foreach $contact ( @{$rule->{contacts}} ) {
+ &debug("Calling add_contact for " . (ref($contact) eq 'HASH' ?
+ $contact->{'rcpt'} : $contact) );
+ add_contact(\@con,$contact);
+ }
}
# Load the messaging functions
# Starting sending out the notifications
foreach $contact ( @con ) {
- if ($test) { &debug("Test mode: Skipping page to $contact"); next;}
+ if ($test) {
+ if( ref($contact) eq 'HASH' ) {
+ &debug("Test mode: Skipping page to" .
+ " rcpt: " . $contact->{'rcpt'} .
+ " delay: " . $contact->{'delay'} .
+ " repeat: " . $contact->{'repeat'} .
+ " escalate: " . $contact->{'escalate'} );
+ } else {
+ &debug("Test mode: Skipping page to $contact");
+ }
+ next;
+ }
if ( $ccnt{$contact} >= $MESSAGES_PER_HOUR ) {
debug( $ccnt{$contact} . " pages sent to $contact in last " .
if ( ref($contact) eq 'HASH') {
if ( defined $contact->{'delay'} ) { $delay = $contact->{'delay'}; }
if ( defined $contact->{'escalate'} )
- { $ecalate = $contact->{'escalate'}; }
+ { $escalate = $contact->{'escalate'}; }
if ( defined $contact->{'repeat'} ) { $repeat = $contact->{'repeat'}; }
}
return;
}
+# --------------------------------------------------------------------------
+# Add a contact to the list of recipients, and handle groups
+# --------------------------------------------------------------------------
+sub add_contact {
+ ($foo,$contact) = @_;
+ @con = @$foo;
+ &debug("Adding contact " . (ref($contact) eq 'HASH' ? "hash: " .
+ $contact->{'rcpt'} : ": " . $contact));
+ push @con,$contact;
+ if ( ref($contact) eq 'HASH') {
+ foreach $rcpt ( split /[, \t]+/, $contact->{'rcpt'} ) {
+ if ( $HUMANS{$rcpt}->{'group'} ) {
+ my $groupee;
+ foreach $groupee ( split /[, \t]+/, $HUMANS{$rcpt}->{'group'} ) {
+ my $newent = {'rcpt' => $groupee};
+ if ( defined $contact->{'delay'} )
+ { $newent->{'delay'} = $contact->{'delay'}; }
+ if ( defined $contact->{'escalate'} )
+ { $newent->{'escalate'} = $contact->{'escalate'}; }
+ if ( defined $contact->{'repeat'} )
+ { $newent->{'repeat'} = $contact->{'repeat'}; }
+ &add_contact(\@con, $newent);
+ }
+ }
+ }
+ } elsif ( $HUMANS{$contact}->{'group'} ) {
+ my $groupee;
+ foreach $groupee ( split /[, \t]+/, $HUMANS{$contact}->{'group'} ) {
+ &add_contact(\@con, $groupee);
+ }
+ }
+}
+
+
# --------------------------------------------------------------------------
# Check to see if a host is in the specifed hosts group
# --------------------------------------------------------------------------
!!SUMMARY!!',
};
+
if (! $templ) {
&error("No custom message template or default template found");
return("","");