| 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::raisecom::snmp::mode::components::temperature; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $mapping = { |
| 27 |
raisecomTemperatureValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.1' }, |
| 28 |
raisecomTemperatureThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.5' }, |
| 29 |
raisecomTemperatureThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.6' } |
| 30 |
}; |
| 31 |
|
| 32 |
my $mapping_pon = { |
| 33 |
raisecomTemperatureValue => { oid => '.1.3.6.1.4.1.8886.1.27.2.1.1.10' } |
| 34 |
}; |
| 35 |
|
| 36 |
my $oid_raisecomTemperatureEntry = '.1.3.6.1.4.1.8886.1.1.4.2'; |
| 37 |
|
| 38 |
my $oid_pon_raisecomShelfTemperature = '.1.3.6.1.4.1.8886.1.27.2.1.1.10'; |
| 39 |
|
| 40 |
sub load { |
| 41 |
} |
| 42 |
|
| 43 |
sub check_temp { |
| 44 |
my ($self, %options) = @_; |
| 45 |
|
| 46 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$options{entry}})) { |
| 47 |
next if ($oid !~ /^$mapping->{raisecomTemperatureValue}->{oid}\.(.*)$/); |
| 48 |
my $instance = $1; |
| 49 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $options{entry}, instance => $instance); |
| 50 |
|
| 51 |
next if ($self->check_filter(section => 'temperature', instance => $instance)); |
| 52 |
$self->{components}->{temperature}->{total}++; |
| 53 |
|
| 54 |
$self->{output}->output_add( |
| 55 |
long_msg => sprintf( |
| 56 |
"temperature '%s' is %.2f C [instance: %s].", |
| 57 |
$instance, |
| 58 |
$result->{raisecomTemperatureValue}, |
| 59 |
$instance |
| 60 |
) |
| 61 |
); |
| 62 |
|
| 63 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{raisecomTemperatureValue}); |
| 64 |
if ($checked == 0) { |
| 65 |
my $warn_th = $result->{raisecomTemperatureThresholdLow} . ':'; |
| 66 |
my $crit_th = ':' . $result->{raisecomTemperatureThresholdHigh}; |
| 67 |
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); |
| 68 |
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); |
| 69 |
|
| 70 |
$exit = $self->{perfdata}->threshold_check( |
| 71 |
value => $result->{raisecomTemperatureValue}, |
| 72 |
threshold => [ |
| 73 |
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, |
| 74 |
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } |
| 75 |
] |
| 76 |
); |
| 77 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); |
| 78 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); |
| 79 |
} |
| 80 |
|
| 81 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 82 |
$self->{output}->output_add( |
| 83 |
severity => $exit, |
| 84 |
short_msg => sprintf( |
| 85 |
"Temperature '%s' is %.2f C", |
| 86 |
$instance, |
| 87 |
$result->{raisecomTemperatureValue} |
| 88 |
) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
$self->{output}->perfdata_add( |
| 93 |
unit => 'C', |
| 94 |
nlabel => 'hardware.temperature.celsius', |
| 95 |
instances => $instance, |
| 96 |
value => $result->{raisecomTemperatureValue}, |
| 97 |
warning => $warn, |
| 98 |
critical => $crit, |
| 99 |
); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
sub check_pon_temp { |
| 104 |
my ($self, %options) = @_; |
| 105 |
|
| 106 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$options{entry}})) { |
| 107 |
my $instance = (split '\.', $oid)[-1]; |
| 108 |
my $temperature = $options{entry}->{$oid}; |
| 109 |
|
| 110 |
next if ($self->check_filter(section => 'temperature', instance => $instance)); |
| 111 |
$self->{components}->{temperature}->{total}++; |
| 112 |
|
| 113 |
$self->{output}->output_add( |
| 114 |
long_msg => sprintf( |
| 115 |
"temperature '%s' is %.2f C [instance: %s].", |
| 116 |
$instance, |
| 117 |
$temperature, |
| 118 |
$instance |
| 119 |
) |
| 120 |
); |
| 121 |
|
| 122 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); |
| 123 |
if ($checked == 0) { |
| 124 |
$exit = $self->{perfdata}->threshold_check( |
| 125 |
value => $temperature, |
| 126 |
threshold => [ |
| 127 |
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, |
| 128 |
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } |
| 129 |
] |
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 134 |
$self->{output}->output_add( |
| 135 |
severity => $exit, |
| 136 |
short_msg => sprintf( |
| 137 |
"Temperature '%s' is %.2f C", |
| 138 |
$instance, |
| 139 |
$temperature |
| 140 |
) |
| 141 |
); |
| 142 |
} |
| 143 |
|
| 144 |
$self->{output}->perfdata_add( |
| 145 |
unit => 'C', |
| 146 |
nlabel => 'hardware.temperature.celsius', |
| 147 |
instances => $instance, |
| 148 |
value => $temperature, |
| 149 |
); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
sub check { |
| 154 |
my ($self) = @_; |
| 155 |
|
| 156 |
$self->{output}->output_add(long_msg => "Checking temperatures"); |
| 157 |
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; |
| 158 |
return if ($self->check_filter(section => 'temperature')); |
| 159 |
|
| 160 |
my $snmp_result = $self->{snmp}->get_table(oid => $oid_raisecomTemperatureEntry); |
| 161 |
if (scalar(keys %{$snmp_result}) <= 0) { |
| 162 |
my $result = $self->{snmp}->get_table(oid => $oid_pon_raisecomShelfTemperature); |
| 163 |
check_pon_temp($self, entry => $result); |
| 164 |
} else { |
| 165 |
check_temp($self, entry => $snmp_result); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
1; |