| 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::geist::snmp::mode::sensors; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'internal', type => 1, cb_prefix_output => 'prefix_internal_output', message_multiple => 'All internal sensors are ok', skipped_code => { -10 => 1 } }, |
| 34 |
{ name => 'climate', type => 1, cb_prefix_output => 'prefix_climate_output', message_multiple => 'All climate sensors are ok', skipped_code => { -10 => 1 } }, |
| 35 |
]; |
| 36 |
|
| 37 |
$self->{maps_counters}->{climate} = [ |
| 38 |
{ label => 'climate-temperature', nlabel => 'sensor.climate.temperature.celsius', set => { |
| 39 |
key_values => [ { name => 'climateTempC', no_value => 0, } ], |
| 40 |
output_template => 'temperature %s C', |
| 41 |
perfdatas => [ |
| 42 |
{ value => 'climateTempC', template => '%s', unit => 'C', label_extra_instance => 1 }, |
| 43 |
], |
| 44 |
} |
| 45 |
}, |
| 46 |
{ label => 'climate-humidity', nlabel => 'sensor.climate.humidity.percentage', set => { |
| 47 |
key_values => [ { name => 'climateHumidity', no_value => 0 } ], |
| 48 |
output_template => 'humidity %.2f %%', |
| 49 |
perfdatas => [ |
| 50 |
{ value => 'climateHumidity', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, |
| 51 |
], |
| 52 |
} |
| 53 |
}, |
| 54 |
{ label => 'climate-light', nlabel => 'sensor.climate.ambientlight.percentage', set => { |
| 55 |
key_values => [ { name => 'climateLight', no_value => 0 } ], |
| 56 |
output_template => 'ambient light %.2f %%', |
| 57 |
perfdatas => [ |
| 58 |
{ value => 'climateLight', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, |
| 59 |
], |
| 60 |
} |
| 61 |
}, |
| 62 |
{ label => 'climate-airflow', nlabel => 'sensor.climate.airflow.percentage', set => { |
| 63 |
key_values => [ { name => 'climateAirflow', no_value => 0 } ], |
| 64 |
output_template => 'airflow %.2f %%', |
| 65 |
perfdatas => [ |
| 66 |
{ value => 'climateAirflow', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, |
| 67 |
], |
| 68 |
} |
| 69 |
}, |
| 70 |
{ label => 'climate-sound', nlabel => 'sensor.climate.sound.percentage', set => { |
| 71 |
key_values => [ { name => 'climateSound', no_value => 0 } ], |
| 72 |
output_template => 'sound %.2f %%', |
| 73 |
perfdatas => [ |
| 74 |
{ value => 'climateSound', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, |
| 75 |
], |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'climate-dewpoint', nlabel => 'sensor.climate.dewpoint.celsius', set => { |
| 79 |
key_values => [ { name => 'climateDewPointC', no_value => 0 } ], |
| 80 |
output_template => 'dew point %s C', |
| 81 |
perfdatas => [ |
| 82 |
{ value => 'climateDewPointC', template => '%s', unit => 'C', label_extra_instance => 1 }, |
| 83 |
], |
| 84 |
} |
| 85 |
}, |
| 86 |
]; |
| 87 |
|
| 88 |
$self->{maps_counters}->{internal} = [ |
| 89 |
{ label => 'internal-temperature', nlabel => 'sensor.internal.temperature.celsius', set => { |
| 90 |
key_values => [ { name => 'internalTemp', no_value => 0, } ], |
| 91 |
output_template => 'temperature %s C', |
| 92 |
perfdatas => [ |
| 93 |
{ value => 'internalTemp', template => '%s', unit => 'C', label_extra_instance => 1 }, |
| 94 |
], |
| 95 |
} |
| 96 |
}, |
| 97 |
{ label => 'internal-humidity', nlabel => 'sensor.internal.humidity.percentage', set => { |
| 98 |
key_values => [ { name => 'internalHumidity', no_value => 0 } ], |
| 99 |
output_template => 'humidity %.2f %%', |
| 100 |
perfdatas => [ |
| 101 |
{ value => 'internalHumidity', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, |
| 102 |
], |
| 103 |
} |
| 104 |
}, |
| 105 |
{ label => 'internal-dewpoint', nlabel => 'sensor.internal.dewpoint.celsius', set => { |
| 106 |
key_values => [ { name => 'internalDewPoint', no_value => 0 } ], |
| 107 |
output_template => 'dew point %s C', |
| 108 |
perfdatas => [ |
| 109 |
{ value => 'internalDewPoint', template => '%s', unit => 'C', label_extra_instance => 1 }, |
| 110 |
], |
| 111 |
} |
| 112 |
}, |
| 113 |
]; |
| 114 |
} |
| 115 |
|
| 116 |
sub prefix_climate_output { |
| 117 |
my ($self, %options) = @_; |
| 118 |
|
| 119 |
return "Climate '" . $options{instance_value}->{climateName} . "' "; |
| 120 |
} |
| 121 |
|
| 122 |
sub prefix_internal_output { |
| 123 |
my ($self, %options) = @_; |
| 124 |
|
| 125 |
return "Internal '" . $options{instance_value}->{internalName} . "' "; |
| 126 |
} |
| 127 |
|
| 128 |
sub new { |
| 129 |
my ($class, %options) = @_; |
| 130 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 131 |
bless $self, $class; |
| 132 |
|
| 133 |
$options{options}->add_options(arguments => { |
| 134 |
}); |
| 135 |
|
| 136 |
return $self; |
| 137 |
} |
| 138 |
|
| 139 |
sub get_climate_v3 { |
| 140 |
my ($self, %options) = @_; |
| 141 |
|
| 142 |
return if (!defined($options{count}) || $options{count} == 0); |
| 143 |
|
| 144 |
my $mapping = { |
| 145 |
climateName => { oid => '.1.3.6.1.4.1.21239.2.2.1.3' }, |
| 146 |
climateTempC => { oid => '.1.3.6.1.4.1.21239.2.2.1.5' }, |
| 147 |
climateHumidity => { oid => '.1.3.6.1.4.1.21239.2.2.1.7' }, |
| 148 |
climateLight => { oid => '.1.3.6.1.4.1.21239.2.2.1.8' }, |
| 149 |
climateAirflow => { oid => '.1.3.6.1.4.1.21239.2.2.1.9' }, |
| 150 |
climateDewPointC => { oid => '.1.3.6.1.4.1.21239.2.2.1.31' }, |
| 151 |
}; |
| 152 |
|
| 153 |
my $oid_climateEntry = '.1.3.6.1.4.1.21239.2.2.1'; |
| 154 |
my $snmp_result = $options{snmp}->get_table( |
| 155 |
oid => $oid_climateEntry, start => $mapping->{climateName}->{oid}, |
| 156 |
); |
| 157 |
|
| 158 |
$self->{climate} = {}; |
| 159 |
foreach my $oid (keys %$snmp_result) { |
| 160 |
next if ($oid !~ /^$mapping->{climateName}->{oid}\.(.*)/); |
| 161 |
my $instance = $1; |
| 162 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 163 |
$self->{climate}->{$result->{climateName}} = { %$result }; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
sub geist_v3 { |
| 168 |
my ($self, %options) = @_; |
| 169 |
|
| 170 |
my $oid_climateCount = '.1.3.6.1.4.1.21239.2.1.8.1.2.0'; |
| 171 |
my $oid_tempSensorCount = '.1.3.6.1.4.1.21239.2.1.8.1.4.0'; |
| 172 |
my $oid_airflowSensorCount = '.1.3.6.1.4.1.21239.2.1.8.1.5.0'; |
| 173 |
my $snmp_result = $options{snmp}->get_leef( |
| 174 |
oids => [$oid_climateCount, $oid_tempSensorCount, $oid_airflowSensorCount], |
| 175 |
); |
| 176 |
|
| 177 |
return 1 if (!defined($snmp_result->{$oid_climateCount})); |
| 178 |
|
| 179 |
$self->get_climate_v3(%options, count => $snmp_result->{$oid_climateCount}); |
| 180 |
|
| 181 |
return 0; |
| 182 |
} |
| 183 |
|
| 184 |
sub get_internal_v4 { |
| 185 |
my ($self, %options) = @_; |
| 186 |
|
| 187 |
my $mapping = { |
| 188 |
internalName => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.3' }, |
| 189 |
internalTemp => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.5' }, |
| 190 |
internalHumidity => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.6' }, |
| 191 |
internalDewPoint => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.7' }, |
| 192 |
}; |
| 193 |
|
| 194 |
my $oid_internalEntry = '.1.3.6.1.4.1.21239.5.1.2.1'; |
| 195 |
my $snmp_result = $options{snmp}->get_table( |
| 196 |
oid => $oid_internalEntry, start => $mapping->{internalName}->{oid}, |
| 197 |
); |
| 198 |
|
| 199 |
$self->{internal} = {}; |
| 200 |
foreach my $oid (keys %$snmp_result) { |
| 201 |
next if ($oid !~ /^$mapping->{internalName}->{oid}\.(.*)/); |
| 202 |
my $instance = $1; |
| 203 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 204 |
if ($options{temp_unit} eq 'F') { |
| 205 |
$result->{internalTemp} = centreon::plugins::misc::convert_fahrenheit(value => $result->{internalTemp}); |
| 206 |
$result->{internalDewPoint} = centreon::plugins::misc::convert_fahrenheit(value => $result->{internalDewPoint}); |
| 207 |
} |
| 208 |
|
| 209 |
$result->{internalTemp} /= 10; |
| 210 |
$result->{internalDewPoint} /= 10; |
| 211 |
$self->{internal}->{$result->{internalName}} = { %$result }; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
sub geist_v4 { |
| 216 |
my ($self, %options) = @_; |
| 217 |
|
| 218 |
my $oid_temperatureUnits = '.1.3.6.1.4.1.21239.5.1.1.7.0'; |
| 219 |
my $snmp_result = $options{snmp}->get_leef( |
| 220 |
oids => [$oid_temperatureUnits], nothing_quit => 1 |
| 221 |
); |
| 222 |
|
| 223 |
my $temp_unit = $snmp_result->{$oid_temperatureUnits} == 1 ? 'C' : 'F'; |
| 224 |
$self->get_internal_v4(%options, temp_unit => $temp_unit); |
| 225 |
} |
| 226 |
|
| 227 |
sub manage_selection { |
| 228 |
my ($self, %options) = @_; |
| 229 |
|
| 230 |
if ($self->geist_v3(%options)) { |
| 231 |
$self->geist_v4(%options) |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
1; |
| 236 |
|
| 237 |
__END__ |
| 238 |
|
| 239 |
=head1 MODE |
| 240 |
|
| 241 |
Check sensors. |
| 242 |
|
| 243 |
=over 8 |
| 244 |
|
| 245 |
=item B<--warning-*> B<--critical-*> |
| 246 |
|
| 247 |
Thresholds. |
| 248 |
Can be: 'climate-temperature', 'climate-humidity', 'climate-light', |
| 249 |
'climate-airflow', 'climate-sound', 'climate-dewpoint', |
| 250 |
'internal-temperature', 'internal-humidity', 'internal-dewpoint'. |
| 251 |
|
| 252 |
=back |
| 253 |
|
| 254 |
=cut |