Debian Codegraph @

src/hardware/sensors/jacarta/snmp/mode/sensors.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::jacarta::snmp::mode::sensors;
22
23 use base qw(centreon::plugins::templates::hardware);
24
25 use strict;
26 use warnings;
27
28 sub set_system {
29 my ($self, %options) = @_;
30
31 $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|humidity)$';
32
33 $self->{cb_hook2} = 'snmp_execute';
34
35 $self->{thresholds} = {
36 default => [
37 ['unknown', 'UNKNOWN'],
38 ['disable', 'OK'],
39 ['normal', 'OK'],
40 ['below-low-warning', 'WARNING'],
41 ['below-low-critical', 'CRITICAL'],
42 ['above-high-warning', 'WARNING'],
43 ['above-high-critical', 'CRITICAL'],
44 ['sensorError', 'CRITICAL']
45 ],
46 input => [
47 ['normal', 'OK'],
48 ['triggered', 'CRITICAL']
49 ]
50 };
51
52 $self->{components_path} = 'hardware::sensors::jacarta::snmp::mode::components';
53 $self->{components_module} = ['temperature', 'humidity', 'input'];
54 }
55
56 sub snmp_execute {
57 my ($self, %options) = @_;
58
59 $self->{snmp} = $options{snmp};
60 my $oid_inSeptTempUnit = '.1.3.6.1.4.1.19011.1.3.1.1.2.16.0'; # inSeptConfigTemperatureUnit
61 my $oid_inSeptProTempUnit = '.1.3.6.1.4.1.19011.1.3.2.1.2.16.0'; # isConfigTemperatureUnit
62 my $result = $self->{snmp}->get_leef(oids => [$oid_inSeptTempUnit, $oid_inSeptProTempUnit]);
63
64 $self->{inSept} = 0;
65 $self->{inSeptPro} = 0;
66 if (defined($result->{$oid_inSeptProTempUnit})) {
67 $self->{inSeptPro} = 1;
68 $self->{temperature_unit} = $result->{$oid_inSeptProTempUnit} == 1 ? 'C' : 'F';
69 } elsif (defined($result->{$oid_inSeptTempUnit})) {
70 $self->{inSept} = 1;
71 $self->{temperature_unit} = $result->{$oid_inSeptTempUnit} == 1 ? 'C' : 'F';
72 }
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments => {});
81
82 return $self;
83 }
84
85 sub getInSeptDevices {
86 my ($self, %options) = @_;
87
88 return $self->{inSeptDevices} if (defined($self->{inSeptDevices}));
89
90 my $oid_deviceName1 = '.1.3.6.1.4.1.19011.1.3.1.1.4.3.1.0';
91 my $oid_deviceState1 = '.1.3.6.1.4.1.19011.1.3.1.1.4.3.2.0';
92 my $oid_deviceName2 = '.1.3.6.1.4.1.19011.1.3.1.1.4.4.1.0';
93 my $oid_deviceState2 = '.1.3.6.1.4.1.19011.1.3.1.1.4.4.2.0';
94 my $result = $self->{snmp}->get_leef(oids => [
95 $oid_deviceName1, $oid_deviceState1,
96 $oid_deviceName2, $oid_deviceState2
97 ]);
98
99 $self->{inSeptDevices} = {
100 1 => { name => $result->{$oid_deviceName1}, state => $result->{$oid_deviceState1} == 1 ? 'disabled' : 'auto' },
101 2 => { name => $result->{$oid_deviceName2}, state => $result->{$oid_deviceState2} == 1 ? 'disabled' : 'auto' }
102 };
103
104 return $self->{inSeptDevices};
105 }
106
107 1;
108
109 __END__
110
111 =head1 MODE
112
113 Check sensors.
114
115 =over 8
116
117 =item B<--component>
118
119 Which component to check (default: '.*').
120 Can be: 'temperature', 'humidity', 'input'.
121
122 =item B<--filter>
123
124 Exclude the items given as a comma-separated list (example: --filter=temperature --filter=input).
125 You can also exclude items from specific instances: --filter=temperature,1
126
127 =item B<--no-component>
128
129 Define the expected status if no components are found (default: critical).
130
131 =item B<--threshold-overload>
132
133 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp).
134 Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)'
135
136 =item B<--warning>
137
138 Set warning threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold)
139 Example: --warning='temperature,.*,30'
140
141 =item B<--critical>
142
143 Set critical threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold)
144 Example: --warning='temperature,.*,50'
145
146 =back
147
148 =cut