retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-raid-areca
1 #!/usr/bin/perl
2
3 # downloaded as check_areca from
4 # http://www.nagiosexchange.org/cgi-bin/page.cgi?g=1486.html;d=1
5 # on 20081001 by weasel.
6 #
7 # local changes: fix path to areca_cli
8
9 #####################################################
10 #Program to check the areca RAID controller for the status of the RAID
11 #Created: 2007-11-27
12 #Version: 1.1.0              
13 #Revised: 2008-07-23
14 #Revised by: Erinn Looney-Triggs
15 #Author: Erinn Looney-Triggs
16 #Changelog: 
17 #1.1: Fixed issue with newer versions of the Areca CLI > 1.72 and
18 #fixed a problem where the RAID name contained spaces 
19 #(Reported by Daniel Philipp). Also did a bit of cleanup.
20 #####################################################
21
22 use Carp;
23 use English qw( -no_match_vars );
24 use Getopt::Long;            #Grab command line switches
25 use Pod::Usage;
26 use strict;                  #Do it right
27 use warnings;
28
29 $ENV{PATH}      = '/usr/local/bin:/usr/bin:'; #Safer path
30 my $areca_cli   = '/usr/local/sbin/areca-cli';
31 my $timeout     = '10';             #Default timeout of 10 seconds
32 my $VERSION     = '1.1.0';          #Version number
33
34 #Nagios plugin return values, in english
35 my $OK          = '0';
36 my $WARNING     = '1';
37 my $CRITICAL    = '2';
38 my $UNKNOWN     = '3';
39
40 GetOptions( 'areca_cli|A=s'     => \$areca_cli,
41             'man'               => sub { pod2usage(3) },
42             'timeout|t=i'       => \$timeout,
43             'usage'             => sub { pod2usage(1) },
44             'version'           => sub { VersionMessage() },
45             'help'              => sub { pod2usage(1) },
46 );
47
48 sanity_checks();
49 parse_areca( check_areca() );
50
51 sub check_areca{
52     my @output;
53     
54     #Timer operation. Times out after $timeout seconds.
55     eval {
56     
57         #Set the alarm and set the timeout
58         local $SIG{ALRM} = sub { die "alarm\n" };
59         alarm $timeout;
60     
61         #Run the command      
62         @output = `sudo $areca_cli vsf info`;
63         if ($?){
64             print "Command: cli vsf info failed, "
65                 . "$OS_ERROR $CHILD_ERROR, aborting!\n";
66             exit $CRITICAL;
67         }
68         
69         #Reset the alarm if successful
70         alarm 0;
71     };
72
73     #Test return value and exit if eval caught the alarm
74     if ($EVAL_ERROR) {
75         if ( $EVAL_ERROR eq "alarm\n" ) {
76             print "Operation timed out after $timeout seconds.\n";
77             exit $CRITICAL;
78         }
79         else {
80             print "An unknown error has occured: $EVAL_ERROR \n";
81             exit $UNKNOWN;
82         }
83     }
84     
85     return @output;  
86 }
87
88 sub parse_areca{
89     my @output = @_;
90     
91     my $abnormal;       #Holds count of non-normal returns
92     
93     my @pertinent_lines = grep (/\s\d+\s/, @output);
94     
95     for my $line (@pertinent_lines){
96         #Strip of leading spaces
97         $line =~ s/^\s+//;
98        
99         #Split the line into discrete parts
100         my ( $number, $level, $capacity, $state, ) 
101             =  (split (/\s+/, "$line"))[0,-4,-3,-1];
102  
103         #If the state is normal continue on in loop
104         if (lc $state eq "normal"){
105             print "|Controller number: $number RAID level: $level "
106             . "Capacity: $capacity State: $state| ";
107         }
108         
109         #If state is abnormal continue on in loop but add 1 to $abnormal
110         else{
111             print "|Controller number: $number RAID level: $level "
112             . "Capacity: $capacity State: $state| ";
113             $abnormal++;
114         }
115     }
116     
117     #If any abnormalities exist ext with a critical error.
118     if ($abnormal){
119         exit $CRITICAL;
120     }
121     else {
122         exit $OK;
123     }
124     
125     return;     #This should never be reached
126 }
127
128 sub sanity_checks{
129     if (! -e $areca_cli){
130         print "$areca_cli does not exist, aborting!\n";
131         exit $CRITICAL;
132     }
133     if (! -x $areca_cli){
134         print "$areca_cli is not executable by the running user, aborting!\n";
135         exit $CRITICAL;
136     }
137     
138     return;     #This should never be reached
139 }
140
141 #Version message information displayed in both --version and --help
142 sub main::VersionMessage {
143     
144     print <<"EOF";
145 This is version $VERSION of check_areca.
146
147 Copyright (c) 2007-2008 Erinn Looney-Triggs (erinn.looneytriggs\@gmail.com). 
148 All rights reserved.
149
150 This module is free software; you can redistribute it and/or
151 modify it under the terms of the GNU General Public License. 
152 See http://www.fsf.org/licensing/licenses/gpl.html
153
154 This program is distributed in the hope that it will be useful,
155 but WITHOUT ANY WARRANTY; without even the implied warranty of
156 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
157
158 EOF
159
160     exit 1;
161 }
162
163 __END__
164
165 =head1 NAME
166
167 check_areca - Checks the status of an Areca RAID via the Areca CLI utility.
168
169 =head1 VERSION
170
171 This documentation refers to check_areca version 1.1.0
172
173 =head1 USAGE
174
175 check_areca.pl
176
177 =head1 REQUIRED ARGUMENTS
178
179 None
180
181 =head1 OPTIONS
182
183     --areca_cli   (-A)     Set the location of the Areca cli executable. 
184     --help                 Display usage information.
185     --man                  Display the entire POD documentation     
186     --timeout     (-t)     Sets the timeout, defaults to 10 seconds.
187     --usage                Display usage information (same as --help)
188     --version              Display the version number
189
190
191 =head1 DESCRIPTION
192  
193 This is a Nagios plugin that runs the Areca CLI to check the status of the 
194 RAID controller. It then parses the resultant exit information and 
195 passes the output to NRPE. 
196
197 =head1 DIAGNOSTICS
198
199 =head2 Command: cli vsf info failed, aborting!
200
201 For some reason the command trying to be run failed. Try running it by hand
202 and seeing if it runs properly.
203
204 =head2 Operation timed out after <timeout> seconds.
205
206 Running the command failed after a certain amount of time (defaults to 10 
207 seconds). Try using the --timeout (-t) switch and increasing the timeout
208 threshold. Also try running the command by hand and see if it is hanging.
209
210 =head2 An unknown error has occurred:
211
212 Just what it says, running the cli command threw an unknown error and the 
213 process died. Run the CLI command by hand and see if you receive proper 
214 output.
215
216 =head2 <areca cli> does not exist, aborting!
217
218 The binary that the script is looking to run does not exist. By default 
219 check_areca looks in /usr/local/areca/bin/ for the cli. However, you can 
220 change this default by setting the --areca_cli (-A) flag from the command
221 line
222
223 =head2 <areca cli> is not executable by the running user, aborting!
224
225 The cli program was found but it is not executable by the current user, 
226 usually this is the nagios user. 
227
228 =head1 CONFIGURATION AND ENVIRONMENT
229
230 The Areca cli program should be available on the system. By default 
231 check_areca looks in /usr/local/areca/bin/cli for the cli. You can set the 
232 location using the --areca_cli (-A) flag from the command line.
233
234 It is helpful to have an Areca RAID controller on the system being checked.
235  
236 =head1 DEPENDENCIES
237  
238     check_areca depends on the following modules:
239     POSIX           Standard Perl 5.8 module
240     Getopt::Long    Standard Perl 5.8 module
241     Pod::USAGE      Standard Perl 5.8 module       
242     
243 =head1 INCOMPATIBILITIES
244
245 None known yet.
246
247 =head1 BUGS AND LIMITATIONS
248
249 Bugs, never heard of 'em ;).
250 If you encounter any bugs let me know. (erinn.looneytriggs@gmail.com)
251
252 =head1 AUTHOR
253
254 Erinn Looney-Triggs (erinn.looneytriggs@gmail.com)
255
256 =head1 LICENCE AND COPYRIGHT
257
258 Copyright (c) 2007-2008 Erinn Looney-Triggs (erinn.looneytriggs@gmail.com). 
259 All rights reserved.
260
261 This module is free software; you can redistribute it and/or
262 modify it under the terms of the GNU General Public License. 
263 See L<http://www.fsf.org/licensing/licenses/gpl.html>.
264  
265 This program is distributed in the hope that it will be useful,
266 but WITHOUT ANY WARRANTY; without even the implied warranty of
267 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.