-
Notifications
You must be signed in to change notification settings - Fork 18
/
check_sas_raid
executable file
·107 lines (91 loc) · 2.64 KB
/
check_sas_raid
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
#!/usr/bin/perl -w
#
# check_sas_raid
# Check hardware raid based on LSI Fusion-MPT SAS(-2)
#
# Nicolas Hennion (aka Nicolargo)
#
# Add the following line to the sudoers file (where 0 is the id card number):
# nagios ALL= NOPASSWD: /usr/sbin/sas2ircu 0 STATUS
#
#==================================================
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
#
# http://www.gnu.org/licenses/gpl.txt
#
#==================================================
my $program_name = "check_sas_raid";
my $program_version = "0.2";
my $program_date = "09/2011";
# Libraries
#----------
use strict;
use lib "/usr/local/nagios/libexec";
use Getopt::Std;
# Globals variables
#------------------
my $cardid = "0";
my $output = "Raid status";
my $raidstatus = 'sudo /usr/sbin/sas2ircu';
my %ERRORS = ('UNKNOWN' , '3',
'OK' , '0',
'WARNING', '1',
'CRITICAL', '2' );
my $state = "UNKNOWN";
my $answer = "";
# Programs argument management
#-----------------------------
my %opts = ();
getopts("hvi:", \%opts);
if ($opts{v}) {
# Display the version
print "$program_name $program_version ($program_date)\n";
exit(-1);
}
if ($opts{h}) {
# Help
print "$program_name $program_version\n";
print "usage: ", $program_name," [options]\n";
print " -h: Print the command line help\n";
print " -v: Print the program version\n";
print " -i: Card id, default is 0\n";
exit (-1);
}
if ($opts{i}) {
$cardid = $opts{i};
}
# Main program
#-------------
system("$raidstatus $cardid STATUS | grep 'Volume state' > /tmp/$program_name.res") == 0
or die "$state: $raidstatus failed ($?)";
open FILE, "</tmp/$program_name.res";
my @lines = <FILE>;
for (@lines) {
if ($_ =~ /Optimal/) {
$state = "OK";
} elsif ($_ =~ /Degraded/) {
$state = "WARNING";
} elsif ($_ =~ /Failed/) {
$state = "CRITICAL";
} else {
$state = "UNKNOWN";
}
$output = $_;
}
system("rm -f /tmp/$program_name.res") == 0
or die "$state: Can not delete /tmp/$program_name.res ($?)";
print $output;
exit $ERRORS{$state};
# The end...