[Mon-commit] mon/mon.d traceroute.monitor,1.2,1.2.2.1
Brought to you by:
trockij
|
From: Jim T. <tr...@us...> - 2007-06-03 13:09:05
|
Update of /cvsroot/mon/mon/mon.d In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32211/mon.d Modified Files: Tag: mon-1-2-branch traceroute.monitor Log Message: traceroute.monitor update Index: traceroute.monitor =================================================================== RCS file: /cvsroot/mon/mon/mon.d/traceroute.monitor,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** traceroute.monitor 15 Nov 2004 14:45:19 -0000 1.2 --- traceroute.monitor 3 Jun 2007 13:08:59 -0000 1.2.2.1 *************** *** 14,22 **** # Jon Meek # Lawrenceville, NJ ! # me...@ie... # # $Id$ # ! # Copyright (C) 2001, Jon Meek # # This program is free software; you can redistribute it and/or modify --- 14,22 ---- # Jon Meek # Lawrenceville, NJ ! # meekj at ieee.org # # $Id$ # ! # Copyright (C) 2001-2005, Jon Meek # # This program is free software; you can redistribute it and/or modify *************** *** 46,50 **** =head1 SYNOPSIS ! B<traceroute.monitor -d -t 20 -c /path/to/traceroute.cf -l /usr/local/mon/logs/routes_YYYYMM.log> The logfile template is usually specified in the configuration file. --- 46,50 ---- =head1 SYNOPSIS ! B<traceroute.monitor -d -t 20 -c -u /path/to/traceroute.cf -l /usr/local/mon/logs/routes_YYYYMM.log> The logfile template is usually specified in the configuration file. *************** *** 54,67 **** =over 5 ! =item B<-d> Debug/Test ! =item B<-c config.cfg> Configuration file for this monitor, see example below ! =item B<-t timeout> Timeout for traceroute to run in seconds default is 20s =item B<-l log_file_template> /path/to/logs/internet_web_YYYYMM.log Current year & month are substituted for YYYYMM, that is the only possible template at this time. =back --- 54,87 ---- =over 5 ! =item B<-d> ! Debug/Test ! =item B<-c config.cfg> ! ! Configuration file for this monitor, see example below ! ! =item B<-t timeout> ! ! Timeout for traceroute to run in seconds default is 20s =item B<-l log_file_template> /path/to/logs/internet_web_YYYYMM.log + Current year & month are substituted for YYYYMM, that is the only possible template at this time. + =item B<-u> + + Fail On Unexpected Hop Only - An alert will be triggered if any of the + IP addresses specified using the UnexpectedHop item in the + configuration file are observed. Any other route change will not + create an alert. This option is useful for alerting when a backup + circuit becomes part of a default route. This option causes + traceroute.monitor to act more like a traditional mon monitor because + an alert will be triggered on every monitor run if an UnexpectedHop + appears in the path. The use of mon's alertafter N directive can be + used to filter out short term glitches that might cause a route to + change for just one monitor cycle. + =back *************** *** 81,85 **** =head1 CONFIGURATION FILE EXAMPLE ! # tracreoute.monitor Config File RouteLogFile /usr/local/mon/logs/routes_YYYYMM.log RouterList /usr/local/mon/rt.list --- 101,105 ---- =head1 CONFIGURATION FILE EXAMPLE ! # traceroute.monitor Config File RouteLogFile /usr/local/mon/logs/routes_YYYYMM.log RouterList /usr/local/mon/rt.list *************** *** 91,94 **** --- 111,120 ---- StopAt 172.30.124.17 A firewall StopAt 172.31.124.17 Another firewall + UnexpectedHop 10.22.249.2 S2S VPN Tunnel + AlertMessage + For more details see: + http://$HOSTNAME/cgi-bin/network/traceroute.anal + EndAlertMessage + Lines with '#' in the first column are ignored. *************** *** 100,107 **** RouterList - Optional IP address to router name translation in ! /etc/hosts format (IP_address router_bame). Supplying this list will provide considerably more meaningful alarm messages, especially if the ! router names contain geographical information. Without this list the ! extended alarm is just a list of interface IP addresses. Traceroute - Overrides the default of /usr/sbin/traceroute --- 126,134 ---- RouterList - Optional IP address to router name translation in ! /etc/hosts format (IP_address router_name). Supplying this list will provide considerably more meaningful alarm messages, especially if the ! router names contain geographical information. Without this list, or ! DNS records, the extended alarm is just a list of interface IP ! addresses. DNS results take precedence over this list. Traceroute - Overrides the default of /usr/sbin/traceroute *************** *** 127,130 **** --- 154,169 ---- directive. There can be multiple StopAt lines. + UnexpectedHop - See the description of the -u option above. The + presence of an UnexpectedHop in a path will trigger an alarm + regardless of whether the -u option is set, or not. + + AlertMessage - A message that is appended to the alert details starts + on the next line. $HOSTNAME, if present in the message, is converted + to the name of the machine on which the monitor is running. + + EndAlertMessage - The AlertMessage can be terminated by this + directive, but it is not required if the message is at the end of the + configuration file. + =head1 BUGS *************** *** 141,149 **** =cut ! use Getopt::Std; ! use POSIX qw(:signal_h WNOHANG); ! use POSIX qw(strftime); ! getopts ("vdt:l:c:"); # -l file Log file name with optional YYYYMM part that will be transformed to current month --- 180,199 ---- =cut ! use Getopt::Long; ! use Sys::Hostname; ! use POSIX qw(:signal_h WNOHANG strftime); ! use Socket; ! #getopts ("vdt:l:c:"); ! ! GetOptions ('v' => \$opt_v, ! 'd' => \$opt_d, ! 'debug' => \$opt_d, ! 't=i' => \$opt_t, ! 'l=s' => \$opt_l, ! 'c=s' => \$opt_c, ! 'u' => \$FailOnUnexpectedHopOnly, ! 'unexpectedhoponly' => \$FailOnUnexpectedHopOnly, ! ); # -l file Log file name with optional YYYYMM part that will be transformed to current month *************** *** 152,156 **** # Usual Linux config ! $TRACEROUTE = '/usr/sbin/traceroute'; #$STATE_DIR = '/usr/local/mon/state.d'; --- 202,206 ---- # Usual Linux config ! $TRACEROUTE = '/bin/traceroute'; #$STATE_DIR = '/usr/local/mon/state.d'; *************** *** 214,217 **** --- 264,282 ---- } + if ($in =~ /^UnexpectedHop\s+/i) { + ($tag, $ip, $name) = split(' ', $in, 3); + print "UnexpectedHop $ip, $name<br>\n" if $opt_d; + $UnexpectedHop{$ip}++; + $UnexpectedHopName{$ip} = $name; + } + + if ($in =~ /^AlertMessage/i) { # Extra text to add to an alert starts on next line + while ($in = <C>) { + last if ($in =~ /^EndAlertMessage/i); + $AlertMessage .= $in; + } + $MonitorHostname = hostname; + $AlertMessage =~ s/\$HOSTNAME/$MonitorHostname/; + } } } else { *************** *** 242,246 **** if ($TestOnly) { foreach $h (@Hosts) { ! print "Host: $h\n"; if (defined $EquivIP{$h}) { --- 307,312 ---- if ($TestOnly) { foreach $h (@Hosts) { ! $name = &HopName($h); ! print "Host: $h $name\n"; if (defined $EquivIP{$h}) { *************** *** 319,326 **** $ThisHopIP = $1; push(@HopList, $ThisHopIP); # Build route hop list if ($opt_v) { chomp $in; ! print "$in $RouterByIP{$ThisHopIP}\n"; } --- 385,396 ---- $ThisHopIP = $1; push(@HopList, $ThisHopIP); # Build route hop list + if ($UnexpectedHop{$ThisHopIP}) { + $UnexpectedHopSeen{$TargetHost}++; + } if ($opt_v) { chomp $in; ! $name = &HopName($h); ! print "$in $name $RouterByIP{$ThisHopIP}\n"; } *************** *** 396,400 **** } ! if (&RouteChanged($current_route, $prev_route)) { # Route changed, alarm and record if ($RunningUnderMon) { # Write results open(S, ">$state_file") || warn "Can't open $state_file for writing\n"; --- 466,475 ---- } ! $ThisTargetFailed = 0; ! $ThisTargetFailed++ if $UnexpectedHopSeen{$k}; ! ! if (&RouteChanged($current_route, $prev_route)) { # Route changed, record, alarm if not using only unexpected hops ! $ThisTargetFailed++ unless $FailOnUnexpectedHopOnly; ! $LogString{$k} = $ResultString{$k}; # Use separate string for logging route changes so that we don't always log unexpected hops if ($RunningUnderMon) { # Write results open(S, ">$state_file") || warn "Can't open $state_file for writing\n"; *************** *** 402,405 **** --- 477,483 ---- close S; } + } + + if ($ThisTargetFailed) { push (@Failures, $k); print " Alarm\n" if $opt_d; *************** *** 413,416 **** --- 491,495 ---- close S; } + # $LogString{$k} = $ResultString{$k}; # Always log the first instance push (@Failures, $k); # Call it a failure so it will be logged and notification will be sent print " New route added to check: $k\n" if $opt_d; *************** *** 419,425 **** } ! # Write results to logfile, if -l ! ! #if ($RunningUnderMon && $LogFile) { if ($LogFile) { --- 498,504 ---- } ! # ! # Write results to logfile ! # if ($LogFile) { *************** *** 445,452 **** } ! if (($NewLogFile == 0) && (@Failures > 0)) { # Just record changes ! foreach $host (sort @Failures) { ! print LOG "$ResultString{$host}\n"; } } --- 524,532 ---- } ! if (($NewLogFile == 0) && (@Failures > 0)) { # Just record changes, not repeated unexpected hops ! foreach $host (sort keys %LogString) { ! print LOG "$LogString{$host}\n"; } + } *************** *** 459,463 **** } ! if (defined $RouterListFile) { # Read the router names if we have a failure open(F, $RouterListFile); --- 539,544 ---- } ! # Note that we might have already read this file if --v was specified ! # if (defined $RouterListFile) { # Read the router names if we have a failure open(F, $RouterListFile); *************** *** 479,487 **** (@hop_ips) = split(/\-/, $rest); foreach $hop_ip (@hop_ips) { ! printf " %-15s %s\n", $hop_ip, $RouterByIP{$hop_ip}; } print "\n"; } exit 1; --- 560,575 ---- (@hop_ips) = split(/\-/, $rest); foreach $hop_ip (@hop_ips) { ! $name = &HopName($hop_ip); ! printf " %-15s %s", $hop_ip, $name; ! print " Unexpected Hop: $UnexpectedHopName{$hop_ip}" if ($UnexpectedHop{$hop_ip}); ! print "\n"; } print "\n"; } + if (defined $AlertMessage) { + print "\n$AlertMessage\n"; + } + exit 1; *************** *** 515,516 **** --- 603,634 ---- } + sub HopName { + my ($h_ip) = @_; + my ($lookupname, $ha); + # print "HopName: $h_ip<br>\n" if $opt_d; + if ($h_ip =~ /^\*/) { + $name = 'Not reached'; + return $name; + } + + if (exists $HopNameCache{$h_ip}) { # Already have the name + $name = $HopNameCache{$h_ip}; + return $name; + } + $name = ''; + $ha = inet_aton($h_ip); + $lookupname = gethostbyaddr($ha, &AF_INET); + + if (length($lookupname) > 0) { # Attempt lookup of address via "normal" system methods (DNS, hosts, etc) + $name = $lookupname; + } elsif ($UseRouterList) { + $name = $RouterByIP{$h_ip} if (exists $RouterByIP{$h_ip}); + } + + # Have an auxilliary name? such as "London Internet Router", prepend it + # $name = qq{$RouteHopName{$h_ip} $name} if (exists $RouteHopName{$h_ip}); + + $HopNameCache{$h_ip} = $name; + # print "$h_ip -- $name<br>\n" if $opt_d; + return $name; + } |