From: Stephen L Johnson Date: Tue, 19 Dec 2000 21:13:46 +0000 (+0000) Subject: added new facility to handle a group of users with new %HUMANS 'group' attrib X-Git-Tag: spong-2_7_2~27 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7fdb36c70de70213d893448aeaf8ef905398212;p=spong.git added new facility to handle a group of users with new %HUMANS 'group' attrib --- diff --git a/src/spong-message.pl b/src/spong-message.pl index 56e49f0..d515c60 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.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@@"; @@ -82,12 +82,14 @@ else { # 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; @@ -475,7 +477,11 @@ RULE: &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 @@ -486,7 +492,18 @@ RULE: # 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 " . @@ -527,7 +544,7 @@ RULE: 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'}; } } @@ -620,6 +637,40 @@ RULE: 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 # -------------------------------------------------------------------------- @@ -663,6 +714,7 @@ sub eval_template { !!SUMMARY!!', }; + if (! $templ) { &error("No custom message template or default template found"); return("","");