| 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 hardware::sensors::jacarta::snmp::mode::components::humidity; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use hardware::sensors::jacarta::snmp::mode::components::resources qw(%map_default_status %map_state); |
| 26 |
|
| 27 |
sub load {} |
| 28 |
|
| 29 |
sub check_inSeptPro { |
| 30 |
my ($self) = @_; |
| 31 |
|
| 32 |
my $mapping = { |
| 33 |
name => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1.2' }, # isDeviceMonitorHumidityName |
| 34 |
current => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1.3' }, # isDeviceMonitorHumidity |
| 35 |
alarm => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1.4', map => \%map_default_status } # isDeviceMonitorHumidityAlarm |
| 36 |
}; |
| 37 |
my $mapping_config = { |
| 38 |
lowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.3' }, # isDeviceConfigHumidityLowWarning |
| 39 |
lowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.4' }, # isDeviceConfigHumidityLowCritical |
| 40 |
highWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.5' }, # isDeviceConfigHumidityHighWarning |
| 41 |
highCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.6' }, # isDeviceConfigHumidityHighCritical |
| 42 |
lowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.9', map => \%map_state }, # isDeviceConfigHumidityLowWarningState |
| 43 |
lowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.10', map => \%map_state }, # isDeviceConfigHumidityLowCriticalState |
| 44 |
highWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.11', map => \%map_state }, # isDeviceConfigHumidityHighWarningState |
| 45 |
highCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.12', map => \%map_state } # isDeviceConfigHumidityHighCriticalState |
| 46 |
}; |
| 47 |
my $oid_humEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1'; # isDeviceMonitorHumidityEntry |
| 48 |
my $oid_configHumEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1'; # isDeviceConfigHumidityEntry |
| 49 |
|
| 50 |
my $snmp_result = $self->{snmp}->get_multiple_table( |
| 51 |
oids => [ |
| 52 |
{ oid => $oid_humEntry, end => $mapping->{alarm}->{oid} } , |
| 53 |
{ oid => $oid_configHumEntry, start => $mapping_config->{lowWarning}->{oid}, end => $mapping_config->{lowWarning}->{highCriticalState} } |
| 54 |
] |
| 55 |
); |
| 56 |
|
| 57 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$snmp_result->{$oid_humEntry}})) { |
| 58 |
next if ($oid !~ /^$mapping->{alarm}->{oid}\.(.*)$/); |
| 59 |
my $instance = $1; |
| 60 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_humEntry}, instance => $instance); |
| 61 |
my $result2 = $self->{snmp}->map_instance(mapping => $mapping_config, results => $snmp_result->{$oid_configHumEntry}, instance => $instance); |
| 62 |
|
| 63 |
next if ($self->check_filter(section => 'humidity', instance => $instance)); |
| 64 |
$self->{components}->{humidity}->{total}++; |
| 65 |
|
| 66 |
$result->{current} *= 0.01; |
| 67 |
$self->{output}->output_add( |
| 68 |
long_msg => sprintf( |
| 69 |
"humidity '%s' status is '%s' [instance: %s] [value: %s]", |
| 70 |
$result->{name}, |
| 71 |
$result->{alarm}, |
| 72 |
$instance, |
| 73 |
$result->{current} |
| 74 |
) |
| 75 |
); |
| 76 |
|
| 77 |
my $exit = $self->get_severity(label => 'default', section => 'humidity', value => $result->{alarm}); |
| 78 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 79 |
$self->{output}->output_add( |
| 80 |
severity => $exit, |
| 81 |
short_msg => sprintf("Humdity '%s' status is '%s'", $result->{name}, $result->{alarm}) |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{current}); |
| 86 |
if ($checked == 0) { |
| 87 |
$result2->{lowWarning} = ($result2->{lowWarningState} eq 'enabled') ? $result2->{lowWarning} * 0.01 : ''; |
| 88 |
$result2->{lowCritical} = ($result2->{lowCriticalState} eq 'enabled') ? $result2->{lowCritical} * 0.01 : ''; |
| 89 |
$result2->{highWarning} = ($result2->{highWarningState} eq 'enabled') ? $result2->{highWarning} * 0.01 : ''; |
| 90 |
$result2->{highCritical} = ($result2->{highCriticalState} eq 'enabled') ? $result2->{highCritical} * 0.01 : ''; |
| 91 |
my $warn_th = $result2->{lowWarning} . ':' . $result2->{highWarning}; |
| 92 |
my $crit_th = $result2->{lowCritical} . ':' . $result2->{highCritical}; |
| 93 |
$self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th); |
| 94 |
$self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th); |
| 95 |
|
| 96 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance); |
| 97 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance); |
| 98 |
} |
| 99 |
|
| 100 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 101 |
$self->{output}->output_add( |
| 102 |
severity => $exit2, |
| 103 |
short_msg => sprintf("Humdity '%s' is %s %%", $result->{name}, $result->{current}) |
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
$self->{output}->perfdata_add( |
| 108 |
nlabel => 'hardware.humidity.percentage', |
| 109 |
unit => '%', |
| 110 |
instances => $result->{name}, |
| 111 |
value => $result->{current}, |
| 112 |
warning => $warn, |
| 113 |
critical => $crit, |
| 114 |
min => 0, max => 100 |
| 115 |
); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
sub check_inSept { |
| 120 |
my ($self) = @_; |
| 121 |
|
| 122 |
my $devices = $self->getInSeptDevices(); |
| 123 |
|
| 124 |
my $mapping = { |
| 125 |
current => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.3.2.1.5' }, # inSeptsensorMonitorDeviceHumidity |
| 126 |
alarm => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.3.2.1.6', map => \%map_default_status } # inSeptsensorMonitorDeviceHumidityAlarm |
| 127 |
}; |
| 128 |
my $mapping_config = { |
| 129 |
1 => { |
| 130 |
name => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.1' }, # inSeptsensorConfigSensor1HumdityName |
| 131 |
lowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.2' }, # inSeptsensorConfigSensor1HumidityLowWarning |
| 132 |
lowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.3' }, # inSeptsensorConfigSensor1HumidityLowCritical |
| 133 |
highWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.4' }, # inSeptsensorConfigSensor1HumidityHighWarning |
| 134 |
highCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.5' }, # inSeptsensorConfigSensor1HumidityHighCritical |
| 135 |
lowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.8', map => \%map_state }, # inSeptsensorConfigSensor1HumidityLowWarningStatus |
| 136 |
lowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.9', map => \%map_state }, # inSeptsensorConfigSensor1HumidityLowCriticalStatus |
| 137 |
highWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.10', map => \%map_state }, # inSeptsensorConfigSensor1HumidityHighWarningStatus |
| 138 |
highCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.4.11', map => \%map_state } # inSeptsensorConfigSensor1HumidityHighCriticalStatus |
| 139 |
}, |
| 140 |
2 => { |
| 141 |
name => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.1' }, # inSeptsensorConfigSensor2HumdityName |
| 142 |
lowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.2' }, # inSeptsensorConfigSensor2HumidityLowWarning |
| 143 |
lowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.3' }, # inSeptsensorConfigSensor2HumidityLowCritical |
| 144 |
highWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.4' }, # inSeptsensorConfigSensor2HumidityHighWarning |
| 145 |
highCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.5' }, # inSeptsensorConfigSensor2HumidityHighCritical |
| 146 |
lowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.8', map => \%map_state }, # inSeptsensorConfigSensor2HumidityLowWarningStatus |
| 147 |
lowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.9', map => \%map_state }, # inSeptsensorConfigSensor2HumidityLowCriticalStatus |
| 148 |
highWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.10', map => \%map_state }, # inSeptsensorConfigSensor2HumidityHighWarningStatus |
| 149 |
highCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.4.11', map => \%map_state } # inSeptsensorConfigSensor2HumidityHighCriticalStatus |
| 150 |
} |
| 151 |
}; |
| 152 |
my $oid_sensorEntry = '.1.3.6.1.4.1.19011.1.3.1.1.3.2.1'; # inSeptsensorMonitorSensorEntry |
| 153 |
|
| 154 |
my $snmp_result = $self->{snmp}->get_table(oid => $oid_sensorEntry, start => $mapping->{current}->{oid}, end => $mapping->{alarm}->{oid}); |
| 155 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { |
| 156 |
next if ($oid !~ /^$mapping->{alarm}->{oid}\.(.*)$/); |
| 157 |
my $instance = $1; |
| 158 |
|
| 159 |
next if (!defined($devices->{$instance}) || $devices->{$instance}->{state} eq 'disabled'); |
| 160 |
|
| 161 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 162 |
|
| 163 |
my $snmp_config = $self->{snmp}->get_leef(oids => [ map($_->{oid} . '.0', values(%{$mapping_config->{$instance}})) ]); |
| 164 |
my $result2 = $self->{snmp}->map_instance(mapping => $mapping_config->{$instance}, results => $snmp_config, instance => 0); |
| 165 |
|
| 166 |
next if ($self->check_filter(section => 'humidity', instance => $instance)); |
| 167 |
$self->{components}->{humidity}->{total}++; |
| 168 |
|
| 169 |
$result->{current} *= 0.1; |
| 170 |
$self->{output}->output_add( |
| 171 |
long_msg => sprintf( |
| 172 |
"humidity '%s' status is '%s' [instance: %s] [value: %s]", |
| 173 |
$result2->{name}, |
| 174 |
$result->{alarm}, |
| 175 |
$instance, |
| 176 |
$result->{current} |
| 177 |
) |
| 178 |
); |
| 179 |
|
| 180 |
my $exit = $self->get_severity(label => 'default', section => 'humidity', value => $result->{alarm}); |
| 181 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 182 |
$self->{output}->output_add( |
| 183 |
severity => $exit, |
| 184 |
short_msg => sprintf("Humdity '%s' status is '%s'", $result2->{name}, $result->{alarm}) |
| 185 |
); |
| 186 |
} |
| 187 |
|
| 188 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{current}); |
| 189 |
if ($checked == 0) { |
| 190 |
$result2->{lowWarning} = ($result2->{lowWarningState} eq 'enabled') ? $result2->{lowWarning} * 0.1 : ''; |
| 191 |
$result2->{lowCritical} = ($result2->{lowCriticalState} eq 'enabled') ? $result2->{lowCritical} * 0.1 : ''; |
| 192 |
$result2->{highWarning} = ($result2->{highWarningState} eq 'enabled') ? $result2->{highWarning} * 0.1 : ''; |
| 193 |
$result2->{highCritical} = ($result2->{highCriticalState} eq 'enabled') ? $result2->{highCritical} * 0.1 : ''; |
| 194 |
my $warn_th = $result2->{lowWarning} . ':' . $result2->{highWarning}; |
| 195 |
my $crit_th = $result2->{lowCritical} . ':' . $result2->{highCritical}; |
| 196 |
$self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th); |
| 197 |
$self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th); |
| 198 |
|
| 199 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance); |
| 200 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance); |
| 201 |
} |
| 202 |
|
| 203 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 204 |
$self->{output}->output_add( |
| 205 |
severity => $exit2, |
| 206 |
short_msg => sprintf("Humdity '%s' is %s %%", $result2->{name}, $result->{current}) |
| 207 |
); |
| 208 |
} |
| 209 |
|
| 210 |
$self->{output}->perfdata_add( |
| 211 |
nlabel => 'hardware.humidity.percentage', |
| 212 |
unit => '%', |
| 213 |
instances => $result2->{name}, |
| 214 |
value => $result->{current}, |
| 215 |
warning => $warn, |
| 216 |
critical => $crit, |
| 217 |
min => 0, max => 100 |
| 218 |
); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
sub check { |
| 223 |
my ($self) = @_; |
| 224 |
|
| 225 |
$self->{output}->output_add(long_msg => "Checking humidities"); |
| 226 |
$self->{components}->{humidity} = {name => 'humidities', total => 0, skip => 0}; |
| 227 |
return if ($self->check_filter(section => 'humidity')); |
| 228 |
|
| 229 |
check_inSeptPro($self) if ($self->{inSeptPro} == 1); |
| 230 |
check_inSept($self) if ($self->{inSept} == 1); |
| 231 |
} |
| 232 |
|
| 233 |
1; |