# (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@@";
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.
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'}; }
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'} ) {
# 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'}} ) {
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];
}
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'}) {
}
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;
}
}
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 <filename>
+ if <filename> 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
# --------------------------------------------------------------------------