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

« back to all changes in this revision

Viewing changes to check_hpasm/check_hpasm-4.6.3/plugins-scripts/HP/Proliant/Component/MemorySubsystem.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::MemorySubsystem;
 
2
our @ISA = qw(HP::Proliant::Component);
 
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
    runtime => $params{runtime},
 
12
    rawdata => $params{rawdata},
 
13
    method => $params{method},
 
14
    condition => $params{condition},
 
15
    status => $params{status},
 
16
    blacklisted => 0,
 
17
    info => undef,
 
18
    extendedinfo => undef,
 
19
    dimms => [],
 
20
  };
 
21
  bless $self, $class;
 
22
  if ($self->{method} eq 'snmp') {
 
23
    return HP::Proliant::Component::MemorySubsystem::SNMP->new(%params);
 
24
  } elsif ($self->{method} eq 'cli') {
 
25
    return HP::Proliant::Component::MemorySubsystem::CLI->new(%params);
 
26
  } else {
 
27
    die "unknown method";
 
28
  }
 
29
}
 
30
 
 
31
sub check {
 
32
  my $self = shift;
 
33
  my $errorfound = 0;
 
34
  $self->add_info('checking memory');
 
35
  foreach (@{$self->{dimms}}) {
 
36
    $_->check(); # info ausfuellen
 
37
  }
 
38
  if ((scalar(grep {
 
39
      $_->is_present() && 
 
40
      ($_->{condition} ne 'n/a' && $_->{condition} ne 'other' ) 
 
41
  } @{$self->{dimms}})) != 0) {
 
42
    foreach (@{$self->{dimms}}) {
 
43
      if (($_->is_present()) && ($_->{condition} ne 'ok')) {
 
44
        $_->add_message(CRITICAL, $_->{info});
 
45
        $errorfound++;
 
46
      }
 
47
    }
 
48
  } else {
 
49
    if ($self->{runtime}->{options}->{ignore_dimms}) {
 
50
      $self->add_message(OK,
 
51
          sprintf "ignoring %d dimms with status 'n/a' ",
 
52
          scalar(grep { ($_->is_present()) } @{$self->{dimms}}));
 
53
    } elsif ($self->{runtime}->{options}->{buggy_firmware}) {
 
54
      $self->add_message(OK,
 
55
          sprintf "ignoring %d dimms with status 'n/a' because of buggy firmware",
 
56
          scalar(grep { ($_->is_present()) } @{$self->{dimms}}));
 
57
    } else {
 
58
      $self->add_message(WARNING,
 
59
        sprintf "status of all %d dimms is n/a (please upgrade firmware)",
 
60
        scalar(grep { $_->is_present() } @{$self->{dimms}}));
 
61
        $errorfound++;
 
62
    }
 
63
  }
 
64
  foreach (@{$self->{dimms}}) {
 
65
    printf "%s\n", $_->{info} if $self->{runtime}->{options}->{verbose} >= 2;
 
66
  }
 
67
  if (! $errorfound && $self->is_faulty()) {
 
68
  #if ($self->is_faulty()) {
 
69
    $self->add_message(WARNING,
 
70
        sprintf 'overall memory error found');
 
71
  }
 
72
}
 
73
 
 
74
sub dump {
 
75
  my $self = shift;
 
76
 printf "i dump the memory\n";
 
77
  foreach (@{$self->{dimms}}) {
 
78
    $_->dump();
 
79
  }
 
80
}
 
81
 
 
82
package HP::Proliant::Component::MemorySubsystem::Dimm;
 
83
our @ISA = qw(HP::Proliant::Component::MemorySubsystem);
 
84
 
 
85
use strict;
 
86
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
 
87
 
 
88
sub new {
 
89
  my $class = shift;
 
90
  my %params = @_;
 
91
  my $self = {
 
92
    runtime => $params{runtime},
 
93
    cartridge => $params{cartridge},
 
94
    module => $params{module},
 
95
    size => $params{size} || 0,
 
96
    status => $params{status},
 
97
    condition => $params{condition},
 
98
    type => $params{type},
 
99
    blacklisted => 0,
 
100
    info => undef,
 
101
    extendedinfo => undef,
 
102
  };
 
103
  bless $self, $class;
 
104
  $self->{name} = sprintf '%s:%s',
 
105
      $self->{cartridge}, $self->{module};
 
106
  $self->{location} = sprintf 'module %s @ cartridge %s',
 
107
      $self->{module}, $self->{cartridge};
 
108
  return $self;
 
109
}  
 
110
 
 
111
sub check {
 
112
  my $self = shift;
 
113
  # check dient nur dazu, info und extended_info zu f�llen
 
114
  # die eigentliche bewertung findet eins h�her statt
 
115
  $self->blacklist('d', $self->{name});
 
116
  if (($self->{status} eq 'present') || ($self->{status} eq 'good')) {
 
117
    if ($self->{condition} eq 'other') {
 
118
      $self->add_info(sprintf 'dimm %s (%s) is n/a',
 
119
          $self->{name}, $self->{location});
 
120
    } elsif ($self->{condition} ne 'ok') {
 
121
      $self->add_info(
 
122
        sprintf "dimm module %s (%s) needs attention (%s)",
 
123
        $self->{name}, $self->{location}, $self->{condition});
 
124
    } else {
 
125
      $self->add_info(sprintf 'dimm module %s (%s) is %s',
 
126
          $self->{name}, $self->{location}, $self->{condition});
 
127
    }
 
128
  } elsif ($self->{status} eq 'notPresent') {
 
129
    $self->add_info(sprintf 'dimm module %s (%s) is not present',
 
130
        $self->{name}, $self->{location});
 
131
  } else {
 
132
    $self->add_info(
 
133
      sprintf "dimm module %s (%s) needs attention (%s)",
 
134
      $self->{name}, $self->{location}, $self->{condition});
 
135
  }
 
136
}
 
137
 
 
138
sub is_present {
 
139
  my $self = shift;
 
140
  my @signs_of_presence = (qw(present good add upgraded doesnotmatch 
 
141
      notsupported badconfig degraded));
 
142
  return scalar(grep { $self->{status} eq $_ } @signs_of_presence);
 
143
}
 
144
 
 
145
 
 
146
sub dump {
 
147
  my $self = shift;
 
148
  #printf "[DIMM_%s_%s]\n", $self->{cartridge}, $self->{module};
 
149
  #foreach (qw(cartridge module size status condition info)) {
 
150
  #  printf "%s: %s\n", $_, $self->{$_};
 
151
  #}
 
152
  #printf "status: %s\n", $self->{status} if exists $self->{status};
 
153
  #printf "\n";
 
154
  printf "car %02d  mod %02d  siz %.0f  sta %-12s  con %-10s  typ %s\n",
 
155
    $self->{cartridge}, $self->{module}, $self->{size}, 
 
156
    $self->{status}, $self->{condition}, defined $self->{type} ? $self->{type} : "";
 
157
}
 
158
 
 
159
 
 
160
package HP::Proliant::Component::MemorySubsystem::Cartridge;
 
161
our @ISA = qw(HP::Proliant::Component::MemorySubsystem);
 
162
 
 
163
use strict;
 
164
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
 
165
 
 
166
sub new {
 
167
  my $class = shift;
 
168
  my %params = @_;
 
169
  my $self = {
 
170
    cpqHeResMemBoardSlotIndex => $params{cpqHeResMemBoardSlotIndex},
 
171
    cpqHeResMemBoardOnlineStatus => $params{cpqHeResMemBoardOnlineStatus},
 
172
    cpqHeResMemBoardErrorStatus => $params{cpqHeResMemBoardErrorStatus},
 
173
    cpqHeResMemBoardNumSockets => $params{cpqHeResMemBoardNumSockets},
 
174
    cpqHeResMemBoardOsMemSize => $params{cpqHeResMemBoardOsMemSize},
 
175
    cpqHeResMemBoardTotalMemSize => $params{cpqHeResMemBoardTotalMemSize},
 
176
    cpqHeResMemBoardCondition => $params{cpqHeResMemBoardCondition},
 
177
    blacklisted => 0,
 
178
    info => undef,
 
179
    extendedinfo => undef,
 
180
  };
 
181
  bless $self, $class;
 
182
  return $self;
 
183
}  
 
184
 
 
185
sub dump {
 
186
  my $self = shift;
 
187
  #printf "[CARTRIDGE_%s_%s]\n", $self->{cpqHeResMemBoardSlotIndex};
 
188
  #foreach (qw(cpqHeResMemBoardSlotIndex cpqHeResMemBoardOnlineStatus
 
189
  #    cpqHeResMemBoardErrorStatus cpqHeResMemBoardNumSockets
 
190
  #    cpqHeResMemBoardOsMemSize cpqHeResMemBoardTotalMemSize
 
191
  #    cpqHeResMemBoardCondition)) {
 
192
  #  printf "%s: %s\n", $_, $self->{$_};
 
193
  #}
 
194
  #printf "\n";
 
195
}
 
196
 
 
197