summaryrefslogtreecommitdiffstats
path: root/contrib/check_arping.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_arping.pl')
-rw-r--r--contrib/check_arping.pl120
1 files changed, 120 insertions, 0 deletions
diff --git a/contrib/check_arping.pl b/contrib/check_arping.pl
new file mode 100644
index 0000000..b78ec68
--- /dev/null
+++ b/contrib/check_arping.pl
@@ -0,0 +1,120 @@
1#! /usr/bin/perl -w
2#
3# check_arping.pl - Nagios plugin to check host status via ARP ping
4#
5# usage:
6# check_arping -H hostname -I interface -T timeout
7#
8#
9# Copyright (C) 2003 Kenny Root
10#
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.
15#
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.
20#
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.
24#
25#
26# Report bugs to: kenny@the-b.org, nagiosplug-help@lists.sf.net
27
28use POSIX;
29use strict;
30use lib "/usr/lib/nagios/plugins" ;
31use utils qw($TIMEOUT %ERRORS &print_revision &support);
32
33use Net::Arping;
34use Getopt::Long;
35
36my $PROGNAME = "check_arping";
37
38my($status, $state, $answer);
39my($opt_V, $opt_h, $opt_t, $opt_I, $opt_H);
40
41
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);
49
50if ($status == 0)
51{
52 print_help() ;
53 exit $ERRORS{'OK'};
54}
55
56
57if ($opt_V) {
58 print_revision($PROGNAME,'$Revision$ ');
59 exit $ERRORS{'OK'};
60}
61
62if ($opt_h) {
63 print_help();
64 exit $ERRORS{'OK'};
65}
66
67if ($opt_t) {
68 if ($opt_t ne int($opt_t)) {
69 print "Timeout not in seconds!\n";
70 print_help();
71 exit $ERRORS{'OK'};
72 }
73 $opt_t = int($opt_t);
74} else {
75 $opt_t = 3;
76}
77
78if (! utils::is_hostname($opt_H)){
79 usage();
80 exit $ERRORS{"UNKNOWN"};
81}
82
83my $ping = Net::Arping->new();
84
85my $reply = $ping->arping(Host => $opt_H, Interface => $opt_I, Timeout => $opt_t);
86
87if ($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";
94}
95
96print "ARPING $state - $answer\n";
97exit $ERRORS{$state};
98
99
100sub 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"};
107}
108
109sub 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$');
119
120}