-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_qnapraid
More file actions
142 lines (108 loc) · 3.41 KB
/
check_qnapraid
File metadata and controls
142 lines (108 loc) · 3.41 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
#===============================================================================
#
# FILE: check_qnapraid
#
# USAGE: ./check_qnapraid
#
# DESCRIPTION: nagios check to monitor the health of the qnap
# appliances. Tested with a TS-859U-RP+ Turbo NAS
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Natxo Asenjo (), nasenjo@asenjo.nl
# COMPANY:
# VERSION: 1.0
# CREATED: 07/07/2011 10:00:00 PM
# REVISION: ---
#===============================================================================
# use common sense
use strict;
use warnings;
# variables:
my ($host, $community, $oid_softraidstatus, $help) ;
# load snmp library
use Net::SNMP;
# load cli parsing arguments
use Getopt::Long;
# load documentatation module
use Pod::Usage;
# parse cli arguemnents. Require both $host and community or help
Getopt::Long::Configure( "no_ignore_case", "bundling" );
GetOptions(
'H|hostname=s' => \$host,
'C|community=s' => \$community,
'h|help|?' => \$help,
);
# print the help message if option help is chosen or if no $host or
# $community are specified
pod2usage(-verbose => 2, -noperldoc => 1) if $help;
pod2usage(1) unless ($host && $community) ;
my %ERRORS = (
'OK' => 0,
'WARNING' => 1,
'CRITICAL' => 2,
'UNKNOWN' => 3,
'DEPENDENT' => 4,
);
# snmp oid that we want to get results from
$oid_softraidstatus = '1.3.6.1.4.1.24681.1.2.17.1.6.1';
# start snmp session
my ( $session, $error ) = Net::SNMP->session(
-hostname => $host,
-community => $community,
);
# if the snmp session fails, exit check with error message
if ( !defined $session ) {
printf "ERROR: %s.\n", $error;
exit 1;
}
# get the value in our wanted oid
my $result = $session->get_request(
-varbindlist => [$oid_softraidstatus] , );
# if we cannot get a result, exit check with error message
if ( !defined $result ) {
printf "ERROR: %s.\n", $error;
$session->close();
exit 1;
}
# close snmp session, after this we parse the results we get
$session->close();
# uncomment this to see the snmp status
#print "$result->{$oid_softraidstatus}.\n";
# nagios logica for monitoring. Warn on errors
if ( $result->{$oid_softraidstatus} eq "Ready" ) {
print "OK: software raid status is $result->{$oid_softraidstatus}.\n";
exit $ERRORS{OK};
}
elsif ( $result->{$oid_softraidstatus} eq "Rebuilding..." ) {
print "WARNING: software raid status is $result->{$oid_softraidstatus}.\n";
exit $ERRORS{WARNING};
}
elsif ( $result->{$oid_softraidstatus} =~ /^In degraded mode.*$/ ) {
print "CRITICAL: software raid status is $result->{$oid_softraidstatus}.\n";
exit $ERRORS{CRITICAL};
}
else {
print "UNKNOWN: software raid status is $result->{$oid_softraidstatus}.\n";
exit $ERRORS{UNKNOWN};
}
=head1 NAME
check_qnapraid
=head1 SYNOPSIS
check_qnapraid -H hostname -C community
=head1 DESCRIPTION
nagios plugin to check the status of the qnap appliances hardware.
The plugin requires that the SNMP service is running on the qnap
appliances, obviously.
This plugin is tested against TS-859U-RP+ Turbo NAS.
This plugin requires the Net::SNMP perl library.
=head1 ARGUMENTS
-H | --host hostname/ip address of server to monitor
-C | --community snmp community name used. Only v1 at this moment
-h | --help this help message
=head1 AUTHOR
natxo@asenjo.nl
=cut