Fix Debian bug #534604: Checking md10 and above
[monitoring-plugins.git] / contrib / check_arping.pl
blobc41c4a8a632dcb51b2e535b2a9b08e783f31a7d4
1 #! /usr/bin/perl -w
3 # check_arping.pl - Nagios plugin to check host status via ARP ping
5 # usage:
6 # check_arping -H hostname -I interface -T timeout
9 # Copyright (C) 2003 Kenny Root
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 # Report bugs to: kenny@the-b.org, nagiosplug-help@lists.sf.net
28 use POSIX;
29 use strict;
30 use lib "/usr/lib/nagios/plugins" ;
31 use utils qw($TIMEOUT %ERRORS &print_revision &support);
33 use Net::Arping;
34 use Getopt::Long;
36 my $PROGNAME = "check_arping";
38 my($status, $state, $answer);
39 my($opt_V, $opt_h, $opt_t, $opt_I, $opt_H);
42 #Option checking
43 $status = GetOptions(
44 "V|version" => \$opt_V,
45 "help" => \$opt_h,
46 "I|interface=s" => \$opt_I,
47 "H|host=s" => \$opt_H,
48 "t|timeout=i" => \$opt_t);
50 if ($status == 0)
52 print_help() ;
53 exit $ERRORS{'OK'};
57 if ($opt_V) {
58 print_revision($PROGNAME,'$Revision: 1112 $ ');
59 exit $ERRORS{'OK'};
62 if ($opt_h) {
63 print_help();
64 exit $ERRORS{'OK'};
67 if ($opt_t) {
68 if ($opt_t ne int($opt_t)) {
69 print "Timeout not in seconds!\n";
70 print_help();
71 exit $ERRORS{'OK'};
73 $opt_t = int($opt_t);
74 } else {
75 $opt_t = 3;
78 if (! utils::is_hostname($opt_H)){
79 usage();
80 exit $ERRORS{"UNKNOWN"};
83 my $ping = Net::Arping->new();
85 my $reply = $ping->arping(Host => $opt_H, Interface => $opt_I, Timeout => $opt_t);
87 if ($reply eq "0") {
88 $state = "CRITICAL";
89 print "$state: no reply from $opt_H on interface $opt_I in $opt_t seconds.\n";
90 exit $ERRORS{$state};
91 } else {
92 $state = "OK";
93 $answer = "replied with MAC address $reply";
96 print "ARPING $state - $answer\n";
97 exit $ERRORS{$state};
100 sub usage {
101 print "\nMissing arguments!\n";
102 print "\n";
103 print "check_arping -I <interface> -H <host IP> [-t <timeout>]\n";
104 print "\n\n";
105 support();
106 exit $ERRORS{"UNKNOWN"};
109 sub print_help {
110 print "check_arping pings hosts that normally wouldn't allow\n";
111 print "ICMP packets but are still on the local network.\n";
112 print "\nUsage:\n";
113 print " -H (--host) IP to query - (required)\n";
114 print " -I (--interface) Interface to use.\n";
115 print " -t (--timeout) Timeout in seconds.\n";
116 print " -V (--version) Plugin version\n";
117 print " -h (--help) usage help \n\n";
118 print_revision($PROGNAME, '$Revision: 1112 $');