Debian Codegraph @

src/storage/ibm/ts2900/snmp/mode/hardware.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package storage::ibm::ts2900::snmp::mode::hardware;
22
23 use base qw(centreon::plugins::templates::hardware);
24
25 sub set_system {
26 my ($self, %options) = @_;
27
28 $self->{cb_hook2} = 'snmp_execute';
29
30 $self->{thresholds} = {
31 default => [
32 ['unknown', 'UNKNOWN'],
33 ['ok', 'OK'],
34 ['warning', 'WARNING'],
35 ['failed', 'CRITICAL'],
36 ['needClean', 'WARNING'], # for drive only
37 ],
38 };
39
40 $self->{components_path} = 'storage::ibm::ts2900::snmp::mode::components';
41 $self->{components_module} = ['robot', 'drive', 'ctrl', 'ctrlpower', 'magazine'];
42 }
43
44 sub new {
45 my ($class, %options) = @_;
46 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1);
47 bless $self, $class;
48
49 $options{options}->add_options(arguments => {});
50
51 return $self;
52 }
53
54 sub snmp_execute {
55 my ($self, %options) = @_;
56
57 $self->{snmp} = $options{snmp};
58 my $oid_contStatusEntry = '.1.3.6.1.4.1.2.6.219.2.2.1.1';
59 my $oid_drvStatusEntry = '.1.3.6.1.4.1.2.6.219.2.2.2.1';
60 $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_contStatusEntry }, { oid => $oid_drvStatusEntry } ], return_type => 1);
61 }
62
63 1;
64
65 =head1 MODE
66
67 Check hardware.
68
69 =over 8
70
71 =item B<--component>
72
73 Which component to check (default: '.*').
74 Can be: 'robot', 'drive', 'ctrl', 'ctrlpower', 'magazine'.
75
76 =item B<--filter>
77
78 Exclude some parts (comma separated list)
79 You can also exclude items from specific instances: --filter=ctrl,1
80
81 =item B<--no-component>
82
83 Define the expected status if no components are found (default: critical).
84
85 =item B<--threshold-overload>
86
87 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp).
88 Example: --threshold-overload='drive,OK,needClean'
89
90 =back
91
92 =cut
93
94 package storage::ibm::ts2900::snmp::mode::components::common;
95
96 my %map_default_status = (1 => 'unknown', 2 => 'ok', 3 => 'warning', 4 => 'failed');
97
98 sub check {
99 my ($self, %options) = @_;
100
101 $self->{output}->output_add(long_msg => "Checking " . $options{description});
102 $self->{components}->{$options{section}} = {name => $options{section}, total => 0, skip => 0};
103 return if ($self->check_filter(section => $options{section}));
104
105 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) {
106 next if ($oid !~ /^$options{mapping}->{$options{status}}->{oid}\.(.*)$/);
107 my $instance = $1;
108 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}, instance => $instance);
109
110 next if ($self->check_filter(section => $options{section}, instance => $instance));
111
112 $self->{components}->{$options{section}}->{total}++;
113 $self->{output}->output_add(long_msg => sprintf("%s '%s' status is '%s' [instance = %s]",
114 $options{description}, $instance, $result->{$options{status}}, $instance));
115 my $exit = $self->get_severity(label => 'default', section => $options{section}, value => $result->{$options{status}});
116 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
117 $self->{output}->output_add(severity => $exit,
118 short_msg => sprintf("%s '%s' status is '%s'", $options{description}, $instance, $result->{$options{status}}));
119 }
120 }
121 }
122
123 package storage::ibm::ts2900::snmp::mode::components::robot;
124
125 use strict;
126 use warnings;
127
128 my $mapping_robot = {
129 robotStatus => { oid => '.1.3.6.1.4.1.2.6.219.2.2.1.1.6', map => \%map_default_status },
130 };
131
132 sub load {}
133
134 sub check {
135 my ($self) = @_;
136
137 storage::ibm::ts2900::snmp::mode::components::common::check($self,
138 section => 'robot', mapping => $mapping_robot, description => 'robot', status => 'robotStatus');
139 }
140
141 package storage::ibm::ts2900::snmp::mode::components::ctrl;
142
143 use strict;
144 use warnings;
145
146 my $mapping_ctrl = {
147 contState => { oid => '.1.3.6.1.4.1.2.6.219.2.2.1.1.7', map => \%map_default_status },
148 };
149
150 sub load {}
151
152 sub check {
153 my ($self) = @_;
154
155 storage::ibm::ts2900::snmp::mode::components::common::check($self,
156 section => 'ctrl', mapping => $mapping_ctrl, description => 'controller', status => 'contState');
157 }
158
159 package storage::ibm::ts2900::snmp::mode::components::ctrlpower;
160
161 use strict;
162 use warnings;
163
164 my $mapping_ctrlpower = {
165 contPowerStatus => { oid => '.1.3.6.1.4.1.2.6.219.2.2.1.1.2', map => \%map_default_status },
166 };
167
168 sub load {}
169
170 sub check {
171 my ($self) = @_;
172
173 storage::ibm::ts2900::snmp::mode::components::common::check($self,
174 section => 'ctrlpower', mapping => $mapping_ctrlpower, description => 'controller power', status => 'contPowerStatus');
175 }
176
177 package storage::ibm::ts2900::snmp::mode::components::magazine;
178
179 use strict;
180 use warnings;
181
182 my $mapping_magazine = {
183 magStatus => { oid => '.1.3.6.1.4.1.2.6.219.2.2.1.1.4', map => \%map_default_status },
184 };
185
186 sub load {}
187
188 sub check {
189 my ($self) = @_;
190
191 storage::ibm::ts2900::snmp::mode::components::common::check($self,
192 section => 'magazine', mapping => $mapping_magazine, description => 'magazine', status => 'magStatus');
193 }
194
195 package storage::ibm::ts2900::snmp::mode::components::drive;
196
197 use strict;
198 use warnings;
199
200 my %map_drive_status = (1 => 'unknown', 2 => 'ok', 3 => 'needClean', 4 => 'warning', 5 => 'failed');
201
202 my $mapping_drive = {
203 driveStatus => { oid => '.1.3.6.1.4.1.2.6.219.2.2.2.1.3', map => \%map_drive_status },
204 };
205
206 sub load {}
207
208 sub check {
209 my ($self) = @_;
210
211 storage::ibm::ts2900::snmp::mode::components::common::check($self,
212 section => 'drive', mapping => $mapping_drive, description => 'drive', status => 'driveStatus');
213 }