summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/check_traceroute-pure_perl.pl119
1 files changed, 119 insertions, 0 deletions
diff --git a/contrib/check_traceroute-pure_perl.pl b/contrib/check_traceroute-pure_perl.pl
new file mode 100644
index 0000000..96d1ff8
--- /dev/null
+++ b/contrib/check_traceroute-pure_perl.pl
@@ -0,0 +1,119 @@
1#!/usr/bin/perl -Wall
2#
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.
7#
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.
12#
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.
16#
17#
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.
22#
23# check_traceroute v0.1
24# By mp@xmission.com
25#
26# Thanks to Sebastian Hetze, Linux Information Systems AG who wrote the
27# excellent check_apache plugin, which this plugin was modeled after.
28#
29#############################################################################
30
31use strict;
32use Net::Traceroute;
33use Getopt::Long;
34
35my $version = "v0.1";
36my $opt_v;
37my $opt_t=undef; #for usage () unless ($opt_t) to work right
38my $opt_help;
39my $opt_w;
40my $opt_c;
41
42my %ERRORS = ('UNKNOWN' , '-1',
43 'OK' , '0',
44 'WARNING', '1',
45 'CRITICAL', '2');
46# Set this to whatever you like, but make sure you don't hang Nagios
47# for too long.
48my $timeout = "30";
49
50GetOptions
51 ("v" => \$opt_v, "t=s" => \$opt_t,
52 "help" => \$opt_help, "h" => \$opt_help,
53 "w=i" => \$opt_w, "c=i" => \$opt_c
54 );
55
56if ($opt_v) {
57 print "\nThis is check_traceroute version $version\n";
58 print "\n";
59 print "Please report errors to mp\@xmission\.com";
60 print "\n\n";
61 }
62
63#subs
64sub print_help () {
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";
68 print "Usage:\n";
69 print "\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";
75 }
76
77sub usage() {
78 print "check_traceroute -t <host> [-w <warning>] [-c <critical>]\n";
79 }
80
81sub do_check() {
82 if ($opt_t) {
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";
85 if($tr->found) {
86 my $hops = $tr->hops;
87 if($hops > $opt_w) {
88 print "Warning: $opt_t is $hops hops away!\n";
89 exit $ERRORS{'WARNING'};
90 }
91 elsif($hops > $opt_c) {
92 print "Critical: $opt_t is $hops hops away!\n";
93 exit $ERRORS{'CRITICAL'};
94 }
95 else {
96 print "OK: $opt_t is $hops hops away\n";
97 exit $ERRORS{'OK'};
98 }
99 }
100 else {
101 print "Couldn't locate host $opt_t!\n";
102 exit $ERRORS{'UNKNOWN'};
103 }
104 }
105 }
106
107# Must be placed at the end for -Wall to compile cleanly, blech
108if ($opt_help) {
109 print_help();
110 }
111usage() unless ($opt_t);
112#timeoutes
113$SIG{'ALRM'} = sub {
114 print ("ERROR: No response from $opt_t (timeout) in $timeout seconds\n");
115 exit $ERRORS{"UNKNOWN"};
116 };
117 alarm($timeout);
118do_check();
119