| 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::ups::mge::snmp::mode::environment; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_counters { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{maps_counters_type} = [ |
| 32 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 33 |
]; |
| 34 |
|
| 35 |
$self->{maps_counters}->{global} = [ |
| 36 |
{ label => 'temperature', nlabel => 'hardware.sensor.temperature.celsius', set => { |
| 37 |
key_values => [ { name => 'temperature', no_value => 0, } ], |
| 38 |
output_template => 'Ambiant Temperature: %.2f C', output_error_template => 'Ambiant Temperature: %s', |
| 39 |
perfdatas => [ |
| 40 |
{ value => 'temperature', label => 'temperature', template => '%.2f', |
| 41 |
unit => 'C' }, |
| 42 |
], |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'humidity', nlabel => 'hardware.sensor.humidity.percentage', set => { |
| 46 |
key_values => [ { name => 'humidity', no_value => 0 } ], |
| 47 |
output_template => 'Humidity: %.2f %%', output_error_template => 'Humidity: %s', |
| 48 |
perfdatas => [ |
| 49 |
{ value => 'humidity', label => 'humidity', template => '%.2f', |
| 50 |
unit => '%', min => 0, max => 100 }, |
| 51 |
], |
| 52 |
} |
| 53 |
}, |
| 54 |
]; |
| 55 |
} |
| 56 |
|
| 57 |
sub new { |
| 58 |
my ($class, %options) = @_; |
| 59 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 60 |
bless $self, $class; |
| 61 |
|
| 62 |
$options{options}->add_options(arguments => { |
| 63 |
}); |
| 64 |
|
| 65 |
return $self; |
| 66 |
} |
| 67 |
|
| 68 |
sub manage_selection { |
| 69 |
my ($self, %options) = @_; |
| 70 |
my $values_ok = 0; |
| 71 |
|
| 72 |
my $oid_upsmgEnvironAmbientTemp = '.1.3.6.1.4.1.705.1.8.1.0'; # in 0.1 degree centigrade |
| 73 |
my $oid_upsmgEnvironAmbientHumidity = '.1.3.6.1.4.1.705.1.8.2.0'; # in 0.1 % |
| 74 |
my $snmp_result = $options{snmp}->get_leef( |
| 75 |
oids => [$oid_upsmgEnvironAmbientTemp, $oid_upsmgEnvironAmbientHumidity], |
| 76 |
nothing_quit => 1 |
| 77 |
); |
| 78 |
|
| 79 |
$self->{global} = {}; |
| 80 |
if (defined($snmp_result->{$oid_upsmgEnvironAmbientTemp}) && $snmp_result->{$oid_upsmgEnvironAmbientTemp} ne '' && |
| 81 |
$snmp_result->{$oid_upsmgEnvironAmbientTemp} != 0) { |
| 82 |
$self->{global}->{temperature} = $snmp_result->{$oid_upsmgEnvironAmbientTemp} / 10; |
| 83 |
$values_ok++; |
| 84 |
} |
| 85 |
if (defined($snmp_result->{$oid_upsmgEnvironAmbientHumidity}) && $snmp_result->{$oid_upsmgEnvironAmbientHumidity} ne '' && |
| 86 |
$snmp_result->{$oid_upsmgEnvironAmbientHumidity} != 0) { |
| 87 |
$self->{global}->{humidity} = $snmp_result->{$oid_upsmgEnvironAmbientHumidity} / 10; |
| 88 |
$values_ok++; |
| 89 |
} |
| 90 |
|
| 91 |
if ($values_ok == 0) { |
| 92 |
$self->{output}->add_option_msg(short_msg => "Cannot get temperature and humidity values."); |
| 93 |
$self->{output}->option_exit(); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
1; |
| 98 |
|
| 99 |
__END__ |
| 100 |
|
| 101 |
=head1 MODE |
| 102 |
|
| 103 |
Check environment (temperature and humidity). |
| 104 |
|
| 105 |
=over 8 |
| 106 |
|
| 107 |
=item B<--warning-*> |
| 108 |
|
| 109 |
Warning threshold. |
| 110 |
Can be: 'temperature', 'humidity'. |
| 111 |
|
| 112 |
=item B<--critical-*> |
| 113 |
|
| 114 |
Critical threshold. |
| 115 |
Can be: 'temperature', 'humidity'. |
| 116 |
|
| 117 |
=back |
| 118 |
|
| 119 |
=cut |