3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # check_traceroute is designed to generate and alarm if a traceroute exceeds
19 # a certain number of hops. This is useful in cases where a multi-homed
20 # network looses a connection and can still ping the remote end because
21 # traffic is being re-routed out through the redundent connection.
23 # check_traceroute v0.1
26 # Thanks to Sebastian Hetze, Linux Information Systems AG who wrote the
27 # excellent check_apache plugin, which this plugin was modeled after.
29 #############################################################################
37 my $opt_t=undef; #for usage () unless ($opt_t) to work right
42 my %ERRORS = ('UNKNOWN' , '-1',
46 # Set this to whatever you like, but make sure you don't hang Nagios
51 ("v" => \
$opt_v, "t=s" => \
$opt_t,
52 "help" => \
$opt_help, "h" => \
$opt_help,
53 "w=i" => \
$opt_w, "c=i" => \
$opt_c
57 print "\nThis is check_traceroute version $version\n";
59 print "Please report errors to mp\@xmission\.com";
65 print "\n\nThis is check_traceroute.pl. It is designed to send an alert\n";
66 print "to Nagios if a route to a particular destination exceeds a\n";
67 print "certain number of hops.\n\n";
70 print "--help Display this help.\n";
71 print "-v Display the version number of check_traceroute.\n";
72 print "-t Host that you wish to traceroute to.\n";
73 print "-w Number of hops before Nagios generates a WARNING.\n";
74 print "-c Number of hops before Nagios generates a CRITICAL.\n";
78 print "check_traceroute -t <host> [-w <warning>] [-c <critical>]\n";
83 unless ($opt_w && $opt_c) {die "You must specify thresholds using -c and -w\n";}
84 my $tr = Net
::Traceroute
->new(host
=>"$opt_t") || die "Can't init traceroute!\n";
88 print "Warning: $opt_t is $hops hops away!\n";
89 exit $ERRORS{'WARNING'};
91 elsif($hops > $opt_c) {
92 print "Critical: $opt_t is $hops hops away!\n";
93 exit $ERRORS{'CRITICAL'};
96 print "OK: $opt_t is $hops hops away\n";
101 print "Couldn't locate host $opt_t!\n";
102 exit $ERRORS{'UNKNOWN'};
107 # Must be placed at the end for -Wall to compile cleanly, blech
111 usage
() unless ($opt_t);
114 print ("ERROR: No response from $opt_t (timeout) in $timeout seconds\n");
115 exit $ERRORS{"UNKNOWN"};