Debian Codegraph @

src/hardware/sensors/netbotz/snmp/mode/components/camera.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::sensors::netbotz::snmp::mode::components::camera;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::netbotz::snmp::mode::components::resources qw($map_status $map_camera_value);
26
27 sub load {
28 my ($self) = @_;
29
30 $self->{mapping_camera} = {
31 cameraMotionSensorId => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.3.1.1' },
32 cameraMotionSensorValue => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.3.1.2', map => $map_camera_value },
33 cameraMotionSensorErrorStatus => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.3.1.3', map => $map_status },
34 cameraMotionSensorLabel => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.3.1.4' }
35 };
36 $self->{oid_cameraMotionSensorEntry} = '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.3.1';
37 push @{$self->{request}}, {
38 oid => $self->{oid_cameraMotionSensorEntry},
39 end => $self->{mapping_camera}->{cameraMotionSensorLabel}->{oid}
40 };
41 }
42
43 sub check {
44 my ($self) = @_;
45
46 $self->{output}->output_add(long_msg => "Checking cameras");
47 $self->{components}->{camera} = { name => 'cameras', total => 0, skip => 0 };
48 return if ($self->check_filter(section => 'camera'));
49
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{oid_cameraMotionSensorEntry} }})) {
51 next if ($oid !~ /^$self->{mapping_camera}->{cameraMotionSensorErrorStatus}->{oid}\.(.*)$/);
52 my $instance = $1;
53 my $result = $self->{snmp}->map_instance(
54 mapping => $self->{mapping_camera},
55 results => $self->{results}->{ $self->{oid_cameraMotionSensorEntry} },
56 instance => $instance
57 );
58
59 next if ($self->check_filter(section => 'camera', instance => $instance));
60 $self->{components}->{camera}->{total}++;
61
62 my $label = defined($result->{cameraMotionSensorLabel}) && $result->{cameraMotionSensorLabel} ne '' ? $result->{cameraMotionSensorLabel} : $result->{cameraMotionSensorId};
63 $self->{output}->output_add(
64 long_msg => sprintf(
65 "camera motion '%s' status is '%s' [instance = %s] [value = %s]",
66 $label,
67 $result->{cameraMotionSensorErrorStatus},
68 $instance,
69 $result->{cameraMotionSensorValue}
70 )
71 );
72
73 my $exit = $self->get_severity(label => 'default', section => 'camera', value => $result->{cameraMotionSensorErrorStatus});
74 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
75 $self->{output}->output_add(
76 severity => $exit,
77 short_msg => sprintf(
78 "Camera motion '%s' status is '%s'",
79 $label,
80 $result->{cameraMotionSensorErrorStatus}
81 )
82 );
83 }
84 }
85 }
86
87 1;