-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_raid
executable file
·6462 lines (5377 loc) · 264 KB
/
check_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
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
# nagios: -epn
# This chunk of stuff was generated by App::FatPacker. To find the original
# file's code, look for the end of this BEGIN block or the string 'FATPACK'
BEGIN {
my %fatpacked;
$fatpacked{"App/Monitoring/Plugin/CheckRaid.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_MONITORING_PLUGIN_CHECKRAID';
package App::Monitoring::Plugin::CheckRaid;
use Carp qw(croak);
use Module::Pluggable 5.1 instantiate => 'new', sub_name => '_plugins';
use strict;
use warnings;
# constructor
sub new {
my $class = shift;
croak 'Odd number of elements in argument hash' if @_ % 2;
my $self = {
@_,
};
my $obj = bless $self, $class;
# setup search path for Module::Pluggable
$self->search_path(add => __PACKAGE__ . '::Plugins');
# setup only certain plugins
if ($self->{enable_plugins}) {
my @plugins = map {
__PACKAGE__ . '::Plugins::' . $_
} @{$self->{enable_plugins}};
$self->only(\@plugins);
}
return $obj;
}
# create list of plugins
sub plugins {
my ($this) = @_;
# call this once
if (!defined $this->{plugins}) {
my @plugins = $this->_plugins(%$this);
$this->{plugins} = \@plugins;
}
wantarray ? @{$this->{plugins}} : $this->{plugins};
}
# get plugin by name
sub plugin {
my ($this, $name) = @_;
if (!defined $this->{plugin_names}) {
my %names;
foreach my $plugin ($this->plugins) {
my $name = $plugin->{name};
$names{$name} = $plugin;
}
$this->{plugin_names} = \%names;
}
croak "Plugin '$name' Can not be created" unless exists $this->{plugin_names}{$name};
$this->{plugin_names}{$name};
}
# Get active plugins.
# Returns the plugin objects
sub active_plugins {
my $this = shift;
my @plugins = ();
# go over all registered plugins
foreach my $plugin ($this->plugins) {
# skip if no check method (not standalone checker)
next unless $plugin->can('check');
# skip inactive plugins (disabled or no tools available)
next unless $plugin->active;
push(@plugins, $plugin);
}
return wantarray ? @plugins : \@plugins;
}
1;
APP_MONITORING_PLUGIN_CHECKRAID
$fatpacked{"App/Monitoring/Plugin/CheckRaid/Plugin.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_MONITORING_PLUGIN_CHECKRAID_PLUGIN';
package App::Monitoring::Plugin::CheckRaid::Plugin;
use Carp qw(croak);
use App::Monitoring::Plugin::CheckRaid::Utils;
use strict;
use warnings;
# Nagios standard error codes
my (%ERRORS) = (OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3);
# default plugin options
our %options = (
# status to set when RAID is in resync state
resync_status => $ERRORS{WARNING},
# Status code to use when no raid volumes were detected
noraid_status => $ERRORS{UNKNOWN},
# status to set when RAID is in check state
check_status => $ERRORS{OK},
# status to set when PD is spare
spare_status => $ERRORS{OK},
# status to set when BBU is in learning cycle.
bbulearn_status => $ERRORS{WARNING},
# status to set when Write Cache has failed.
cache_fail_status => $ERRORS{WARNING},
# check status of BBU
bbu_monitoring => 0,
);
# 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;
croak 'Class is already a reference' if ref $class;
# convert to hash
my %args = @_;
# merge 'options' from param and class defaults
my %opts = %options;
%opts = (%options, %{$args{options}}) if $args{options};
delete $args{options};
# merge commands
my %commands = %{$class->commands};
%commands = (%commands, %{$args{commands}}) if $args{commands};
delete $args{commands};
my $self = {
commands => \%commands,
sudo => $class->sudo ? find_sudo() : '',
options => \%opts,
%args,
# name of the plugin, without package namespace
name => ($class =~ /.*::([^:]+)$/),
status => undef,
message => undef,
perfdata => undef,
longoutput => undef,
};
my $this = bless $self, $class;
# lookup program, if not defined by params
if (!$self->{program}) {
$self->{program} = which($this->program_names);
}
return $this;
}
# see if plugin is active (disabled or no tools available)
sub active {
my $this = shift;
# no tool found, return false
return 0 unless $this->{program};
# program file must exist, don't check for execute bit. #104
-f $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;
}
# helper to set status for resync
# returns $this to allow fluent api
sub resync {
my ($this) = @_;
$this->status($this->{options}{resync_status});
return $this;
}
# helper to set status for check
# returns $this to allow fluent api
sub check_status {
my ($this) = @_;
$this->status($this->{options}{check_status});
return $this;
}
# helper to set status for no raid condition
# returns $this to allow fluent api
sub noraid {
my ($this) = @_;
$this->status($this->{options}{noraid_status});
return $this;
}
# helper to set status for spare
# returns $this to allow fluent api
sub spare {
my ($this) = @_;
$this->status($this->{options}{spare_status});
return $this;
}
# helper to set status for BBU learning cycle
# returns $this to allow fluent api
sub bbulearn {
my ($this) = @_;
$this->status($this->{options}{bbulearn_status});
return $this;
}
# helper to set status when Write Cache fails
# returns $this to allow fluent api
sub cache_fail {
my ($this) = @_;
$this->status($this->{options}{cache_fail_status});
return $this;
}
# helper to get/set bbu monitoring
sub bbu_monitoring {
my ($this, $val) = @_;
if (defined $val) {
$this->{options}{bbu_monitoring} = $val;
}
$this->{options}{bbu_monitoring};
}
# setup status message text
sub message {
my ($this, $message) = @_;
if (defined $message) {
# TODO: append if already something there
$this->{message} = $message;
}
$this->{message};
}
# Set performance data output.
sub perfdata {
my ($this, $perfdata) = @_;
if (defined $perfdata) {
# TODO: append if already something there
$this->{perfdata} = $perfdata;
}
$this->{perfdata};
}
# Set plugin long output.
sub longoutput {
my ($this, $longoutput) = @_;
if (defined $longoutput) {
# TODO: append if already something there
$this->{longoutput} = $longoutput;
}
$this->{longoutput};
}
# 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";
}
# disable sudo temporarily
sub nosudo_cmd {
my ($this, $command, $cb) = @_;
my ($res, @res);
my $sudo = $this->{sudo};
$this->{sudo} = 0;
if (wantarray) {
@res = $this->cmd($command, $cb);
} else {
$res = $this->cmd($command, $cb);
}
$this->{sudo} = $sudo;
return wantarray ? @res : $res;
}
# 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) = @_;
my $debug = $App::Monitoring::Plugin::CheckRaid::Utils::debug;
# 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 $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 $debug;
my $pid = open3(undef, $fh, $cb, @cmd);
} else {
warn "DEBUG EXEC: @cmd" if $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 $debug;
opendir($fh, $cmd[0]) or croak "opendir failed: @cmd: $!";
}
return $fh;
}
1;
APP_MONITORING_PLUGIN_CHECKRAID_PLUGIN
$fatpacked{"App/Monitoring/Plugin/CheckRaid/Plugins/aaccli.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_MONITORING_PLUGIN_CHECKRAID_PLUGINS_AACCLI';
package App::Monitoring::Plugin::CheckRaid::Plugins::aaccli;
# Adaptec ServeRAID
use base 'App::Monitoring::Plugin::CheckRaid::Plugin';
use strict;
use warnings;
sub program_names {
shift->{name};
}
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";
$write .= "exit\n";
my $read = $this->cmd('container list', \$write);
#File foo receiving all output.
#
#AAC0>
#COMMAND: container list /full=TRUE
#Executing: container list /full=TRUE
#Num Total Oth Stripe Scsi Partition Creation
#Label Type Size Ctr Size Usage C:ID:L Offset:Size State RO Lk Task Done% Ent Date Time
#----- ------ ------ --- ------ ------- ------ ------------- ------- -- -- ------- ------ --- ------ --------
# 0 Mirror 74.5GB Open 0:02:0 64.0KB:74.5GB Normal 0 051006 13:48:54
# /dev/sda Auth 0:03:0 64.0KB:74.5GB Normal 1 051006 13:48:54
#
#
#AAC0>
#COMMAND: logfile end
#Executing: logfile end
while (<$read>) {
if (my($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\S+\s+(\S+)/) {
next unless $this->valid($dsk);
$dsk =~ s#:#/#g;
next unless $this->valid($dsk);
push(@status, "$dsk:$stat");
$this->critical if ($stat eq "Broken");
$this->warning if ($stat eq "Rebuild");
$this->warning if ($stat eq "Bld/Vfy");
$this->critical if ($stat eq "Missing");
if ($stat eq "Verify") {
$this->resync;
}
$this->warning if ($stat eq "VfyRepl");
}
}
close $read;
return unless @status;
$this->message(join(', ', @status));
}
1;
APP_MONITORING_PLUGIN_CHECKRAID_PLUGINS_AACCLI
$fatpacked{"App/Monitoring/Plugin/CheckRaid/Plugins/afacli.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_MONITORING_PLUGIN_CHECKRAID_PLUGINS_AFACLI';
package App::Monitoring::Plugin::CheckRaid::Plugins::afacli;
# Adaptec AACRAID
use base 'App::Monitoring::Plugin::CheckRaid::Plugin';
use strict;
use warnings;
sub program_names {
shift->{name};
}
sub commands {
{
'container list' => ['=', '@CMD'],
}
}
sub check {
my $this = shift;
# status messages pushed here
my @status;
my $write = "";
$write .= "open afa0\n";
$write .= "container list /full\n";
$write .= "exit\n";
my $read = $this->cmd('container list', \$write);
while (<$read>) {
# 0 Mirror 465GB Valid 0:00:0 64.0KB: 465GB Normal 0 032511 17:55:06
# /dev/sda root 0:01:0 64.0KB: 465GB Normal 1 032511 17:55:06
if (my($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\s?\S+\s+(\S+)/) {
next unless $this->valid($dsk);
$dsk =~ s#:#/#g;
next unless $this->valid($dsk);
push(@status, "$dsk:$stat");
$this->critical if ($stat eq "Broken");
$this->warning if ($stat eq "Rebuild");
$this->warning if ($stat eq "Bld/Vfy");
$this->critical if ($stat eq "Missing");
if ($stat eq "Verify") {
$this->resync;
}
$this->warning if ($stat eq "VfyRepl");
}
}
close $read;
return unless @status;
$this->ok->message(join(', ', @status));
}
1;
APP_MONITORING_PLUGIN_CHECKRAID_PLUGINS_AFACLI
$fatpacked{"App/Monitoring/Plugin/CheckRaid/Plugins/arcconf.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_MONITORING_PLUGIN_CHECKRAID_PLUGINS_ARCCONF';
package App::Monitoring::Plugin::CheckRaid::Plugins::arcconf;
# Adaptec AAC-RAID
use base 'App::Monitoring::Plugin::CheckRaid::Plugin';
use strict;
use warnings;
sub program_names {
shift->{name};
}
sub commands {
{
'getstatus' => ['-|', '@CMD', 'GETSTATUS', '1'],
# 'nologs' does not exist in arcconf 6.50. #118
'getconfig' => ['-|', '@CMD', 'GETCONFIG', '$ctrl', 'AL'],
}
}
sub sudo {
my ($this, $deep) = @_;
# quick check when running check
return 1 unless $deep;
my $cmd = $this->{program};
(
"CHECK_RAID ALL=(root) NOPASSWD: $cmd GETSTATUS 1",
"CHECK_RAID ALL=(root) NOPASSWD: $cmd GETCONFIG * AL",
);
}
sub parse_error {
my ($this, $message) = @_;
warn "arcconf: parse error: $message";
$this->unknown->message("Parse Error: $message");
}
# parse GETSTATUS command
# parses
# - number of controllers
# - logical device tasks (if any running)
sub parse_status {
my ($this) = @_;
my $count = 0;
my $ok = 0;
my $fh = $this->cmd('getstatus');
my %s;
# controller task
my %task;
while (<$fh>) {
chomp;
# empty line or comment
next if /^$/ or /^#/;
# termination
if (/^Command completed successfully/) {
$ok = 1;
last;
}
if (my($c) = /^Controllers [Ff]ound: (\d+)/) {
$count = int($c);
next;
}
if (/^(\S.+) Task:$/) {
$task{type} = $1;
next;
}
if (/^\s+Logical device\s+: (\d+)/) {
$task{device} = $1;
} elsif (/^\s+Task ID\s+: (\d+)/) {
$task{id} = $1;
} elsif (/^\s+Current operation\s+: (.+)/) {
$task{operation} = $1;
} elsif (/^\s+Status\s+: (.+)/) {
$task{status} = $1;
} elsif (/^\s+Priority\s+: (.+)/) {
$task{priority} = $1;
} elsif (/^\s+Percentage complete\s+: (\d+)/) {
$task{percent} = $1;
} elsif (/^Invalid controller number/) {
;
} else {
warn "Unknown line: [$_]";
# FIXME: ->message() gets overwritten later on
$this->unknown->message("Unknown line: [$_]");
}
}
close($fh);
# Tasks seem to be Controller specific, but as we don't support over one controller, let it be global
$s{tasks} = { %task } if %task;
if ($count == 0) {
# if command completed, but no controllers,
# assume no hardware present
if (!$ok) {
$this->unknown->message("No controllers found!");
}
return undef;
}
$s{ctrl_count} = $count;
return \%s;
}
# parse GETCONFIG for all controllers
sub parse_config {
my ($this, $status) = @_;
my %c;
for (my $i = 1; $i <= $status->{ctrl_count}; $i++) {
$c{$i} = $this->parse_ctrl_config($i, $status->{ctrl_count});
}
return { controllers => \%c };
}
# parse GETCONFIG command for specific controller
sub parse_ctrl_config {
my ($this, $ctrl, $ctrl_count) = @_;
# Controller information, Logical/Physical device info
my ($ld, $ch, $pd);
my $res = { controller => {}, logical => [], physical => [] };
my $fh = $this->cmd('getconfig', { '$ctrl' => $ctrl });
my ($section, $subsection, $ok);
my %sectiondata = ();
# called when data for section needs to be processed
my $flush = sub {
my $method = 'process_' . lc($section);
$method =~ s/[.\s]+/_/g;
$this->$method($res, \%sectiondata);
%sectiondata = ();
};
my $subsection_reset = sub {
$ch = 0;
undef($ld);
undef($pd);
undef($subsection);
};
while (<$fh>) {
chomp;
# empty line or comment
if (/^$/ or /^#/) {
&$subsection_reset;
next;
}
if (/^Command completed successfully/) {
$ok = 1;
last;
}
if (my($c) = /^Controllers [Ff]ound: (\d+)/) {
if ($c != $ctrl_count) {
# internal error?!
$this->unknown->message("Controller count mismatch");
}
next;
}
# section start
if (/^---+/) {
if (my($s) = <$fh> =~ /^(\w.+)$/) {
# flush the lines
if (defined($section)) {
&$flush();
}
$section = $s;
unless (<$fh> =~ /^---+/) {
$this->parse_error($_);
}
&$subsection_reset;
next;
}
$this->parse_error($_);
}
# sub section start
# there are also sections in subsections, but currently section names
# are unique enough
if (/^\s+---+/) {
if (my($s) = <$fh> =~ /^\s+(\S.+?)\s*?$/) {
$subsection = $s;
unless (<$fh> =~ /^\s+---+/) {
$this->parse_error($_);
}
next;
}
$this->parse_error($_);
}
warn("SKIP without section: [$_]\n"),next unless defined $section;
# regex notes:
# - value portion may be missing
# - value may be empty
# - value may be truncated (t/data/arcconf/issue47/getconfig)
my ($key, $value) = /^\s*(.+?)(?:\s+:\s*(.*?))?$/;
if ($section =~ /Controller [Ii]nformation/) {
if (not defined $subsection) {
$sectiondata{$key} = $value;
} else {
$sectiondata{$subsection}{$key} = $value;
}
} elsif ($section =~ /Physical Device [Ii]nformation/) {
if (my($c) = /Channel #(\d+)/) {
$ch = int($c);
undef($pd);
next;
} elsif (my($n) = /^\s+Device #(\d+)/) {
$pd = int($n);
next;
} else {
if (not defined $pd) {
$sectiondata{$ch}{$key} = $value;
} elsif (not defined $subsection) {
$sectiondata{$ch}{'pd'}{$pd}{$key} = $value;
} else {
$sectiondata{$ch}{'pd'}{$pd}{$subsection}{$key} = $value;
}
}
} elsif ($section =~ /Logical ([Dd]evice|drive) [Ii]nformation/) {
if (my($n) = /Logical (?:[Dd]evice|drive) [Nn]umber (\d+)/) {
$ld = int($n);
} else {
# skip lone line: issue87/getconfig
if (/No logical devices configured/) {
next;
}
if (not defined $ld) {
warn "LD undefined:[$_]\n";
next;
}
if (not defined $subsection) {
$sectiondata{$ld}{$key} = $value;
} else {
$sectiondata{$ld}{$subsection}{$key} = $value;
}
}
} elsif ($section eq 'MaxCache 3.0 information') {
# not parsed yet
} elsif ($section eq 'Connector information') {
# not parsed yet
} else {
warn "NOT PARSED: [$section] [$_]";
}
}
close $fh;
&$flush() if $section;
$this->unknown->message("Command did not succeed") unless defined $ok;
return $res;
}
# Process Controller Information section
sub process_controller_information {
my ($this, $res, $data) = @_;
my $c = {};
my $s;
# current section
my $cs = $data;
$c->{status} = $cs->{'Controller Status'};
if (exists $cs->{$s = 'Defunct Disk Drive Count'} || exists $cs->{$s = 'Defunct disk drive count'}) {
$c->{defunct_count} = int($cs->{$s});
}
if ($s = $cs->{'Logical devices/Failed/Degraded'}) {
my($td, $fd, $dd) = $s =~ m{(\d+)/(\d+)/(\d+)};
$c->{logical_count} = int($td);
$c->{logical_failed} = int($fd);
$c->{logical_degraded} = int($dd);
}
# ARCCONF 9.30: Logical drives/Offline/Critical
if ($s = $cs->{'Logical drives/Offline/Critical'}) {
my($td2, $fd2, $dd2) = $s =~ m{(\d+)/(\d+)/(\d+)};
$c->{logical_count} = int($td2);
$c->{logical_offline} = int($fd2);
$c->{logical_critical} = int($dd2);
}
$cs = $data->{'Controller Battery Information'};
$c->{battery_status} = $cs->{Status} if exists $cs->{Status};
$c->{battery_overtemp} = $cs->{'Over temperature'} if exists $cs->{'Over temperature'};
if ($s = $cs->{'Capacity remaining'}) {
my ($bc) = $s =~ m{(\d+)\s*percent.*$};
$c->{battery_capacity} = int($bc);
}
if ($s = $cs->{'Time remaining (at current draw)'}) {
my($d, $h, $m) = $s =~ /(\d+) days, (\d+) hours, (\d+) minutes/;
$c->{battery_time} = int($d) * 1440 + int($h) * 60 + int($m);
$c->{battery_time_full} = "${d}d${h}h${m}m";
}
$cs = $data->{'Controller ZMM Information'};
$c->{zmm_status} = $cs->{Status} if exists $cs->{'Status'};
$res->{controller} = $c;
}
sub process_logical_device_information {
my ($this, $res, $data) = @_;
my $s;
my @ld;
while (my($ld, $cs) = each %$data) {
$ld[$ld]{id} = $ld;
if (exists $cs->{$s = 'RAID Level'} || exists $cs->{$s = 'RAID level'}) {
$ld[$ld]{raid} = $cs->{$s};
}
$ld[$ld]{size} = $cs->{'Size'};
$ld[$ld]{failed_stripes} = $cs->{'Failed stripes'} if exists $cs->{'Failed stripes'};
$ld[$ld]{defunct_segments} = $cs->{'Defunct segments'} if exists $cs->{'Defunct segments'};
if ($s = $cs->{'Status of Logical Device'} || $cs->{'Status of logical device'} || $cs->{'Status of logical drive'}) {
$ld[$ld]{status} = $s;
}
if ($s = $cs->{'Logical Device name'} || $cs->{'Logical device name'} || $cs->{'Logical drive name'}) {
$ld[$ld]{name} = $s;
}
# Write-cache mode : Not supported]
# Partitioned : Yes]
# Number of segments : 2]
# Drive(s) (Channel,Device) : 0,0 0,1]
# Defunct segments : No]
}
$res->{logical} = \@ld;
}