Debian Codegraph @

check_hpasm/check_hpasm-4.9/plugins-scripts/HP/StorageWorks.pm

raw
1 package HP::StorageWorks;
2
3 use strict;
4 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
5 use Data::Dumper;
6
7 our @ISA = qw(HP::Server);
8
9 sub init {
10 my $self = shift;
11 $self->{serial} = 'unknown';
12 $self->{product} = 'unknown';
13 $self->{romversion} = 'unknown';
14 $self->collect();
15 if (! $self->{runtime}->{plugin}->check_messages()) {
16 $self->set_serial();
17 $self->overall_init();
18 $self->overall_check();
19 }
20 }
21
22 sub overall_init {
23 my $self = shift;
24 my %params = @_;
25 my $snmpwalk = $self->{rawdata};
26 my $cpqHoMibStatusArray = '1.3.6.1.4.1.232.11.2.10.1.0';
27 $self->{cpqHoMibStatusArray} = SNMP::Utils::get_object(
28 $snmpwalk, $cpqHoMibStatusArray);
29 if ($self->{cpqHoMibStatusArray} =~ /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
30 $self->{cpqHoMibStatusArray} = 1 * $2;
31 } elsif ($self->{cpqHoMibStatusArray} =~ /^0x.*(\d\d)(\d\d)(\d\d)(\d\d)$/) {
32 $self->{cpqHoMibStatusArray} = 1 * $2;
33 }
34 }
35
36 sub overall_check {
37 my $self = shift;
38 if ($self->{cpqHoMibStatusArray} == 4) {
39 $self->add_info('overall status is failed');
40 $self->add_message(CRITICAL, 'overall status is failed');
41 } elsif ($self->{cpqHoMibStatusArray} == 3) {
42 $self->add_info('overall status is degraded');
43 $self->add_message(WARNING, 'overall status is degraded');
44 } elsif ($self->{cpqHoMibStatusArray} == 2) {
45 $self->add_info('overall status is ok');
46 $self->add_message(OK, 'overall status is ok');
47 } elsif ($self->{cpqHoMibStatusArray} == 1) {
48 $self->add_info('overall status is other');
49 $self->add_message(UNKNOWN, 'overall status is other');
50 }
51 }
52
53 sub identify {
54 my $self = shift;
55 return $self->{productname};
56 }
57
58 sub dump {
59 my $self = shift;
60 printf STDERR "serial %s\n", $self->{serial};
61 printf STDERR "product %s\n", $self->{product};
62 printf STDERR "romversion %s\n", $self->{romversion};
63 printf STDERR "%s\n", Data::Dumper::Dumper($self->{components});
64 }
65
66 sub collect {
67 my $self = shift;
68 if ($self->{runtime}->{plugin}->opts->snmpwalk) {
69 my $cpqHoMibStatusArray = '1.3.6.1.4.1.232.11.2.10.1.0';
70 if (! exists $self->{rawdata}->{$cpqHoMibStatusArray}) {
71 $self->add_message(CRITICAL,
72 'snmpwalk returns no health data (cpqhost-mib)');
73 }
74 } else {
75 my $net_snmp_version = Net::SNMP->VERSION(); # 5.002000 or 6.000000
76 #$params{'-translate'} = [
77 # -all => 0x0
78 #];
79 my ($session, $error) =
80 Net::SNMP->session(%{$self->{runtime}->{snmpparams}});
81 if (! defined $session) {
82 $self->{plugin}->add_message(CRITICAL, 'cannot create session object');
83 $self->trace(1, Data::Dumper::Dumper($self->{runtime}->{snmpparams}));
84 }
85 if (! $self->{runtime}->{plugin}->check_messages()) {
86 # snmp peer is alive
87 $self->trace(2, sprintf "Protocol is %s",
88 $self->{runtime}->{snmpparams}->{'-version'});
89 my $cpqHoMibStatusArray = '1.3.6.1.4.1.232.11.2.10.1.0';
90 $session->translate;
91 my $tic = time;
92 my $response = $session->get_request(
93 -varbindlist => [$cpqHoMibStatusArray]
94 );
95 my $tac = time;
96 $self->trace(2, sprintf "%03d seconds for walk cpqHoMibStatusArray (%d oids)",
97 $tac - $tic, scalar(keys %{$response}));
98 $session->close;
99 map { $response->{$_} =~ s/^\s+//; $response->{$_} =~ s/\s+$//; }
100 keys %$response;
101 $self->{rawdata} = $response;
102 }
103 }
104 return $self->{runtime}->{plugin}->check_messages();
105 }
106
107 sub set_serial {
108 my $self = shift;
109 my $snmpwalk = $self->{rawdata};
110 my @serials = ();
111 my @models = ();
112 my @fws = ();
113 my $cpqSsBackplaneEntry = '1.3.6.1.4.1.232.8.2.2.6.1';
114 my $cpqSsBackplaneFWRev = '1.3.6.1.4.1.232.8.2.2.6.1.3';
115 my $cpqSsBackplaneModel = '1.3.6.1.4.1.232.8.2.2.6.1.9';
116 my $cpqSsBackplaneSerialNumber = '1.3.6.1.4.1.232.8.2.2.6.1.13';
117 # INDEX { cpqSsBackplaneChassisIndex, cpqSsBackplaneIndex }
118 my @indexes = SNMP::Utils::get_indices($snmpwalk,
119 $cpqSsBackplaneEntry);
120 foreach (@indexes) {
121 my($idx1, $idx2) = ($_->[0], $_->[1]);
122 my $fw = SNMP::Utils::get_object($snmpwalk,
123 $cpqSsBackplaneFWRev, $idx1, $idx2);
124 my $model = SNMP::Utils::get_object($snmpwalk,
125 $cpqSsBackplaneModel, $idx1, $idx2);
126 my $serial = SNMP::Utils::get_object($snmpwalk,
127 $cpqSsBackplaneSerialNumber, $idx1, $idx2);
128 push(@serials, $serial);
129 push(@models, $model);
130 push(@fws, $fw);
131 }
132
133 $self->{serial} = join('/', @serials);
134 $self->{product} = join('/', @models);
135 $self->{romversion} = join('/', @fws);
136 $self->{runtime}->{product} = $self->{product};
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 1;