~ubuntu-branches/ubuntu/trusty/nagios-plugins-contrib/trusty-proposed

« back to all changes in this revision

Viewing changes to check_hpasm/check_hpasm-4.5.2/plugins-scripts/HP/Proliant/Component/DiskSubsystem/Da/CLI.pm

  • Committer: Package Import Robot
  • Author(s): Bernd Zeimetz
  • Date: 2013-05-21 22:11:50 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130521221150-k5bda5v5euvt7wg9
Tags: 6.20130521
* [e68c82e1] check_raid: do not run hpacucli if cciss_vol_status is available.
* [4a1c57e8] Also support tw-cli as additional name for the 3ware binary.
  Thanks to Dennis Hoppe
* [eb5e1c7c] Add /run/ to the check_libs ignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package HP::Proliant::Component::DiskSubsystem::Da::CLI;
2
 
our @ISA = qw(HP::Proliant::Component::DiskSubsystem::Da);
3
 
 
4
 
use strict;
5
 
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
6
 
 
7
 
sub new {
8
 
  my $class = shift;
9
 
  my %params = @_;
10
 
  my $self = {
11
 
    controllers => [],
12
 
    accelerators => [],
13
 
    physical_drives => [],
14
 
    logical_drives => [],
15
 
    spare_drives => [],
16
 
    blacklisted => 0,
17
 
  };
18
 
  bless $self, $class;
19
 
  return $self;
20
 
}
21
 
 
22
 
sub init {
23
 
  my $self = shift;
24
 
  my $hpacucli = $self->{rawdata};
25
 
  my $slot = 0;
26
 
  my $type = "unkn";
27
 
  my @lines = ();
28
 
  my $thistype = 0;
29
 
  my $tmpcntl = {};
30
 
  my $tmpaccel = {};
31
 
  my $tmpld = {};
32
 
  my $tmppd = {};
33
 
  my $cntlindex = 0;
34
 
  my $ldriveindex = 0;
35
 
  my $pdriveindex = 0;
36
 
  my $incontroller = 0;
37
 
  foreach (split(/\n/, $hpacucli)) {
38
 
    next unless /^status/;
39
 
    next if /^status\s*$/;
40
 
    s/^status\s*//;
41
 
    if (/([\s\w]+) in Slot\s+(\d+)/) {
42
 
      $incontroller = 1;
43
 
      $slot = $2;
44
 
      $cntlindex++;
45
 
      $tmpcntl->{$slot}->{cpqDaCntlrIndex} = $cntlindex;
46
 
      $tmpcntl->{$slot}->{cpqDaCntlrModel} = $1;
47
 
      $tmpcntl->{$slot}->{cpqDaCntlrSlot} = $slot;
48
 
    } elsif (/(MSA[\s\w]+)\s+in\s+(\w+)/) { 
49
 
      $incontroller = 1;
50
 
      $slot = $2;
51
 
      $cntlindex++;
52
 
      $tmpcntl->{$slot}->{cpqDaCntlrIndex} = $cntlindex;
53
 
      $tmpcntl->{$slot}->{cpqDaCntlrModel} = $1;
54
 
      $tmpcntl->{$slot}->{cpqDaCntlrSlot} = $slot;
55
 
    } elsif (/Controller Status: (\w+)/) {
56
 
      $tmpcntl->{$slot}->{cpqDaCntlrBoardCondition} = lc $1;
57
 
      $tmpcntl->{$slot}->{cpqDaCntlrCondition} = lc $1;
58
 
    } elsif (/Cache Status: ([\w\s]+\s*$)/) {
59
 
      # Cache Status: OK
60
 
      # Cache Status: Not Configured
61
 
      # Cache Status: Temporarily Disabled
62
 
      $tmpaccel->{$slot}->{cpqDaAccelCntlrIndex} = $cntlindex;
63
 
      $tmpaccel->{$slot}->{cpqDaAccelSlot} = $slot;
64
 
      #condition: other,ok,degraded,failed
65
 
      #status: other,invalid,enabled,tmpDisabled,permDisabled
66
 
      $tmpaccel->{$slot}->{cpqDaAccelCondition} = lc $1; 
67
 
      if ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'ok') {
68
 
        $tmpaccel->{$slot}->{cpqDaAccelStatus} = 'enabled';
69
 
      } elsif ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'not configured') {
70
 
        $tmpaccel->{$slot}->{cpqDaAccelCondition} = 'ok';
71
 
        $tmpaccel->{$slot}->{cpqDaAccelStatus} = 'enabled';
72
 
      } elsif ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'temporarily disabled') {
73
 
        $tmpaccel->{$slot}->{cpqDaAccelCondition} = 'ok';
74
 
        $tmpaccel->{$slot}->{cpqDaAccelStatus} = 'tmpDisabled';
75
 
      } elsif ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'permanently disabled') {
76
 
        $tmpaccel->{$slot}->{cpqDaAccelCondition} = 'ok';
77
 
        $tmpaccel->{$slot}->{cpqDaAccelStatus} = 'permDisabled';
78
 
      } else {
79
 
        $tmpaccel->{$slot}->{cpqDaAccelStatus} = 'enabled';
80
 
      }
81
 
    } elsif (/Battery.* Status: (\w+)/) {
82
 
      # sowas gibts auch Battery/Capacitor Status: OK
83
 
      $tmpaccel->{$slot}->{cpqDaAccelBattery} = lc $1;
84
 
    } elsif (/^\s*$/) {
85
 
    }
86
 
  }
87
 
  $cntlindex = 0;
88
 
  $ldriveindex = 0;
89
 
  $pdriveindex = 0;
90
 
  foreach (split(/\n/, $hpacucli)) {
91
 
    next unless /^config/;
92
 
    next if /^config\s*$/;
93
 
    s/^config\s*//;
94
 
    if (/([\s\w]+) in Slot\s+(\d+)/) {
95
 
      $slot = $2;
96
 
      $cntlindex++;
97
 
      $pdriveindex = 1;
98
 
    } elsif (/(MSA[\s\w]+)\s+in\s+(\w+)/) {
99
 
      $slot = $2;
100
 
      $cntlindex++;
101
 
      $pdriveindex = 1;
102
 
    } elsif (/logicaldrive\s+(.+?)\s+\((.*)\)/) {
103
 
      # logicaldrive 1 (683.5 GB, RAID 5, OK)
104
 
      # logicaldrive 1 (683.5 GB, RAID 5, OK)
105
 
      # logicaldrive 2 (442 MB, RAID 1+0, OK)
106
 
      $ldriveindex = $1;
107
 
      $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvCntlrIndex} = $cntlindex;
108
 
      $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvIndex} = $ldriveindex;
109
 
      ($tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvSize},
110
 
          $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvFaultTol},
111
 
          $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvCondition}) =
112
 
          map { lc $_ } split(/,\s*/, $2);
113
 
      $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvStatus} =
114
 
          $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvCondition};
115
 
      $tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvPhyDrvIDs} = 'unknown';
116
 
    } elsif (/physicaldrive\s+(.+?)\s+\((.*)\)/) {
117
 
      # physicaldrive 2:0   (port 2:id 0 , Parallel SCSI, 36.4 GB, OK)
118
 
      # physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 146 GB, OK)
119
 
      # physicaldrive 1:1 (box 1:bay 1, Parallel SCSI, 146 GB, OK)
120
 
      my $name = $1;
121
 
      my($location, $type, $size, $status) = split(/,/, $2);
122
 
      $status =~ s/^\s+//g;
123
 
      $status =~ s/\s+$//g;
124
 
      $status = lc $status;
125
 
      my %location = ();
126
 
      foreach (split(/:/, $location)) {
127
 
        $location{$1} = $2 if /(\w+)\s+(\w+)/;
128
 
      }
129
 
      $location{box} ||= 0;
130
 
      $location{id} ||= $pdriveindex;
131
 
      $location{bay} ||= $location{id};
132
 
      $location{port} ||= $location{bay};
133
 
      $tmppd->{$slot}->{$name}->{name} = lc $name;
134
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvCntlrIndex} = $cntlindex;
135
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvIndex} = $location{id};
136
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvBay} = $location{bay};
137
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvBusNumber} = $location{port};
138
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvSize} = $size;
139
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvStatus} = $status;
140
 
      $tmppd->{$slot}->{$name}->{cpqDaPhyDrvCondition} = $status;
141
 
      $tmppd->{$slot}->{$name}->{ldriveindex} = $ldriveindex || -1;
142
 
      foreach (keys %{$tmppd->{$slot}->{$name}}) {
143
 
        $tmppd->{$slot}->{$name}->{$_} =~ s/^\s+//g;
144
 
        $tmppd->{$slot}->{$name}->{$_} =~ s/\s+$//g;
145
 
        $tmppd->{$slot}->{$name}->{$_} = lc $tmppd->{$slot}->{$name}->{$_};
146
 
      }
147
 
      $pdriveindex++;
148
 
    }
149
 
  }
150
 
 
151
 
  foreach my $slot (keys %{$tmpcntl}) {
152
 
    if (exists $tmpcntl->{$slot}->{cpqDaCntlrModel} &&
153
 
        ! $self->identified($tmpcntl->{$slot}->{cpqDaCntlrModel})) {
154
 
      delete $tmpcntl->{$slot};
155
 
      delete $tmpaccel->{$slot};
156
 
      delete $tmpld->{$slot};
157
 
      delete $tmppd->{$slot};
158
 
    }
159
 
  }
160
 
 
161
 
#printf "%s\n", Data::Dumper::Dumper($tmpcntl);
162
 
#printf "%s\n", Data::Dumper::Dumper($tmpaccel);
163
 
#printf "%s\n", Data::Dumper::Dumper($tmpld);
164
 
#printf "%s\n", Data::Dumper::Dumper($tmppd);
165
 
  foreach my $slot (sort {
166
 
      $tmpcntl->{$a}->{cpqDaCntlrIndex} <=> $tmpcntl->{$b}->{cpqDaCntlrIndex}
167
 
      }keys %{$tmpcntl}) {
168
 
    $tmpcntl->{$slot}->{runtime} = $self->{runtime};
169
 
    push(@{$self->{controllers}},
170
 
        HP::Proliant::Component::DiskSubsystem::Da::Controller->new(
171
 
            %{$tmpcntl->{$slot}}));
172
 
  }
173
 
  foreach my $slot (sort {
174
 
      $tmpaccel->{$a}->{cpqDaAccelCntlrIndex} <=> $tmpaccel->{$b}->{cpqDaAccelCntlrIndex}
175
 
      } keys %{$tmpaccel}) {
176
 
    $tmpaccel->{$slot}->{runtime} = $self->{runtime};
177
 
    push(@{$self->{accelerators}},
178
 
        HP::Proliant::Component::DiskSubsystem::Da::Accelerator->new(
179
 
            %{$tmpaccel->{$slot}}));
180
 
  }
181
 
  foreach my $slot (keys %{$tmpld}) {
182
 
    foreach my $ldriveindex (keys %{$tmpld->{$slot}}) {
183
 
      $tmpld->{$slot}->{$ldriveindex}->{runtime} = $self->{runtime};
184
 
      push(@{$self->{logical_drives}},
185
 
          HP::Proliant::Component::DiskSubsystem::Da::LogicalDrive->new(
186
 
              %{$tmpld->{$slot}->{$ldriveindex}}));
187
 
    }
188
 
    foreach my $pdriveindex (sort {
189
 
        (split ':', $a, 2)[0] cmp (split ':', $b, 2)[0] ||
190
 
        (split ':', $a, 2)[1] cmp (split ':', $b, 2)[1] ||
191
 
        (split ':', $a, 2)[2] <=> (split ':', $b, 2)[2]
192
 
        } keys %{$tmppd->{$slot}}) {
193
 
      $tmppd->{$slot}->{$pdriveindex}->{runtime} = $self->{runtime};
194
 
      push(@{$self->{physical_drives}},
195
 
          HP::Proliant::Component::DiskSubsystem::Da::PhysicalDrive->new(
196
 
              %{$tmppd->{$slot}->{$pdriveindex}}));
197
 
    }
198
 
  }
199
 
}
200
 
 
201
 
sub identified {
202
 
  my $self = shift;
203
 
  my $info = shift;
204
 
  return 1 if $info =~ /Parallel SCSI/;
205
 
  return 1 if $info =~ /Smart Array/; # Trond: works fine on E200i, P400, E400
206
 
  return 1 if $info =~ /MSA500/;
207
 
  #return 1 if $info =~ /Smart Array (5|6)/;
208
 
  #return 1 if $info =~ /Smart Array P400i/; # snmp sagt Da, trotz SAS in cli
209
 
  #return 1 if $info =~ /Smart Array P410i/; # dto
210
 
  return 0;
211
 
}