Debian Codegraph @

src/network/bluecoat/snmp/mode/components/sensor.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::bluecoat::snmp::mode::components::sensor;
22
23 use strict;
24 use warnings;
25
26 my %map_status = (
27 1 => 'ok',
28 2 => 'unavailable',
29 3 => 'nonoperational',
30 );
31 my %map_code = (
32 1 => 'ok',
33 2 => 'unknown',
34 3 => 'notInstalled',
35 4 => 'voltageLowWarning',
36 5 => 'voltageLowCritical',
37 6 => 'noPower',
38 7 => 'voltageHighWarning',
39 8 => 'voltageHighCritical',
40 9 => 'voltageHighSevere',
41 10 => 'temperatureHighWarning',
42 11 => 'temperatureHighCritical',
43 12 => 'temperatureHighSevere',
44 13 => 'fanSlowWarning',
45 14 => 'fanSlowCritical',
46 15 => 'fanStopped',
47 );
48 my %map_units = (
49 1 => { unit => '', nunit => '' }, # other
50 2 => { unit => '', nunit => '' }, # truthvalue
51 3 => { unit => '', nunit => '' }, # specialEnum
52 4 => { unit => 'V', nunit => 'voltage.volt' }, # volts
53 5 => { unit => 'C', nunit => 'temperature.celsius' }, # celsius
54 6 => { unit => 'rpm', nunit => 'speed.rpm' },
55 );
56
57 # In MIB 'BLUECOAT-SG-SENSOR-MIB'
58 my $mapping = {
59 deviceSensorUnits => { oid => '.1.3.6.1.4.1.3417.2.1.1.1.1.1.3', map => \%map_units },
60 deviceSensorScale => { oid => '.1.3.6.1.4.1.3417.2.1.1.1.1.1.4' },
61 deviceSensorValue => { oid => '.1.3.6.1.4.1.3417.2.1.1.1.1.1.5' },
62 deviceSensorCode => { oid => '.1.3.6.1.4.1.3417.2.1.1.1.1.1.6', map => \%map_code },
63 deviceSensorStatus => { oid => '.1.3.6.1.4.1.3417.2.1.1.1.1.1.7', map => \%map_status },
64 deviceSensorName => { oid => '.1.3.6.1.4.1.3417.2.1.1.1.1.1.9' },
65 };
66 my $oid_deviceSensorValueEntry = '.1.3.6.1.4.1.3417.2.1.1.1.1.1';
67
68 sub load {
69 my ($self) = @_;
70
71 push @{$self->{request}}, { oid => $oid_deviceSensorValueEntry };
72 }
73
74 sub check {
75 my ($self) = @_;
76
77 $self->{output}->output_add(long_msg => "Checking sensors");
78 $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0};
79 return if ($self->check_filter(section => 'sensor'));
80
81 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceSensorValueEntry}})) {
82 next if ($oid !~ /^$mapping->{deviceSensorStatus}->{oid}\.(.*)$/);
83 my $instance = $1;
84 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_deviceSensorValueEntry}, instance => $instance);
85
86 next if ($self->check_filter(section => 'sensor', instance => $instance));
87 $self->{components}->{sensor}->{total}++;
88
89 $self->{output}->output_add(long_msg => sprintf("Sensor '%s' status is '%s' [instance: %s, operational status: %s, value: %s, scale: %s, unit: %s]",
90 $result->{deviceSensorName}, $result->{deviceSensorCode},
91 $instance, $result->{deviceSensorStatus}, $result->{deviceSensorValue}, $result->{deviceSensorScale},
92 $result->{deviceSensorUnits}->{unit}));
93 my $exit = $self->get_severity(section => 'sensor_opstatus', value => $result->{deviceSensorStatus});
94 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
95 $self->{output}->output_add(severity => $exit,
96 short_msg => sprintf("Sensor '%s' operational status is %s",
97 $result->{deviceSensorName}, $result->{deviceSensorStatus}));
98 }
99 $exit = $self->get_severity(section => 'sensor', value => $result->{deviceSensorCode});
100 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
101 $self->{output}->output_add(severity => $exit,
102 short_msg => sprintf("Sensor '%s' status is %s",
103 $result->{deviceSensorName}, $result->{deviceSensorCode}));
104 }
105
106 if (defined($result->{deviceSensorValue}) && $result->{deviceSensorValue} =~ /[0-9]/ && $result->{deviceSensorUnits}->{unit} ne '') {
107 my $value = ($result->{deviceSensorValue} * (10 ** $result->{deviceSensorScale}));
108 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensor', instance => $instance, value => $value);
109 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
110 $self->{output}->output_add(severity => $exit2,
111 short_msg => sprintf("Sensor '%s' value is %s %s", $result->{deviceSensorName}, $value, $result->{deviceSensorUnits}->{unit}));
112 }
113
114 $self->{output}->perfdata_add(
115 label => 'sensor', unit => $result->{deviceSensorUnits}->{unit},
116 nlabel => 'hardware.sensor.' . $result->{deviceSensorUnits}->{nunit},
117 instances => $result->{deviceSensorName},
118 value => $value,
119 warning => $warn,
120 critical => $crit
121 );
122 }
123 }
124 }
125
126 1;