-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_nfsping.pl
executable file
·94 lines (74 loc) · 2.52 KB
/
check_nfsping.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env perl
# check_nfsping.pl
# Author: Johan van den Dorpe <[email protected]>
# Use nfsping to check the availability of an NFS server
#
# TODO: Also test mount protocol
# Handle hosts with multiple interfaces
use strict;
use warnings;
use Data::Dumper;
use Nagios::Plugin;
use Switch;
my $nfsping = "/usr/bin/nfsping";
my $n = Nagios::Plugin->new(
shortname => 'check_nfsping',
usage => 'Usage: %s --hostname HOSTNAME'
);
$n->add_arg(
spec => 'hostname|H=s',
help => '--hostname HOSTNAME - hostname of the NFS server',
required => 1
);
$n->add_arg(
spec => 'count=s',
help => '--count COUNT - number of nfsping packets to send (Default: 5)',
default => 5
);
$n->add_arg(
spec => 'time=s',
help => '--time TIMEOUT - milliseconds before ping times out (Default: 2500)',
default => 2500
);
$n->add_arg(
spec => 'critical=s',
help => '--critical CRITICAL - critical loss percentage threshold (Default: 100)',
default => 100
);
$n->add_arg(
spec => 'use-tcp|T',
help => '--use-tcp - use TCP (Default: UDP)'
);
$n->getopts;
$n->nagios_die("no hostname specified") unless $n->opts->hostname;
$n->nagios_die("nfsping not installed") unless (-e $nfsping);
run_nfsping();
$n->nagios_exit(OK, "");
sub run_nfsping {
$nfsping = $nfsping . " -T" if $n->opts->get('use-tcp');
my $cmd = sprintf "%s -q -c %s -t %s %s", $nfsping, $n->opts->count, $n->opts->time, $n->opts->hostname;
my @output = `$cmd 2>&1`;
my $result = $?;
chomp @output;
# Search for known errors in output
my $searchstring = quotemeta "xmt/rcv/%loss";
foreach my $line (@output) {
switch ($line) {
# normal output
# filer1 : xmt/rcv/%loss = 5/5/0%, min/avg/max = 0.14/0.18/0.19
case /$searchstring/ {
$line =~ s/.*$searchstring = (.*)%.*/$1/;
my ($xmt, $rcv, $loss) = split(/\//, $line);
$n->nagios_exit(CRITICAL, "nfsping loss $loss% above critical threshold 100%") if ($loss >= $n->opts->critical);
}
# in TCP mode, server hard down
# clnttcp_create: RPC: Remote system error - Connection timed out
case qr/clnttcp_create: RPC: Remote system error - Connection timed out/ { $n->nagios_exit(CRITICAL, "host is dead") }
# server hard down
# clnttcp_create: RPC: Remote system error - No route to host
case qr/clnttcp_create: RPC: Remote system error - No route to host/ { $n->nagios_exit(CRITICAL, "host is dead") }
}
}
# If exitcode is not 0, return UNKNOWN
$n->nagios_exit(UNKNOWN, \@output) if ($result != 0)
}