forked from glensc/nagios-plugin-check_raid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_raid.pl
executable file
·3300 lines (2740 loc) · 74.9 KB
/
check_raid.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# vim:ts=4:sw=4:noet
# Nagios EPN Workaround:
# nagios: -epn
#
# Check RAID status. Look for any known types of RAID configurations, and check them all.
# Return CRITICAL if in a DEGRADED or FAILED state.
# Return UNKNOWN if there are no RAID configs that can be found.
# Return WARNING if rebuilding or initialising
#
# 2004-2006 Steve Shipway, university of auckland,
# http://www.steveshipway.org/forum/viewtopic.php?f=20&t=417&p=3211
# Steve Shipway Thanks M Carmier for megaraid section.
# 2009-2013 Elan Ruusamäe <[email protected]>
# Requires: Perl 5.8 for the open(my $fh , '-|', @CMD) syntax.
# You can workaround for earlier Perl it as:
# open(my $fh , join(" ", @CMD, '|') or return;
# http://perldoc.perl.org/perl58delta.html#PerlIO-is-Now-The-Default
#
# License: GPL v2
# Homepage: https://github.com/glensc/nagios-plugin-check_raid
# Nagios Exchange Entry: http://exchange.nagios.org/directory/Plugins/Hardware/Storage-Systems/RAID-Controllers/check_raid/details
# Reporting Bugs: https://github.com/glensc/nagios-plugin-check_raid#reporting-bugs
#
# You can also mail patches directly to Elan Ruusamäe <[email protected]>,
# but please attach them in unified format (diff -u) against latest version in github.
#
# Supports:
# - Adaptec AAC RAID via aaccli or afacli or arcconf
# - AIX software RAID via lsvg
# - HP/Compaq Smart Array via cciss_vol_status (hpsa supported too)
# - HP Smart Array Controllers and MSA Controllers via hpacucli (see hapacucli readme)
# - HP Smart Array (MSA1500) via serial line
# - Linux 3ware SATA RAID via tw_cli
# - Linux DPT/I2O hardware RAID controllers via /proc/scsi/dpt_i2o
# - Linux GDTH hardware RAID controllers via /proc/scsi/gdth
# - Linux LSI MegaRaid hardware RAID via CmdTool2
# - Linux LSI MegaRaid hardware RAID via megarc
# - Linux LSI MegaRaid hardware RAID via /proc/megaraid
# - Linux MegaIDE hardware RAID controllers via /proc/megaide
# - Linux MPT hardware RAID via mpt-status
# - Linux software RAID (md) via /proc/mdstat
# - LSI Logic MegaRAID SAS series via MegaCli
# - LSI MegaRaid via lsraid
# - Serveraid IPS via ipssend
# - Solaris software RAID via metastat
# - Areca SATA RAID Support via cli64/cli32
# - Detecting SCSI devices or hosts with lsscsi
#
# Changes:
# Version 1.1: IPS; Solaris, AIX, Linux software RAID; megaide
# Version 2.0: Added megaraid, mpt (serveraid), aaccli (serveraid)
# Version 2.1:
# - Made script more generic and secure
# - Added gdth
# - Added dpt_i2o
# - Added 3ware SATA RAID
# - Added Adaptec AAC-RAID via arcconf
# - Added LSI MegaRaid via megarc
# - Added LSI MegaRaid via CmdTool2
# - Added HP/Compaq Smart Array via cciss_vol_status
# - Added HP MSA1500 check via serial line
# - Added checks via HP hpacucli utility.
# - Added hpsa module support for cciss_vol_status
# - Added smartctl checks for cciss disks
# Version 2.2:
# - Project moved to github: https://github.com/glensc/nagios-plugin-check_raid
# - SAS2IRCU support
# - Areca SATA RAID Support
# Version 3.0:
# - Rewritten to be more modular, this allows better code testing
# - Improvements to plugins: arcconf, tw_cli, gdth, cciss
# Version 3.0.1:
# - Fixes to cciss plugin, improvements in mpt, areca, mdstat plugins
# Version 3.0.x:
# - Detecting SCSI devices or hosts with lsscsi
# - Updated to handle ARCCONF 9.30 output
# - Fixed -W option handling (#29)
use warnings;
use strict;
{
package utils;
my @EXPORT = qw(which $sudo);
my @EXPORT_OK = @EXPORT;
# registered plugins
our @plugins;
# devices to ignore
our @ignore;
# debug level
our $debug = 0;
# paths for which()
our @paths = split /:/, $ENV{'PATH'};
unshift(@paths, qw(/usr/local/nrpe /usr/local/bin /sbin /usr/sbin /bin /usr/sbin));
# lookup program from list of possibele filenames
# search is performed from $PATH plus additional hardcoded @paths
sub which {
for my $prog (@_) {
for my $path (@paths) {
return "$path/$prog" if -x "$path/$prog";
}
}
return undef;
}
our $sudo = which('sudo');
} # package utils
{
package plugin;
use Carp qw(croak);
# Nagios standard error codes
my (%ERRORS) = (OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3);
# return list of programs this plugin needs
# @internal
sub program_names {
}
# return hash of canonical commands that plugin can use
# @internal
sub commands {
{}
}
# return sudo rules if program needs it
# may be SCALAR or LIST of scalars
# @internal
sub sudo {
();
}
# constructor for plugins
sub new {
my $class = shift;
croak 'Odd number of elements in argument hash' if @_ % 2;
my $self = {
program_names => [ $class->program_names ],
commands => $class->commands,
sudo => $class->sudo ? $utils::sudo : '',
@_,
name => $class,
status => undef,
message => undef,
};
# lookup program, if not defined by params
if (!$self->{program}) {
$self->{program} = utils::which(@{$self->{program_names}});
}
return bless $self, $class;
}
# see if plugin is active (disabled or no tools available)
sub active {
my $this = shift;
# program not found
return 0 unless $this->{program};
# program not executable
-x $this->{program};
}
# set status code for plugin result
# does not overwrite status with lower value
# returns the current status code
sub status {
my ($this, $status) = @_;
if (defined $status) {
$this->{status} = $status unless defined($this->{status}) and $status < $this->{status};
}
$this->{status};
}
sub set_critical_as_warning {
$ERRORS{CRITICAL} = $ERRORS{WARNING};
}
# helper to set status to WARNING
# returns $this to allow fluent api
sub warning {
my ($this) = @_;
$this->status($ERRORS{WARNING});
return $this;
}
# helper to set status to CRITICAL
# returns $this to allow fluent api
sub critical {
my ($this) = @_;
$this->status($ERRORS{CRITICAL});
return $this;
}
# helper to set status to UNKNOWN
# returns $this to allow fluent api
sub unknown {
my ($this) = @_;
$this->status($ERRORS{UNKNOWN});
return $this;
}
# helper to set status to OK
sub ok {
my ($this) = @_;
$this->status($ERRORS{OK});
return $this;
}
# setup status message text
sub message {
my ($this, $message) = @_;
if (defined $message) {
# TODO: append if already something there
$this->{message} = $message;
}
$this->{message};
}
# a helper to join similar statuses for items
# instead of printing
# 0: OK, 1: OK, 2: OK, 3: NOK, 4: OK
# it would print
# 0-2,4: OK, 3: NOK
# takes as input list:
# { status => @items }
sub join_status {
my $this = shift;
my %status = %{$_[0]};
my @status;
for my $status (sort {$a cmp $b} keys %status) {
my $disks = $status{$status};
my @s;
foreach my $disk (@$disks) {
push(@s, $disk);
}
push(@status, join(',', @s).'='.$status);
}
return join ' ', @status;
}
# return true if parameter is not in ignore list
sub valid($) {
my $this = shift;
my ($v) = lc $_[0];
foreach (@utils::ignore) {
return 0 if lc $_ eq $v;
}
return 1;
}
use constant K => 1024;
use constant M => K * 1024;
use constant G => M * 1024;
use constant T => G * 1024;
sub format_bytes($) {
my $this = shift;
my ($bytes) = @_;
if ($bytes > T) {
return sprintf("%.2f TiB", $bytes / T);
}
if ($bytes > G) {
return sprintf("%.2f GiB", $bytes / G);
}
if ($bytes > M) {
return sprintf("%.2f MiB", $bytes / M);
}
if ($bytes > K) {
return sprintf("%.2f KiB", $bytes / K);
}
return "$bytes B";
}
# build up command for $command
# returns open filehandle to process output
# if command fails, program is exited (caller needs not to worry)
sub cmd {
my ($this, $command, $cb) = @_;
# build up command
my @CMD = $this->{program};
# add sudo if program needs
unshift(@CMD, $this->{sudo}) if $> and $this->{sudo};
my $args = $this->{commands}{$command} or croak "command '$command' not defined";
# callback to replace args in command
my $cb_ = sub {
my $param = shift;
if ($cb) {
if (ref $cb eq 'HASH' and exists $cb->{$param}) {
return wantarray ? @{$cb->{$param}} : $cb->{$param};
}
return &$cb($param) if ref $cb eq 'CODE';
}
if ($param eq '@CMD') {
# command wanted, but not found
croak "Command for $this->{name} not found" unless defined $this->{program};
return @CMD;
}
return $param;
};
# add command arguments
my @cmd;
for my $arg (@$args) {
local $_ = $arg;
# can't do arrays with s///
# this limits that @arg must be single argument
if (/@/) {
push(@cmd, $cb_->($_));
} else {
s/([\$]\w+)/$cb_->($1)/ge;
push(@cmd, $_);
}
}
my $op = shift @cmd;
my $fh;
if ($op eq '=' and ref $cb eq 'SCALAR') {
# Special: use open2
use IPC::Open2;
warn "DEBUG EXEC: $op @cmd" if $utils::debug;
my $pid = open2($fh, $$cb, @cmd) or croak "open2 failed: @cmd: $!";
} elsif ($op eq '>&2') {
# Special: same as '|-' but reads both STDERR and STDOUT
use IPC::Open3;
warn "DEBUG EXEC: $op @cmd" if $utils::debug;
my $pid = open3(undef, $fh, $cb, @cmd);
} else {
warn "DEBUG EXEC: @cmd" if $utils::debug;
open($fh, $op, @cmd) or croak "open failed: @cmd: $!";
}
# for dir handles, reopen as opendir
if (-d $fh) {
undef($fh);
warn "DEBUG OPENDIR: $cmd[0]" if $utils::debug;
opendir($fh, $cmd[0]) or croak "opendir failed: @cmd: $!";
}
return $fh;
}
} # package plugin
package lsscsi;
use base 'plugin';
push(@utils::plugins, __PACKAGE__);
sub program_names {
__PACKAGE__;
}
sub commands {
{
'lsscsi list' => ['-|', '@CMD', '-g'],
}
}
# scan lsscsi output
sub scan {
my $this = shift;
# Scan such output:
# [0:0:0:0] disk HP LOGICAL VOLUME 3.00 /dev/sda /dev/sg0
# [0:3:0:0] storage HP P410i 3.00 - /dev/sg1
# or without sg driver:
# [0:0:0:0] disk HP LOGICAL VOLUME 3.00 /dev/sda -
# [0:3:0:0] storage HP P410i 3.00 - -
my $fh = $this->cmd('lsscsi list');
my @sdevs;
while (<$fh>) {
chop;
if (my($hctl, $type, $vendor, $model, $rev, $devnode, $sgnode) = m{^
\[([\d:]+)\] # SCSI Controller, SCSI bus, SCSI target, and SCSI LUN
\s+(\S+) # type
\s+(\S+) # vendor
\s+(.*?) # model, match everything as it may contain spaces
\s+(\S+) # revision
\s+((?:/dev/\S+|-)) # /dev node
\s+((?:/dev/\S+|-)) # /dev/sg node
}x) {
push(@sdevs, {
'hctl' => $hctl,
'type' => $type,
'vendor' => $vendor,
'model' => $model,
'rev' => $rev,
'devnode' => $devnode,
'sgnode' => $sgnode,
});
}
}
close $fh;
return wantarray ? @sdevs : \@sdevs;
}
package metastat;
# Solaris, software RAID
use base 'plugin';
# Status: BROKEN: no test data
#push(@utils::plugins, __PACKAGE__);
sub program_names {
__PACKAGE__;
}
sub commands {
{
'status' => ['-|', '@CMD'],
}
}
sub sudo {
my $cmd = shift->{program};
"CHECK_RAID ALL=(root) NOPASSWD: $cmd"
}
sub check {
my $this = shift;
my ($d, $sd);
# status messages pushed here
my @status;
my $fh = $this->cmd('status');
while (<$fh>) {
if (/^(\S+):/) { $d = $1; $sd = ''; next; }
if (/Submirror \d+:\s+(\S+)/) { $sd = $1; next; }
if (my($s) = /State: (\S.+)/) {
if ($sd and valid($sd) and valid($d)) {
if ($s =~ /Okay/i) {
# no worries...
} elsif ($s =~ /Resync/i) {
$this->warning;
} else {
$this->critical;
}
push(@status, "$d:$sd:$s");
}
}
}
close $fh;
return unless @status;
$this->message(join(' ', @status));
}
package megaide;
# MegaIDE RAID controller
use base 'plugin';
# register
# Status: BROKEN: no test data
#push(@utils::plugins, __PACKAGE__);
sub sudo {
my $cat = utils::which('cat');
"CHECK_RAID ALL=(root) NOPASSWD: $cat /proc/megaide/0/status";
}
sub check {
my $this = shift;
my $fh;
# status messages pushed here
my @status;
foreach my $f (</proc/megaide/*/status>) { # / silly comment to fix vim syntax hilighting
if (-r $f) {
open $fh, '<', $f or next;
=cut
} else {
my @CMD = ($cat, $f);
unshift(@CMD, $sudo) if $> and $sudo;
open($fh , '-|', @CMD) or next;
=cut
}
while (<$fh>) {
next unless (my($s, $n) = /Status\s*:\s*(\S+).*Logical Drive.*:\s*(\d+)/i);
next unless $this->valid($n);
if ($s ne 'ONLINE') {
$this->critical;
push(@status, "$n:$s");
} else {
push(@status, "$n:$s");
}
last;
}
close $fh;
}
return unless @status;
$this->message(join(' ', @status));
}
package mdstat;
# Linux Multi-Device (md)
use base 'plugin';
# register
push(@utils::plugins, __PACKAGE__);
sub commands {
{
'mdstat' => ['<', '/proc/mdstat'],
}
}
sub active ($) {
my ($this) = @_;
# easy way out. no /proc/mdstat
return 0 unless -e $this->{commands}{mdstat}[1];
# extra check if mdstat is empty
my @md = $this->parse;
return $#md >= 0;
}
sub parse {
my $this = shift;
my (@md, %md);
my $fh = $this->cmd('mdstat');
while (<$fh>) {
chomp;
# md1 : active raid1 sdb2[0] sda2[1]
if (my($d, $p) = /^(\S+)\s+:\s+(?:\S+)\s+(\S+)\s+/) {
# first line resets %md
%md = (dev => $d, personality => $p);
@{$md{failed_disks}} = $_ =~ m/(\S+)\[\d+\]\(F\)/g;
next;
}
# linux-2.6.33/drivers/md/dm-raid1.c, device_status_char
# A => Alive - No failures
# D => Dead - A write failure occurred leaving mirror out-of-sync
# S => Sync - A sychronization failure occurred, mirror out-of-sync
# R => Read - A read failure occurred, mirror data unaffected
# U => for the rest
#" 8008320 blocks [2/2] [UU]"
#" 58291648 blocks 64k rounding" - linear
if (my($b, $s) = /^\s+(\d+)\sblocks\s+.*?(?:\s+\[([ADSRU_]+)\])?$/) {
$md{status} = $s;
$md{blocks} = $b;
next;
}
# linux-2.6.33/drivers/md/md.c, md_seq_show
if (my($action) = m{(resync=(?:PENDING|DELAYED))}) {
$md{resync_status} = $action;
next;
}
# linux-2.6.33/drivers/md/md.c, status_resync
# [==>..................] resync = 13.0% (95900032/732515712) finish=175.4min speed=60459K/sec
# [=>...................] check = 8.8% (34390144/390443648) finish=194.2min speed=30550K/sec
if (my($action, $perc, $eta, $speed) = m{(resync|recovery|reshape)\s+=\s+([\d.]+%) \(\d+/\d+\) finish=([\d.]+min) speed=(\d+K/sec)}) {
$md{resync_status} = "$action:$perc $speed ETA: $eta";
next;
}
# we need empty line denoting end of one md
next unless /^\s*$/;
next unless $this->valid($md{dev});
push(@md, { %md } ) if %md;
}
close $fh;
return wantarray ? @md : \@md;
}
sub check {
my $this = shift;
my (@status);
my @md = $this->parse;
foreach (@md) {
my %md = %$_;
# common status
my $size = $this->format_bytes($md{blocks} * 1024);
my $s = "$md{dev}($size $md{personality}):";
# raid0 is just there or its not. raid0 can't degrade.
# same for linear, no $md_status available
if ($md{personality} =~ /linear|raid0/) {
$s .= "OK";
} elsif ($md{resync_status}) {
$this->warning;
$s .= "$md{status} ($md{resync_status})";
} elsif ($md{status} =~ /_/) {
$this->critical;
$s .= "F:". join(",", @{$md{failed_disks}}) .":$md{status}";
} elsif (@{$md{failed_disks}} > 0) {
# FIXME: this is same as above?
$this->warning;
$s .= "hot-spare failure:". join(",", @{$md{failed_disks}}) .":$md{status}";
} else {
$s .= "$md{status}";
}
push(@status, $s);
}
return unless @status;
# denote this plugin as ran ok
$this->ok;
$this->message(join(', ', @status));
}
package lsraid;
# Linux, software RAID
use base 'plugin';
# register
# Broken: missing test data
#push(@utils::plugins, __PACKAGE__);
sub program_names {
__PACKAGE__;
}
sub commands {
{
'list' => ['-|', '@CMD', '-A', '-p'],
}
}
sub sudo {
my ($this, $deep) = @_;
# quick check when running check
return 1 unless $deep;
my $cmd = $this->{program};
"CHECK_RAID ALL=(root) NOPASSWD: $cmd -A -p"
}
sub check {
my $this = shift;
# status messages pushed here
my @status;
my $fh = $this->cmd('list');
while (<$fh>) {
next unless (my($n, $s) = m{/dev/(\S+) \S+ (\S+)});
next unless $this->valid($n);
if ($s =~ /good|online/) {
# no worries
} elsif ($s =~ /sync/) {
$this->warning;
} else {
$this->critical;
}
push(@status, "$n:$s");
}
close $fh;
return unless @status;
$this->message(join(', ', @status));
}
package megacli;
# MegaRAID SAS 8xxx controllers
# based on info from here:
# http://www.bxtra.net/Articles/2008-09-16/Dell-Perc6i-RAID-Monitoring-Script-using-MegaCli-LSI-CentOS-52-64-bits
# TODO: http://www.techno-obscura.com/~delgado/code/check_megaraid_sas
# TODO: process several adapters
# TODO: process drive temperatures
# TODO: check error counts
# TODO: hostspare information
use base 'plugin';
# register
push(@utils::plugins, __PACKAGE__);
sub program_names {
qw(MegaCli64 MegaCli megacli);
}
sub commands {
{
'pdlist' => ['-|', '@CMD', '-PDList', '-aALL', '-NoLog'],
'ldinfo' => ['-|', '@CMD', '-LdInfo', '-Lall', '-aALL', '-NoLog'],
}
}
# TODO: process from COMMANDS
sub sudo {
my ($this, $deep) = @_;
# quick check when running check
return 1 unless $deep;
my $cmd = $this->{program};
(
"CHECK_RAID ALL=(root) NOPASSWD: $cmd -PDList -aALL -NoLog",
"CHECK_RAID ALL=(root) NOPASSWD: $cmd -LdInfo -Lall -aALL -NoLog",
);
}
sub check {
my $this = shift;
my $fh = $this->cmd('pdlist');
my (@status, @devs, @vols, %cur, %cur_vol);
while (<$fh>) {
if (my($s) = /Device Id: (\S+)/) {
push(@devs, { %cur }) if %cur;
%cur = ( dev => $s, state => undef, name => undef );
next;
}
if (my($s) = /Firmware state: (.+)/) {
# strip the extra state:
# 'Hotspare, Spun Up'
# 'Hotspare, Spun down'
# 'Online, Spun Up'
# 'Online, Spun Up'
# 'Online, Spun down'
# 'Unconfigured(bad)'
# 'Unconfigured(good), Spun Up'
# 'Unconfigured(good), Spun down'
$s =~ s/,.+//;
$cur{state} = $s;
next;
}
if (my($s) = /Inquiry Data: (.+)/) {
# trim some spaces
$s =~ s/\s+/ /g; $s =~ s/^\s+|\s+$//g;
$cur{name} = $s;
next;
}
}
close $fh;
push(@devs, { %cur }) if %cur;
$fh = $this->cmd('ldinfo');
while (<$fh>) {
if (my($s) = /Name\s*:\s*(\S+)/) {
push(@vols, { %cur_vol }) if %cur_vol;
%cur_vol = ( name => $s, state => undef );
next;
}
if (my($s) = /State\s*:\s*(\S+)/) {
$cur_vol{state} = $s;
next;
}
}
close $fh;
push(@vols, { %cur_vol }) if %cur_vol;
my @vstatus;
foreach my $vol (@vols) {
# It's possible to create volumes without a name
if (!$vol->{name}) {
$vol->{name} = 'NoName';
}
push(@vstatus, sprintf "%s:%s", $vol->{name}, $vol->{state});
if ($vol->{state} ne 'Optimal') {
$this->critical;
}
}
my %dstatus;
foreach my $dev (@devs) {
if ($dev->{state} eq 'Online' || $dev->{state} eq 'Hotspare' || $dev->{state} eq 'Unconfigured(good)') {
push(@{$dstatus{$dev->{state}}}, sprintf "%02d", $dev->{dev});
} else {
$this->critical;
# TODO: process other statuses
push(@{$dstatus{$dev->{state}}}, sprintf "%02d (%s)", $dev->{dev}, $dev->{name});
}
}
push(@status,
'Volumes(' . ($#vols + 1) . '): ' . join(',', @vstatus) .
'; Devices('. ($#devs + 1) . '): ' . $this->join_status(\%dstatus));
return unless @status;
# denote this plugin as ran ok
$this->ok;
$this->message(join(' ', @status));
}
package lsvg;
# AIX LVM
use base 'plugin';
# register
# Status: broken (no test data)
#push(@utils::plugins, __PACKAGE__);
sub program_names {
__PACKAGE__;
}
sub commands {
{
'lsvg' => ['-|', '@CMD'],
'lsvg list' => ['-|', '@CMD', '-l', '$vg'],
}
}
sub sudo {
my ($this, $deep) = @_;
# quick check when running check
return 1 unless $deep;
my $cmd = $this->{program};
(
"CHECK_RAID ALL=(root) NOPASSWD: $cmd",
"CHECK_RAID ALL=(root) NOPASSWD: $cmd -l *",
)
}
sub check {
my $this = shift;
# status messages pushed here
my @status;
my @vg;
my $fh = $this->cmd('lsvg');
while (<$fh>) {
chomp;
push @vg, $_;
}
close $fh;
foreach my $vg (@vg) {
next unless $this->valid($vg); # skip entire VG
my $fh = $this->cmd('lsvg list', { '$vg' => $vg });
while (<$fh>) {
my @f = split /\s/;
my ($n, $s) = ($f[0], $f[5]);
next if (!$this->valid($n) or !$s);
next if ($f[3] eq $f[2]); # not a mirrored LV
if ($s =~ m#open/(\S+)#i) {
$s = $1;
if ($s ne 'syncd') {
$this->critical;
}
push(@status, "lvm:$n:$s");
}
}
close $fh;
}
return unless @status;
$this->message(join(', ', @status));
}
package ips;
# Serveraid IPS
# Tested on IBM xSeries 346 servers with Adaptec ServeRAID 7k controllers.
# The ipssend version was v7.12.14.
use base 'plugin';
# register
push(@utils::plugins, __PACKAGE__);
sub program_names {
qw(ipssend);
}
sub commands {
{
'list logical drive' => ['-|', '@CMD', 'GETCONFIG', '1', 'LD'],
}
}
sub sudo {
my ($this, $deep) = @_;
# quick check when running check
return 1 unless $deep;
my $cmd = $this->{program};
"CHECK_RAID ALL=(root) NOPASSWD: $cmd getconfig 1 LD"
}
sub check {
my $this = shift;
# status messages pushed here
my @status;
my $n;
my $fh = $this->cmd('list logical drive');
while (<$fh>) {
if (/drive number (\d+)/i){
$n = $1;
next;
}
next unless $n;
next unless $this->valid($n);
next unless (my($s, $c) = /Status .*: (\S+)\s+(\S+)/);
if ($c =~ /SYN|RBL/i ) { # resynching
$this->warning;
} elsif ($c !~ /OKY/i) { # not OK
$this->critical;
}
push(@status, "$n:$s");
}
close $fh;
return unless @status;
$this->ok->message(join(', ', @status));
}
package aaccli;
# Adaptec ServeRAID
use base 'plugin';
# register
push(@utils::plugins, __PACKAGE__);
sub program_names {
__PACKAGE__;
}
sub commands {
{
'container list' => ['=', '@CMD'],
}
}
sub sudo {
my ($this, $deep) = @_;
# quick check when running check
return 1 unless $deep;
my $cmd = $this->{program};
"CHECK_RAID ALL=(root) NOPASSWD: $cmd container list /full"
}
sub check {
my $this = shift;
# status messages pushed here
my @status;
my $write = "";
$write .= "open aac0\n";
$write .= "container list /full\n";