Debian Codegraph @

src/centreon/common/h3c/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 centreon::common::h3c::snmp::mode::hardware;
22
23 use base qw(centreon::plugins::templates::hardware);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::statefile;
28
29 sub set_system {
30 my ($self, %options) = @_;
31
32 $self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$';
33
34 $self->{cb_hook2} = 'snmp_execute';
35
36 $self->{thresholds} = {
37 psu => [
38 ['notSupported', 'WARNING'],
39 ['normal', 'OK'],
40 ['entityAbsent', 'OK'],
41 ['psuError', 'CRITICAL'],
42 ['hardwareFaulty', 'CRITICAL']
43 ],
44 fan => [
45 ['notSupported', 'WARNING'],
46 ['normal', 'OK'],
47 ['entityAbsent', 'OK'],
48 ['fanError', 'CRITICAL'],
49 ['hardwareFaulty', 'CRITICAL']
50 ],
51 sensor => [
52 ['notSupported', 'WARNING'],
53 ['normal', 'OK'],
54 ['entityAbsent', 'OK'],
55 ['sensorError', 'CRITICAL'],
56 ['hardwareFaulty', 'CRITICAL']
57 ],
58 other => [
59 ['notSupported', 'WARNING'],
60 ['normal', 'OK'],
61 ['entityAbsent', 'OK'],
62 ['hardwareFaulty', 'CRITICAL']
63 ],
64 unknown => [
65 ['notSupported', 'WARNING'],
66 ['normal', 'OK'],
67 ['entityAbsent', 'OK'],
68 ['hardwareFaulty', 'CRITICAL']
69 ],
70 chassis => [
71 ['notSupported', 'WARNING'],
72 ['normal', 'OK'],
73 ['entityAbsent', 'OK'],
74 ['hardwareFaulty', 'CRITICAL']
75 ],
76 backplane => [
77 ['notSupported', 'WARNING'],
78 ['normal', 'OK'],
79 ['entityAbsent', 'OK'],
80 ['hardwareFaulty', 'CRITICAL']
81 ],
82 container => [
83 ['notSupported', 'WARNING'],
84 ['normal', 'OK'],
85 ['entityAbsent', 'OK'],
86 ['hardwareFaulty', 'CRITICAL']
87 ],
88 module => [
89 ['notSupported', 'WARNING'],
90 ['normal', 'OK'],
91 ['entityAbsent', 'OK'],
92 ['hardwareFaulty', 'CRITICAL']
93 ],
94 port => [
95 ['notSupported', 'WARNING'],
96 ['normal', 'OK'],
97 ['entityAbsent', 'OK'],
98 ['hardwareFaulty', 'CRITICAL']
99 ],
100 stack => [
101 ['notSupported', 'WARNING'],
102 ['normal', 'OK'],
103 ['entityAbsent', 'OK'],
104 ['hardwareFaulty', 'CRITICAL']
105 ],
106 cpu => [
107 ['notSupported', 'WARNING'],
108 ['normal', 'OK'],
109 ['entityAbsent', 'OK'],
110 ['hardwareFaulty', 'CRITICAL']
111 ]
112 };
113
114 $self->{components_path} = 'centreon::common::h3c::snmp::mode::components';
115 $self->{components_module} = [
116 'chassis', 'backplane', 'container', 'psu', 'fan', 'sensor',
117 'module', 'port', 'stack', 'cpu', 'other', 'unknown'
118 ];
119
120 $self->{mapping_name} = {
121 1 => 'other', 2 => 'unknown', 3 => 'chassis', 4 => 'backplane', 5 => 'container', 6 => 'psu',
122 7 => 'fan', 8 => 'sensor', 9 => 'module', 10 => 'port', 11 => 'stack', 12 => 'cpu'
123 };
124 $self->{mapping_component} = {
125 1 => 'default', 2 => 'default', 3 => 'default', 4 => 'default', 5 => 'default', 6 => 'psu',
126 7 => 'fan', 8 => 'sensor', 9 => 'default', 10 => 'default', 11 => 'default', 12 => 'default'
127 };
128 }
129
130 my $oid_hh3cEntityExtStateEntry = '.1.3.6.1.4.1.25506.2.6.1.1.1.1';
131 my $oid_h3cEntityExtStateEntry = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1';
132 my $oid_h3cEntityExtErrorStatus = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.19';
133 my $oid_hh3cEntityExtErrorStatus = '.1.3.6.1.4.1.25506.2.6.1.1.1.1.19';
134
135 sub snmp_execute {
136 my ($self, %options) = @_;
137
138 push @{$self->{request}},
139 { oid => $oid_h3cEntityExtErrorStatus },
140 { oid => $oid_hh3cEntityExtErrorStatus };
141
142 $self->{snmp} = $options{snmp};
143 $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
144 $self->get_physical();
145
146 $self->{branch} = $oid_hh3cEntityExtStateEntry;
147 if (defined($self->{results}->{$oid_h3cEntityExtErrorStatus}) && scalar(keys %{$self->{results}->{$oid_h3cEntityExtErrorStatus}}) > 0) {
148 $self->{branch} = $oid_h3cEntityExtStateEntry;
149 }
150 }
151
152 sub new {
153 my ($class, %options) = @_;
154 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
155 bless $self, $class;
156
157 $options{options}->add_options(arguments => {
158 'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 },
159 'short-name' => { name => 'short_name' }
160 });
161
162 $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
163 return $self;
164 }
165
166 sub check_options {
167 my ($self, %options) = @_;
168 $self->SUPER::check_options(%options);
169
170 $self->{short_name} = (defined($self->{option_results}->{short_name})) ? 1 : 0;
171
172 $self->{statefile_cache}->check_options(%options);
173 }
174
175 my $oid_entPhysicalEntry = '.1.3.6.1.2.1.47.1.1.1.1';
176 my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
177 my $oid_entPhysicalContainedIn = '.1.3.6.1.2.1.47.1.1.1.1.4';
178 my $oid_entPhysicalClass = '.1.3.6.1.2.1.47.1.1.1.1.5';
179 my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
180
181 sub get_physical {
182 my ($self, %options) = @_;
183
184 # init cache file
185 my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_h3c_entity_' . $self->{snmp}->get_hostname() . '_' . $self->{snmp}->get_port());
186 my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
187 if ($has_cache_file == 0 ||
188 !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60)) && $self->{option_results}->{reload_cache_time} != '-1') {
189 $self->{results}->{$oid_entPhysicalEntry} = $self->{snmp}->get_multiple_table(
190 oids => [
191 { oid => $oid_entPhysicalDescr },
192 { oid => $oid_entPhysicalContainedIn },
193 { oid => $oid_entPhysicalClass },
194 { oid => $oid_entPhysicalName }
195 ],
196 return_type => 1
197 );
198 my $datas = {};
199 $datas->{last_timestamp} = time();
200 $datas->{oids} = $self->{results}->{$oid_entPhysicalEntry};
201 $self->{statefile_cache}->write(data => $datas);
202 } else {
203 $self->{results}->{$oid_entPhysicalEntry} = $self->{statefile_cache}->get(name => 'oids');
204 }
205 }
206
207 sub get_short_name {
208 my ($self, %options) = @_;
209
210 return $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalName . '.' . $options{instance}};
211 }
212
213 sub get_long_name {
214 my ($self, %options) = @_;
215
216 my @names = ($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $options{instance}});
217 my %loop = ($options{instance} => 1);
218 my $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $options{instance}};
219 while (1) {
220 last if (!defined($child) || defined($loop{$child}) || !defined($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child}));
221
222 unshift @names, $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child};
223 $loop{$child} = 1;
224 $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $child};
225 }
226
227 return join(' > ', @names);
228 }
229
230 sub get_instance_class {
231 my ($self, %options) = @_;
232
233 my @instances = ();
234 foreach (keys %{$self->{results}->{$oid_entPhysicalEntry}}) {
235 if (/^$oid_entPhysicalClass\.(\d+)/ && defined($options{class}->{$self->{results}->{$oid_entPhysicalEntry}->{$_}})) {
236 push @instances, $1;
237 }
238 }
239
240 return @instances;
241 }
242
243 sub load_components {
244 my ($self, %options) = @_;
245
246 foreach (keys %{$self->{mapping_name}}) {
247 if ($self->{mapping_name}->{$_} =~ /$self->{option_results}->{component}/) {
248 my $mod_name = $self->{components_path} . "::" . $self->{mapping_component}->{$_};
249 centreon::plugins::misc::mymodule_load(
250 output => $self->{output}, module => $mod_name,
251 error_msg => "Cannot load module '$mod_name'."
252 );
253 $self->{loaded} = 1;
254 }
255 }
256 }
257
258 sub exec_components {
259 my ($self, %options) = @_;
260
261 foreach (keys %{$self->{mapping_name}}) {
262 if ($self->{mapping_name}->{$_} =~ /$self->{option_results}->{component}/) {
263 my $mod_name = $self->{components_path} . "::" . $self->{mapping_component}->{$_};
264 my $func = $mod_name->can('check');
265 $func->($self, component => $self->{mapping_name}->{$_}, component_class => $_);
266 }
267 }
268 }
269
270 1;
271
272 __END__
273
274 =head1 MODE
275
276 Check Hardware (Fans, Power Supplies, Module,...).
277
278 =over 8
279
280 =item B<--component>
281
282 Which component to check (default: '.*').
283 Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane',
284 'container', 'module', 'port', 'stack', 'cpu'.
285
286 =item B<--filter>
287
288 Exclude the items given as a comma-separated list (example: --filter=fan --filter=psu).
289 You can also exclude items from specific instances: --filter=fan,101
290
291 =item B<--absent-problem>
292
293 Return an error if an entity is not 'present' (default is skipping) (comma separated list)
294 Can be specific or global: --absent-problem=psu#44#
295
296 =item B<--no-component>
297
298 Define the expected status if no components are found (default: critical).
299
300
301 =item B<--threshold-overload>
302
303 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp).
304 Example: --threshold-overload='psu,CRITICAL,^(?!(normal)$)'
305
306 =item B<--warning>
307
308 Set warning threshold for 'temperature' (syntax: type,regexp,threshold)
309 Example: --warning='temperature,.*,40'
310
311 =item B<--critical>
312
313 Set critical threshold for 'temperature' (syntax: type,regexp,threshold)
314 Example: --critical='temperature,.*,45'
315
316 =item B<--warning-count-*>
317
318 Set warning threshold for component count.
319 Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane',
320 'container', 'module', 'port', 'stack', 'cpu'.
321
322 =item B<--critical-count-*>
323
324 Set critical threshold for component count.
325 Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane',
326 'container', 'module', 'port', 'stack', 'cpu'.
327
328 =item B<--reload-cache-time>
329
330 Time in seconds before reloading cache file (default: 180).
331 Use '-1' to disable cache reload.
332
333 =back
334
335 =cut