Debian Codegraph @

src/hardware/devices/camera/avigilon/snmp/mode/temperature.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::avigilon::snmp::mode::temperature;
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_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "sensor %s [type:%s] status: %s",
34 $self->{result_values}->{id},
35 $self->{result_values}->{type},
36 $self->{result_values}->{status}
37 );
38 }
39
40 sub set_counters {
41 my ($self, %options) = @_;
42
43 $self->{maps_counters_type} = [
44 { name => 'sensors', type => 0 }
45 ];
46
47 $self->{maps_counters}->{sensors} = [
48 { label => 'temperature',
49 nlabel => 'sensor.temperature.celsius',
50 set => {
51 key_values => [{ name => 'temperature' }],
52 output_template => 'temperature: %.2f C',
53 perfdatas => [
54 { template => '%s', min => 0, unit => 'C', label_extra_instance => 1, instance_use => 'id' }
55 ]
56 }
57 },
58 { label => 'status',
59 type => 2,
60 critical_default => '%{status} ne "ok"',
61 set => {
62 key_values => [{ name => 'status' }, { name => 'id' }, { name => 'type' }],
63 closure_custom_output => $self->can('custom_status_output'),
64 closure_custom_perfdata => sub { return 0; },
65 closure_custom_threshold_check => \&catalog_status_threshold_ng
66 }
67 }
68 ];
69 }
70
71 sub new {
72 my ($class, %options) = @_;
73 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
74 bless $self, $class;
75
76 $options{options}->add_options(arguments => {
77 'filter-sensor-id:s' => { name => 'filter_id' }
78 });
79
80 return $self;
81 }
82
83 my $state_mapping = {
84 1 => 'ok',
85 2 => 'failure',
86 3 => 'outOfBoundary'
87 };
88
89 my $type_mapping = {
90 1 => 'mainSensor',
91 };
92
93 sub manage_selection {
94 my ($self, %options) = @_;
95
96 my $oid_type = '.1.3.6.1.4.1.46202.1.1.1.1.1.1'; # tempSensorType: The type of a temperature sensor, i.e. where it is mounted
97 my $oid_id = '.1.3.6.1.4.1.46202.1.1.1.1.1.2'; # tempSensorId: The unique identifier for a temperature sensor.
98 my $oid_status = '.1.3.6.1.4.1.46202.1.1.1.1.1.3'; # tempSensorStatus: The status of a temperature sensor.
99 my $oid_temperature = '.1.3.6.1.4.1.46202.1.1.1.1.1.4'; # tempSensorValue: The temperature as measured in degrees Celsius.
100
101 my $snmp_result = $options{snmp}->get_leef(
102 oids => [$oid_type, $oid_id, $oid_status, $oid_temperature],
103 nothing_quit => 1
104 );
105
106 $self->{sensors} = {
107 id => $snmp_result->{$oid_id},
108 type => $type_mapping->{$snmp_result->{$oid_type}},
109 status => $state_mapping->{$snmp_result->{$oid_status}},
110 temperature => $snmp_result->{$oid_temperature}
111 };
112 }
113
114 1;
115
116 __END__
117
118 =head1 MODE
119
120 Check temperature sensor state and value.
121
122 =over 8
123
124 =item B<--warning-status>
125
126 Define the conditions to match to return a warning status.
127 The condition can be written using the following macros: %{status}.
128
129 =item B<--critical-status>
130
131 Define the conditions to match to return a critical status (default: '%{status} ne "ok"').
132 The condition can be written using the following macros: %{status}.
133
134 =item B<--warning-temperature*>
135
136 Warning threshold for temperature (Celsius).
137
138 =item B<--critical-temperature*>
139
140 Critical threshold for temperature (Celsius).
141
142 =back
143
144 =cut