Debian Codegraph @

src/network/fortinet/fortiadc/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::fortinet::fortiadc::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $mapping_cpu = {
27 name => { oid => '.1.3.6.1.4.1.12356.112.6.1.1.1.2' }, # fadcCPUName
28 current => { oid => '.1.3.6.1.4.1.12356.112.6.1.1.1.3' } # fadcCPUTemp
29 };
30 my $oid_cpuTable = '.1.3.6.1.4.1.12356.112.6.1.1'; # fadcCPUTable
31
32 my $mapping_temp = {
33 name => { oid => '.1.3.6.1.4.1.12356.112.6.4.1.1.1.2' }, # fadcDeviceTempName
34 current => { oid => '.1.3.6.1.4.1.12356.112.6.4.1.1.1.3' } # fadcDeviceTempValue
35 };
36 my $oid_tempTable = '.1.3.6.1.4.1.12356.112.6.4.1.1'; # fadcDeviceTempTable
37
38 sub load {
39 my ($self) = @_;
40
41 push @{$self->{request}},
42 { oid => $oid_cpuTable, start => $mapping_cpu->{name}->{oid} },
43 { oid => $oid_tempTable, start => $mapping_temp->{name}->{oid} }
44 ;
45 }
46
47 sub check_temperature {
48 my ($self, %options) = @_;
49
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) {
51 next if ($oid !~ /^$options{mapping}->{current}->{oid}\.(.*)$/);
52 my $instance = $1;
53 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance);
54
55 $instance = $options{type} . '.' . $instance;
56 next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{name}));
57 $self->{components}->{temperature}->{total}++;
58
59 $self->{output}->output_add(
60 long_msg => sprintf(
61 "temperature '%s' is %s C [instance: %s]",
62 $result->{name},
63 $result->{current},
64 $instance,
65 )
66 );
67
68 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{name}, value => $result->{current});
69 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
70 $self->{output}->output_add(
71 severity => $exit,
72 short_msg => sprintf(
73 "temperature '%s' is %s degree centigrate",
74 $result->{name},
75 $result->{current}
76 )
77 );
78 }
79 $self->{output}->perfdata_add(
80 nlabel => 'hardware.temperature.celsius',
81 unit => 'C',
82 instances => $result->{name},
83 value => $result->{current},
84 warning => $warn,
85 critical => $crit
86 );
87 }
88 }
89
90 sub check {
91 my ($self) = @_;
92
93 $self->{output}->output_add(long_msg => 'checking temperatures');
94 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
95 return if ($self->check_filter(section => 'temperature'));
96
97 check_temperature($self, entry => $oid_cpuTable, mapping => $mapping_cpu, type => 'cpu');
98 check_temperature($self, entry => $oid_tempTable, mapping => $mapping_temp, type => 'device');
99 }
100
101 1;