Debian Codegraph @

src/network/a10/ax/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 network::a10::ax::snmp::mode::hardware;
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|fan)$';
32
33 $self->{cb_hook2} = 'snmp_execute';
34
35 $self->{thresholds} = {
36 psu => [
37 ['off', 'CRITICAL'],
38 ['on', 'OK'],
39 ['unknown', 'UNKNOWN']
40 ],
41 fan => [
42 ['failed', 'CRITICAL'],
43 ['okFixedHigh', 'OK'],
44 ['okLowMed', 'OK'],
45 ['okMedMed', 'OK'],
46 ['okMedHigh', 'OK'],
47 ['notReady', 'WARNING'],
48 ['unknown', 'UNKNOWN']
49 ]
50 };
51
52 $self->{components_path} = 'network::a10::ax::snmp::mode::components';
53 $self->{components_module} = ['psu', 'fan', 'temperature'];
54 }
55
56 sub new {
57 my ($class, %options) = @_;
58 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1);
59 bless $self, $class;
60
61 $options{options}->add_options(arguments => {});
62
63 return $self;
64 }
65
66 sub snmp_execute {
67 my ($self, %options) = @_;
68
69 my $oid_axSysHwInfo = '.1.3.6.1.4.1.22610.2.4.1.5';
70 $self->{snmp} = $options{snmp};
71 $self->{results} = $self->{snmp}->get_table(oid => $oid_axSysHwInfo);
72 }
73
74 1;
75
76 =head1 MODE
77
78 Check hardware.
79
80 =over 8
81
82 =item B<--component>
83
84 Which component to check (default: '.*').
85 Can be: 'psu', 'fan', 'temperature'.
86
87 =item B<--filter>
88
89 Exclude some parts (comma separated list)
90 You can also exclude items from specific instances: --filter=psu,1
91
92 =item B<--no-component>
93
94 Define the expected status if no components are found (default: critical).
95
96
97 =item B<--threshold-overload>
98
99 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp).
100 Example: --threshold-overload='psu,OK,off'
101
102 =item B<--warning>
103
104 Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
105 Example: --warning='temperature,.*,40'
106
107 =item B<--critical>
108
109 Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
110 Example: --critical='temperature,.*,50'
111
112 =back
113
114 =cut
115
116 package network::a10::ax::snmp::mode::components::fan;
117
118 use strict;
119 use warnings;
120
121 my %map_fan_status = (0 => 'failed', 4 => 'okFixedHigh',
122 5 => 'okLowMed', 6 => 'okMedMed', 7 => 'okMedHigh',
123 -2 => 'notReady', -1 => 'unknown'
124 );
125
126 my $mapping = {
127 axFanName => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.9.1.2' },
128 axFanStatus => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.9.1.3', map => \%map_fan_status },
129 axFanSpeed => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.9.1.4' },
130 };
131
132 sub load { }
133
134 sub check {
135 my ($self) = @_;
136
137 $self->{output}->output_add(long_msg => "Checking fans");
138 $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
139 return if ($self->check_filter(section => 'fan'));
140
141 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) {
142 next if ($oid !~ /^$mapping->{axFanStatus}->{oid}\.(.*)$/);
143 my $instance = $1;
144 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
145
146 next if ($self->check_filter(section => 'fan', instance => $instance));
147
148 $self->{components}->{fan}->{total}++;
149 $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s, speed = %s]",
150 $result->{axFanName}, $result->{axFanStatus}, $instance, $result->{axFanSpeed}));
151 my $exit = $self->get_severity(section => 'fan', value => $result->{axFanStatus});
152 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
153 $self->{output}->output_add(severity => $exit,
154 short_msg => sprintf("fan '%s' status is '%s'", $result->{axFanName}, $result->{axFanStatus}));
155 }
156
157 if ($result->{axFanSpeed} > 0) {
158 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{axFanSpeed});
159 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
160 $self->{output}->output_add(severity => $exit2,
161 short_msg => sprintf("fan '%s' speed is %s rpm", $result->{axFanName}, $result->{axFanSpeed}));
162 }
163 $self->{output}->perfdata_add(
164 label => 'fan', unit => 'rpm',
165 nlabel => 'hardware.fan.speed.rpm',
166 instances => $result->{axFanName},
167 value => $result->{axFanSpeed},
168 warning => $warn,
169 critical => $crit, min => 0
170 );
171 }
172 }
173 }
174
175 1;
176
177 package network::a10::ax::snmp::mode::components::psu;
178
179 use strict;
180 use warnings;
181
182 my %map_psu_status = (0 => 'off', 1 => 'on', -1 => 'unknown');
183
184 my $mapping_psu = {
185 axSysLowerPowerSupplyStatus => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.7', map => \%map_psu_status },
186 axSysUpperPowerSupplyStatus => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.8', map => \%map_psu_status },
187 };
188
189 sub load {}
190
191 sub check_psu {
192 my ($self, %options) = @_;
193
194 return if (!defined($options{status}));
195 return if ($self->check_filter(section => 'psu', instance => $options{instance}));
196
197 $self->{components}->{psu}->{total}++;
198 $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]",
199 $options{instance}, $options{status}, $options{instance}));
200 my $exit = $self->get_severity(section => 'psu', value => $options{status});
201 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
202 $self->{output}->output_add(severity => $exit,
203 short_msg => sprintf("power supply '%s' status is '%s'", $options{instance}, $options{status}));
204 }
205 }
206
207 sub check {
208 my ($self) = @_;
209
210 $self->{output}->output_add(long_msg => "Checking power supplies");
211 $self->{components}->{psu} = {name => 'psu', total => 0, skip => 0};
212 return if ($self->check_filter(section => 'psu'));
213
214 my $result = $self->{snmp}->map_instance(mapping => $mapping_psu, results => $self->{results}, instance => '0');
215
216 check_psu($self, status => $result->{axSysLowerPowerSupplyStatus}, instance => 1);
217 check_psu($self, status => $result->{axSysUpperPowerSupplyStatus}, instance => 2);
218 }
219
220 1;
221
222 package network::a10::ax::snmp::mode::components::temperature;
223
224 use strict;
225 use warnings;
226
227 my $mapping_temp = {
228 axSysHwPhySystemTemp => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.1' },
229 };
230
231 sub load {}
232
233 sub check {
234 my ($self) = @_;
235
236 $self->{output}->output_add(long_msg => "Checking temperature");
237 $self->{components}->{temperature} = {name => 'temperature', total => 0, skip => 0};
238 return if ($self->check_filter(section => 'temperature'));
239
240 my $result = $self->{snmp}->map_instance(mapping => $mapping_temp, results => $self->{results}, instance => '0');
241
242 return if (!defined($result->{axSysHwPhySystemTemp}));
243 $self->{components}->{temperature}->{total}++;
244 $self->{output}->output_add(long_msg => sprintf("physical temperature is %s C [instance = %s]",
245 $result->{axSysHwPhySystemTemp}, '0'));
246 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => '0', value => $result->{axSysHwPhySystemTemp});
247 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
248 $self->{output}->output_add(severity => $exit,
249 short_msg => sprintf("physical temperature is %s C", $result->{axSysHwPhySystemTemp}));
250 }
251 $self->{output}->perfdata_add(
252 label => 'temperature', unit => 'C',
253 nlabel => 'hardware.temperature.celsius',
254 instances => 'physical',
255 value => $result->{axSysHwPhySystemTemp},
256 warning => $warn,
257 critical => $crit
258 );
259 }
260
261 1;