From: Stephen L Johnson Date: Sun, 24 Dec 2000 20:43:14 +0000 (+0000) Subject: added printing of new 'name' attribute in --debug output and added help() X-Git-Tag: spong-2_7_2~8 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35c8d86aab428124561245c406d2165d71e34b7a;p=spong.git added printing of new 'name' attribute in --debug output and added help() --- diff --git a/pod/spong.message.pod b/pod/spong.message.pod index 41ecc07..d534840 100755 --- a/pod/spong.message.pod +++ b/pod/spong.message.pod @@ -47,6 +47,11 @@ terms: =over +=item * name + +The is a comment field to allow the rule to be described. This field +is printed on certain lines when the B<--debug> switch is specified. + =item * hosts A list of one or more regular expressions that are matched against the host diff --git a/src/spong-message.pl b/src/spong-message.pl index f169bb7..7c73134 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.22 2000/12/24 19:52:29 sljohnson Exp $ +# $Id: spong-message.pl,v 1.23 2000/12/24 20:43:14 sljohnson Exp $ use lib "@@LIBDIR@@"; @@ -25,10 +25,11 @@ use English; use POSIX qw(strftime); my %opt; -@options = ( "help", "host=s", "service=s", "time=i", "color|status=s", "summary=s", - "duration=i", "message=s", "file=s", "debug", "test" ); +@options = ( "help", "host=s", "service=s", "time=i", "color|status=s", + "summary=s", "duration=i", "message=s", "file=s", "debug", + "test" ); Getopt::Long::Configure("pass_through"); -if( ! GetOptions( \%opt, @options ) ) { &error("Incorect usage"); exit 1; } +if( ! GetOptions( \%opt, @options ) ) { &error("Incorrect usage"); exit 1; } # Check usage, and read in what we are supposed to do. @@ -43,7 +44,7 @@ if ( $color !~ /red|yellow|green/ ) { if ( ! $host && defined $opt{'host'} ) { $host = $opt{'host'}; } if ( ! $host ) { &error("Host name is required"); exit 1; } if ( ! $service && defined $opt{'service'} ) { $service = $opt{'service'}; } -if ( ! $service ) { &error("Service name is required"); exit -1; } +if ( ! $service ) { &error("Service name is required"); exit 1; } if ( ! $time && defined $opt{'time'} ) { $time = $opt{'time'}; } if ( ! $time ) { &error("Time is required"); exit 1; } if ( ! $summary && defined $opt{'summary'} ) { $summary = $opt{'summary'}; } @@ -333,7 +334,7 @@ RULE: last; } - &debug("Processing rule # $c"); + &debug("Processing rule # $c $rule->{'name'}"); # Check for matches in excluded hosts and services and host_groups if ( defined $rule->{'exclude_hosts'} ) { @@ -378,7 +379,7 @@ RULE: # Match on hosts and host_groups if ( ! defined $rule->{'hosts'} && ! defined $rule->{'host_groups'} ) { - &debug("Host match for $host on rule $c"); + &debug("Host match for $host on rule $c $rule->{'name'}"); } else { $m = 0; foreach $e ( @{$rule->{'hosts'}} ) { @@ -392,39 +393,39 @@ RULE: if ( &in_group($host,$g) ) { $m = 1; last; } } if (! $m) { - &debug("No match for host_groups on rule $c"); + &debug("No match for host_groups on rule $c $rule->{'name'}"); next RULE; } else { - &debug("host group match for $g on rule $c"); + &debug("host group match for $g on rule $c $rule->{'name'}"); } } else { - &debug("No match for host_groups on rule $c"); + &debug("No match for host_groups on rule $c $rule->{'name'}"); next RULE; } } else { - &debug("Host match for $host on rule $c"); + &debug("Host match for $host on rule $c $rule->{'name'}"); } } # Match on service if ( ! defined $rule->{'services'} ) { - &debug("service match for $service on rule $c"); + &debug("service match for $service on rule $c $rule->{'name'}"); } else { $m = 0; foreach $e ( @{$rule->{'services'}} ) { if ( $service =~ /^$e/ ) { $m = 1; last; } } if (! $m) { - &debug("No match for service $service on rule $c"); + &debug("No match for service $service on rule $c $rule->{'name'}"); next RULE; } else { - &debug("service match for $service on rule $c"); + &debug("service match for $service on rule $c $rule->{'name'}"); } } # Match on times if ( ! defined $rule->{'times'} ) { - &debug("time default match on rule $c"); + &debug("time default match on rule $c $rule->{'name'}"); } else { my($day,$time,$beg,$end,$timehit,$dayhit); my( $nday, $nhour, $nmin ) = (localtime())[6,2,1]; @@ -444,13 +445,13 @@ RULE: } if ($nday >= $beg and $nday <= $end) { $dayhit = 1; - &debug("Match on days sub-clause of rule $c"); + &debug("Match on days sub-clause of rule $c $rule->{'name'}"); last; } } } else { $dayhit = 1; - &debug("Match on days sub-clause of rule $c"); + &debug("Match on days sub-clause of rule $c $rule->{'name'}"); } if (defined $e->{'times'}) { @@ -464,24 +465,24 @@ RULE: } if ($nhour*60+$nmin >= $beg and $nhour*60+$nmin <= $end) { $timehit = 1; - &debug("Match on times sub-clause of rule $c"); + &debug("Match on times sub-clause of rule $c $rule->{'name'}"); last; } } } else { $timehit = 1; - &debug("Match on times sub-clause of rule $c"); + &debug("Match on times sub-clause of rule $c $rule->{'name'}"); } if ($timehit and $dayhit) { - &debug("Match on times clause of rule $c"); + &debug("Match on times clause of rule $c $rule->{'name'}"); $m=1; last; } } if (! $m) { - &debug("No match on times clause of rule $c"); + &debug("No match on times clause of rule $c $rule->{'name'}"); next RULE; } } @@ -650,6 +651,31 @@ RULE: return; } +sub help { + print STDERR " +Usage: spong-message [options] color host service time message [duration] + or: spong-message [options] + +Options: + --debug Print debugging output (verbose) + --test Test message rules only, don't send notifications + --file filename Read detailed message field from + if is '-', STDIN is used + --message 'text' Text for detailed message field + + --color|--status color Status color of message: red, yellow or green + --host hostname Hostname of the server being reported + --service service Service name of the service being reported + --time time The time of the event in epoch format + --summary 'text' The text for the summary message + +Note: --file and --message are mutually exclusive options. only one may be +specified. + +"; + exit(0); +} + # -------------------------------------------------------------------------- # Add a contact to the list of recipients, and handle groups # --------------------------------------------------------------------------