/[svn]/nagios/tags/monitoring.dennisonwilliams.com/libexec/check_belkin_dns.pl
ViewVC logotype

Contents of /nagios/tags/monitoring.dennisonwilliams.com/libexec/check_belkin_dns.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2138 - (show annotations)
Sat Apr 25 18:01:17 2009 UTC (10 years, 7 months ago) by evoltech
File MIME type: text/plain
File size: 4047 byte(s)
This directory must have gotten lost from the repo when frenzy did the rm -rf, adding it again
1 #!/usr/bin/perl -w
2 use POSIX;
3 use strict;
4 use lib "/usr/local/nagios/libexec" ;
5 use utils qw($TIMEOUT %ERRORS &print_revision &support);
6
7 use Getopt::Long;
8 Getopt::Long::Configure('bundling');
9 use BelkinF5D72304v8000;
10 use Data::Dumper;
11
12 my $PROGNAME = "check_belkin_dns";
13 my $VERSION = "v1.0";
14
15 sub print_help ();
16 sub usage ();
17 sub process_arguments ();
18
19 my $status;
20
21 my $timeout ;
22 my $state = "UNKNOWN";
23 my $answer = "";
24
25 my $hostname;
26 my $username;
27 my $password;
28 my $DNSSERVER = 0;
29
30 my $opt_h ;
31 my $opt_V ;
32 my $opt_c ;
33 my $opt_C ;
34 my $opt_w ;
35 my $opt_s ;
36
37 # Just in case of problems, let's not hang Nagios
38 $SIG{'ALRM'} = sub {
39 print ("ERROR: No response from BelkinF5D72304v8000.pm (alarm timeout)\n");
40 exit $ERRORS{"UNKNOWN"};
41 };
42
43 #Option checking
44 $status = process_arguments();
45
46 if ($status != 0)
47 {
48 print_help() ;
49 exit $ERRORS{'OK'};
50 }
51
52 my $belkin = new BelkinF5D72304v8000($hostname);
53 alarm($timeout);
54 eval {
55 $belkin->init();
56 };
57 if ($@) {
58 print "There was a problem connecting to the belkin router: $@";
59 exit $ERRORS{'UNKNOWN'};
60 }
61 alarm(0);
62
63 if ($opt_s < 0 || $opt_s > $#{$belkin->{dns}}) {
64 print "you entered an invalid DNS server to check, you can check form 0 to ". $#{$belkin->{dns}} ."\n";
65 exit $ERRORS{'UNKNOWN'};
66 }
67
68 #there has got to be a better way to do this
69 my $path = $INC[0];
70 my $check = 'check_dns';
71 my $cmd = $path ."/". $check ." -H $opt_C -s ". $belkin->{dns}[$opt_s];
72 open(CMD, "$cmd |")
73 or die("Could not execute '$cmd': $!");
74
75 print $belkin->{dns}[$opt_s] ." ";
76 while (<CMD>) {
77 print $_;
78 }
79 close (CMD);
80 exit ($?>>8);
81
82 #then we pretty much wantto pass everything off to the check_ping command
83
84 sub usage (){
85 printf "\nMissing arguments!\n";
86 printf "\n";
87 printf "$0 -H <BELKIN_ROUTER_ADDR> -C <HOST>\n";
88 printf "Copyright (C) 2008 Dennison Williams <dennison.williams\@gmail.com>\n";
89 printf "\n\n";
90 support();
91 exit $ERRORS{"UNKNOWN"};
92 }
93
94 sub print_help (){
95 printf "$PROGNAME plugin for Nagios check if Belkin router gw is reachable.\n";
96 printf "\nUsage:\n";
97 printf " -u (--username) Username\n";
98 printf " -p (--password) Password\n";
99 printf " -H (--hostname) Hostname\n";
100 printf " -w (--warning) Warning threshold\n";
101 printf " -c (--critical) Critical threshold\n";
102 printf " -t (--timeout) seconds before the plugin times out (default=$TIMEOUT)\n";
103 printf " -s (--server) DNS server (default=$DNSSERVER)\n";
104 printf " -C (--host2check) Host to lookup\n";
105 printf " -V (--version) Plugin version\n";
106 printf " -h (--help) usage help \n\n";
107
108 printf "DNS server is the DNS server of the belkin you would like to check.\n";
109 printf "ie 0, 1, 2, or 3.\n\n";
110
111 printf "THRESHOLD is <rta>,<pl>% where <rta> is the round trip average travel\n";
112 printf "time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n";
113 printf "percentage of packet loss to trigger an alarm state.\n\n";
114
115 printf "This plugin uses the check_ping nagios plugin to check the state of the\n";
116 printf "gateway set in the Belkin router.\n\n";
117
118 print_revision($PROGNAME, $VERSION);
119 }
120
121 sub process_arguments() {
122 $status = GetOptions(
123 "V" => \$opt_V, "version" => \$opt_V,
124 "h" => \$opt_h, "help" => \$opt_h,
125 "u=s" => \$username, "username=s" => \$username,
126 "p=s" => \$password, "password=s" => \$password,
127 "H=s" => \$hostname, "hostname=s" => \$hostname,
128 "w=s" => \$opt_w, "warning=i" => \$opt_w,
129 "c=s" => \$opt_c, "critical=i" => \$opt_c,
130 "s=i" => \$opt_s, "server=i" => \$opt_s,
131 "C=s" => \$opt_C, "host2check=s" => \$opt_C,
132 "t=i" => \$timeout, "timeout=i" => \$timeout,
133 );
134
135 if ($status == 0){
136 print_help() ;
137 exit $ERRORS{'OK'};
138 }
139
140 if ($opt_V) {
141 print_revision($PROGNAME, $VERSION);
142 exit $ERRORS{'OK'};
143 }
144
145 if ($opt_h) {
146 print_help();
147 exit $ERRORS{'OK'};
148 }
149
150 unless (defined $timeout) {
151 $timeout = $TIMEOUT;
152 }
153
154 unless ( defined $username ) {
155 $username = 'admin';
156 }
157
158 unless ( defined $hostname ) {
159 usage();
160 }
161
162 unless ( defined $opt_s ) {
163 $opt_s = $DNSSERVER;
164 }
165
166 return 0;
167 }

Properties

Name Value
svn:executable

dennison.williams@gmail.com
ViewVC Help
Powered by ViewVC 1.1.5