Debian Codegraph @

src/hardware/devices/camera/optelecom/snmp/mode/alarms.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 hardware::devices::camera::optelecom::snmp::mode::alarms;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_alarm_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "alarm: %s",
34 $self->{result_values}->{alarm}
35 );
36 }
37
38 sub device_long_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "checking device '%s'",
43 $options{instance_value}->{deviceName}
44 );
45 }
46
47 sub prefix_device_output {
48 my ($self, %options) = @_;
49
50 return sprintf(
51 "device '%s' ",
52 $options{instance_value}->{deviceName}
53 );
54 }
55
56 sub custom_alarm_perfdata {
57 my ($self, %options) = @_;
58
59 $self->{output}->perfdata_add(
60 nlabel => 'alarm.enabled.count',
61 instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{alarmName}],
62 value => sprintf('%s', $self->{result_values}->{alarmValue})
63 );
64 }
65
66 sub prefix_alarm_output {
67 my ($self, %options) = @_;
68
69 return "alarm '" . $options{instance_value}->{alarmName} . "' ";
70 }
71
72 sub set_counters {
73 my ($self, %options) = @_;
74
75 $self->{maps_counters_type} = [
76 { name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output',
77 indent_long_output => ' ', message_multiple => 'All devices are ok',
78 group => [
79 { name => 'alarms', type => 1, cb_prefix_output => 'prefix_alarm_output', message_multiple => 'all alarms are ok', skipped_code => { -10 => 1 } }
80 ]
81 }
82 ];
83
84 $self->{maps_counters}->{alarms} = [
85 {
86 label => 'alarm-status',
87 type => 2,
88 critical_default => '%{alarm} eq "enabled"',
89 set => {
90 key_values => [
91 { name => 'alarm' }, { name => 'alarmValue' }, { name => 'alarmName' }, { name => 'deviceName' }
92 ],
93 closure_custom_output => $self->can('custom_alarm_output'),
94 closure_custom_threshold_check => \&catalog_status_threshold_ng,
95 closure_custom_perfdata => $self->can('custom_alarm_perfdata')
96 }
97 }
98 ];
99 }
100
101 sub new {
102 my ($class, %options) = @_;
103 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
104 bless $self, $class;
105
106 $options{options}->add_options(arguments => {
107 'filter-device-name:s' => { name => 'filter_device_name' }
108 });
109
110 return $self;
111 }
112
113 my $mapping_device = {
114 serial => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.6' }, # optcSerialNumber
115 userLabel1 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.8' }, # optcUserLabel1
116 userLabel2 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.9' } # optcUserLabel2
117 };
118 my $mapping_stream = {
119 streamDesc => { oid => '.1.3.6.1.4.1.17534.2.2.2.2.1.5' }, # optcStreamDescription
120 streamDownAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.2.2.1.10' } # optcStreamDownAlarm
121 };
122 my $mapping_input = {
123 inputDesc => { oid => '.1.3.6.1.4.1.17534.2.2.2.3.1.4' }, # optcInputDescription
124 signalLostAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.2.3.1.7' }, # optcSignalLostAlarm
125 formatAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.2.3.1.8' } # optcFormatAlarm
126 };
127 my $mapping_image_quality = {
128 badContrastAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.5' }, # optcBadContrastAlarm
129 badExposureAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.6' }, # optcBadExposureAlarm
130 lowDetailAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.7' }, # optcLowDetailAlarm
131 lowSnrAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.8' } # optcLowSnrAlarm
132 };
133 my $mapping_tampering = {
134 noMatchAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.2.1.3' }, # optcNoMatchAlarm
135 positionChangedAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.2.1.4' } # optcPositionChangedAlarm
136 };
137
138 sub add_stream_alarm {
139 my ($self, %options) = @_;
140
141 my $oid_streamTable = '.1.3.6.1.4.1.17534.2.2.2.2.1'; # optcStreamEntry
142 my $snmp_result = $options{snmp}->get_table(
143 oid => $oid_streamTable,
144 start => $mapping_stream->{streamDesc}->{oid}
145 );
146
147 foreach (keys %$snmp_result) {
148 next if (! /\.(\d+)\.(\d+)$/);
149 my ($deviceIndex, $streamIndex) = ($1, $2);
150
151 next if (!defined($self->{devices}->{$deviceIndex}));
152
153 my $result = $options{snmp}->map_instance(mapping => $mapping_stream, results => $snmp_result, instance => $deviceIndex . '.' . $streamIndex);
154
155 my $name = 'streamDown ' . $result->{streamDesc};
156
157 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
158 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
159 alarmName => $name,
160 alarmValue => $result->{streamDownAlarm} =~ /1|true/i ? 1 : 0,
161 alarm => $result->{streamDownAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
162 };
163 }
164 }
165
166 sub add_input_alarm {
167 my ($self, %options) = @_;
168
169 my $oid_inputTable = '.1.3.6.1.4.1.17534.2.2.2.3.1'; # optcInputEntry
170 my $snmp_result = $options{snmp}->get_table(
171 oid => $oid_inputTable,
172 start => $mapping_stream->{inputDesc}->{oid}
173 );
174
175 $self->{inputs} = {};
176 foreach (keys %$snmp_result) {
177 next if (! /\.(\d+)\.(\d+)$/);
178 my ($deviceIndex, $inputIndex) = ($1, $2);
179
180 next if (!defined($self->{devices}->{$deviceIndex}));
181
182 my $result = $options{snmp}->map_instance(mapping => $mapping_input, results => $snmp_result, instance => $deviceIndex . '.' . $inputIndex);
183
184 $self->{inputs}->{$deviceIndex . $inputIndex} = $result->{inputDesc};
185
186 my $name = 'signalLost ' . $result->{inputDesc};
187 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
188 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
189 alarmName => $name,
190 alarmValue => $result->{signalLostAlarm} =~ /1|true/i ? 1 : 0,
191 alarm => $result->{signalLostAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
192 };
193
194 $name = 'format ' . $result->{inputDesc};
195 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
196 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
197 alarmName => $name,
198 alarmValue => $result->{formatAlarm} =~ /1|true/i ? 1 : 0,
199 alarm => $result->{formatAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
200 };
201 }
202 }
203
204 sub add_image_quality_alarm {
205 my ($self, %options) = @_;
206
207 my $oid_imageQualityTable = '.1.3.6.1.4.1.17534.2.2.3.1.1'; # optcImageQualityEntry
208 my $snmp_result = $options{snmp}->get_table(
209 oid => $oid_imageQualityTable,
210 start => $mapping_image_quality->{badContrastAlarm}->{oid}
211 );
212
213 foreach (keys %$snmp_result) {
214 next if (! /\.(\d+)\.(\d+)$/);
215 my ($deviceIndex, $inputIndex) = ($1, $2);
216
217 next if (!defined($self->{devices}->{$deviceIndex}));
218
219 my $result = $options{snmp}->map_instance(mapping => $mapping_image_quality, results => $snmp_result, instance => $deviceIndex . '.' . $inputIndex);
220
221 my $name = 'badContrast ' . $self->{inputs}->{$deviceIndex . $inputIndex};
222 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
223 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
224 alarmName => $name,
225 alarmValue => $result->{badContrastAlarm} =~ /1|true/i ? 1 : 0,
226 alarm => $result->{badContrastAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
227 };
228
229 $name = 'badExposure ' . $self->{inputs}->{$deviceIndex . $inputIndex};
230 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
231 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
232 alarmName => $name,
233 alarmValue => $result->{badExposureAlarm} =~ /1|true/i ? 1 : 0,
234 alarm => $result->{badExposureAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
235 };
236
237 $name = 'lowDetail ' . $self->{inputs}->{$deviceIndex . $inputIndex};
238 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
239 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
240 alarmName => $name,
241 alarmValue => $result->{lowDetailAlarm} =~ /1|true/i ? 1 : 0,
242 alarm => $result->{lowDetailAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
243 };
244
245 $name = 'lowSnr ' . $self->{inputs}->{$deviceIndex . $inputIndex};
246 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
247 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
248 alarmName => $name,
249 alarmValue => $result->{lowSnrAlarm} =~ /1|true/i ? 1 : 0,
250 alarm => $result->{lowSnrAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
251 };
252 }
253 }
254
255 sub add_tampering_alarm {
256 my ($self, %options) = @_;
257
258 my $oid_tamperingTable = '.1.3.6.1.4.1.17534.2.2.3.2.1'; # optcTamperingEntry
259 my $snmp_result = $options{snmp}->get_table(
260 oid => $oid_tamperingTable,
261 start => $mapping_tampering->{noMatchAlarm}->{oid}
262 );
263
264 foreach (keys %$snmp_result) {
265 next if (! /\.(\d+)\.(\d+)$/);
266 my ($deviceIndex, $inputIndex) = ($1, $2);
267
268 next if (!defined($self->{devices}->{$deviceIndex}));
269
270 my $result = $options{snmp}->map_instance(mapping => $mapping_tampering, results => $snmp_result, instance => $deviceIndex . '.' . $inputIndex);
271
272 my $name = 'noMatchoptcNoMatchAlarm ' . $self->{inputs}->{$deviceIndex . $inputIndex};
273 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
274 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
275 alarmName => $name,
276 alarmValue => $result->{noMatchAlarm} =~ /1|true/i ? 1 : 0,
277 alarm => $result->{noMatchAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
278 };
279
280 $name = 'positionChanged ' . $self->{inputs}->{$deviceIndex . $inputIndex};
281 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
282 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
283 alarmName => $name,
284 alarmValue => $result->{positionChangedAlarm} =~ /1|true/i ? 1 : 0,
285 alarm => $result->{positionChangedAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
286 };
287 }
288 }
289
290 sub add_network_alarm {
291 my ($self, %options) = @_;
292
293 my $oid_networkOverloadAlarm = '.1.3.6.1.4.1.17534.2.2.2.4.1.2';
294 my $snmp_result = $options{snmp}->get_table(
295 oid => $oid_networkOverloadAlarm
296 );
297
298 foreach (keys %$snmp_result) {
299 /\.(\d+)$/;
300 my $deviceIndex = $1;
301
302 next if (!defined($self->{devices}->{$deviceIndex}));
303
304 my $name = 'networkOverload';
305 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
306 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
307 alarmName => $name,
308 alarmValue => $snmp_result->{$_} =~ /1|true/i ? 1 : 0,
309 alarm => $snmp_result->{$_} =~ /1|true/i ? 'enabled' : 'disabled'
310 };
311 }
312 }
313
314 sub add_psu_alarm {
315 my ($self, %options) = @_;
316
317 # it's not linked to a device... weird..
318 my $oid_powerSupplyAlarm = '.1.3.6.1.4.1.17534.2.2.1.3.3.0';
319 my $snmp_result = $options{snmp}->get_leef(
320 oids => [$oid_powerSupplyAlarm]
321 );
322
323 if (defined($snmp_result->{$oid_powerSupplyAlarm})) {
324 foreach (keys %{$self->{devices}}) {
325 my $name = 'powersupply';
326 $self->{devices}->{$_}->{alarms}->{$name} = {
327 deviceName => $self->{devices}->{$_}->{deviceName},
328 alarmName => $name,
329 alarmValue => $snmp_result->{$oid_powerSupplyAlarm} =~ /1|true/i ? 1 : 0,
330 alarm => $snmp_result->{$oid_powerSupplyAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
331 };
332 }
333 }
334 }
335
336 sub manage_selection {
337 my ($self, %options) = @_;
338
339 my $oid_deviceTable = '.1.3.6.1.4.1.17534.2.2.1.1.1'; # optcSysInfoEntry
340 my $snmp_result = $options{snmp}->get_table(
341 oid => $oid_deviceTable,
342 start => $mapping_device->{serial}->{oid},
343 end => $mapping_device->{userLabel2}->{oid},
344 nothing_quit => 1
345 );
346
347 $self->{devices} = {};
348 foreach (keys %$snmp_result) {
349 next if (! /^$mapping_device->{serial}->{oid}\.(.*)$/);
350 my $instance = $1;
351 my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance);
352
353 my $name = defined($result->{userLabel1}) && $result->{userLabel1} ne '' ? $result->{userLabel1} : $result->{serial};
354 next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' &&
355 $name !~ /$self->{option_results}->{filter_device_name}/);
356
357 $self->{devices}->{$instance} = { deviceName => $name, alarms => {} };
358 }
359
360 my $oid_temperatureAlarm = '.1.3.6.1.4.1.17534.2.2.1.3.1.1.5'; # optcTemperatureAlarm
361 $snmp_result = $options{snmp}->get_table(oid => $oid_temperatureAlarm);
362 foreach (keys %$snmp_result) {
363 next if (! /\.(\d+).(\d+)$/);
364 my ($deviceIndex, $probeIndex) = ($1, $2);
365
366 next if (!defined($self->{devices}->{$deviceIndex}));
367
368 my $name = 'temperature ' . $probeIndex;
369
370 $self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
371 deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
372 alarmName => $name,
373 alarmValue => $snmp_result->{$_} =~ /1|true/i ? 1 : 0,
374 alarm => $snmp_result->{$_} =~ /1|true/i ? 'enabled' : 'disabled'
375 };
376 }
377
378 $self->add_stream_alarm(snmp => $options{snmp});
379 $self->add_input_alarm(snmp => $options{snmp});
380 $self->add_image_quality_alarm(snmp => $options{snmp});
381 $self->add_tampering_alarm(snmp => $options{snmp});
382 $self->add_network_alarm(snmp => $options{snmp});
383 $self->add_psu_alarm(snmp => $options{snmp});
384 }
385
386 1;
387
388 __END__
389
390 =head1 MODE
391
392 Check alarms.
393
394 =over 8
395
396 =item B<--filter-device-name>
397
398 Filter devices by name (can be a regexp).
399
400 =item B<--unknown-alarm-status>
401
402 Define the conditions to match for the status to be UNKNOWN.
403 You can use the following variables: %{alarm}, %{alarmName}, %{deviceName}
404
405 =item B<--warning-alarm-status>
406
407 Define the conditions to match for the status to be WARNING.
408 You can use the following variables: %{alarm}, %{alarmName}, %{deviceName}
409
410 =item B<--critical-alarm-status>
411
412 Define the conditions to match for the status to be CRITICAL (default: '%{alarm} eq "enabled"').
413 You can use the following variables: %{alarm}, %{alarmName}, %{deviceName}
414
415 =back
416
417 =cut