Debian Codegraph @

src/network/mikrotik/snmp/mode/components/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 network::mikrotik::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use network::mikrotik::snmp::mode::components::resources qw($map_gauge_unit $mapping_gauge);
26
27 my $mapping = {
28 mtxrHlTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.10' }, # SoC or PCB according to Mikrotik support
29 mtxrHlProcessorTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.11' }
30 };
31
32 sub load {}
33
34 sub check_temperature {
35 my ($self, %options) = @_;
36
37 $self->{output}->output_add(
38 long_msg => sprintf(
39 "temperature '%s' is %s C",
40 $options{name},
41 $options{value}
42 )
43 );
44
45 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $options{name}, value => $options{value});
46 if ($options{value} == -273) { # RouterOS returns this when the SNMP agent hangs...
47 $exit = 'UNKNOWN';
48 }
49 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
50 $self->{output}->output_add(
51 severity => $exit,
52 short_msg => sprintf("Temperature '%s' is %s C", $options{name}, $options{value})
53 );
54 }
55 $self->{output}->perfdata_add(
56 nlabel => 'hardware.temperature.celsius',
57 unit => 'C',
58 instances => $options{name},
59 value => $options{value},
60 warning => $warn,
61 critical => $crit
62 );
63 $self->{components}->{temperature}->{total}++;
64 }
65
66 sub check {
67 my ($self) = @_;
68
69 $self->{output}->output_add(long_msg => "Checking temperature");
70 $self->{components}->{temperature} = { name => 'temperature', total => 0, skip => 0 };
71 return if ($self->check_filter(section => 'temperature'));
72
73 foreach (keys %{$self->{results}}) {
74 next if (! /^$mapping_gauge->{unit}->{oid}\.(\d+)/);
75 next if ($map_gauge_unit->{ $self->{results}->{$_} } ne 'celsius');
76 my $result = $self->{snmp}->map_instance(mapping => $mapping_gauge, results => $self->{results}, instance => $1);
77 next if ($self->check_filter(section => 'temperature', instance => $result->{name}));
78 check_temperature(
79 $self,
80 value => $result->{value},
81 name => $result->{name}
82 );
83 }
84
85 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => 0);
86 if (defined($result->{mtxrHlTemperature}) && ! $self->check_filter(section => 'temperature', instance => 'system')) {
87 check_temperature(
88 $self,
89 value => $result->{mtxrHlTemperature} / 10,
90 name => 'system'
91 );
92 }
93 if (defined($result->{mtxrHlProcessorTemperature}) && ! $self->check_filter(section => 'temperature', instance => 'processor')) {
94 check_temperature(
95 $self,
96 value => $result->{mtxrHlProcessorTemperature} / 10,
97 name => 'processor'
98 );
99 }
100 }
101
102 1;