| 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::inmatics::sputnik::snmp::mode::environment; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
# Needed libraries |
| 26 |
use strict; |
| 27 |
use warnings; |
| 28 |
|
| 29 |
sub new { |
| 30 |
my ($class, %options) = @_; |
| 31 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 32 |
bless $self, $class; |
| 33 |
|
| 34 |
# Declare options |
| 35 |
$options{options}->add_options(arguments => { |
| 36 |
'filter-id:s' => { name => 'filter_id' } |
| 37 |
}); |
| 38 |
|
| 39 |
return $self; |
| 40 |
} |
| 41 |
|
| 42 |
sub prefix_sensors_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return "'" . $options{instance_value}->{display} . "': "; |
| 46 |
} |
| 47 |
|
| 48 |
sub set_counters { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
$self->{maps_counters_type} = [ |
| 52 |
{ name => 'sensors', type => 1, cb_prefix_output => 'prefix_sensors_output', message_multiple => 'All sensors are ok' } |
| 53 |
]; |
| 54 |
|
| 55 |
$self->{maps_counters}->{sensors} = [ |
| 56 |
{ label => 'temperature', nlabel => 'environment.temperature.celsius', set => { |
| 57 |
key_values => [ { name => 'temperature' }, { name => 'display' } ], |
| 58 |
output_template => 'temperature %.2f C', |
| 59 |
perfdatas => [ |
| 60 |
{ label => 'temperature', template => '%.2f', unit => 'C', label_extra_instance => 1, instance_use => 'display' } |
| 61 |
] |
| 62 |
} |
| 63 |
}, |
| 64 |
{ label => 'humidity', nlabel => 'environment.humidity.percentage', set => { |
| 65 |
key_values => [ { name => 'humidity' }, { name => 'display' } ], |
| 66 |
output_template => 'humidity %s %%', |
| 67 |
perfdatas => [ |
| 68 |
{ label => 'humidity', template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' } |
| 69 |
] |
| 70 |
} |
| 71 |
} |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
sub manage_selection { |
| 76 |
my ($self, %options) = @_; |
| 77 |
|
| 78 |
# FI: upsEnvSensorCounts is not used but it gives the number of sensors |
| 79 |
#my $oid_upsEnvSensorCounts = '.1.3.6.1.4.1.54661.1.1.1.2.1.0'; |
| 80 |
my $oid_upsEnvSensors = '.1.3.6.1.4.1.54661.1.1.1.2.2.1'; |
| 81 |
# FI: the actual MIB OIDs: |
| 82 |
#my $oid_upsEnvSensorTemperature = '.1.3.6.1.4.1.54661.1.1.1.2.2.1.2'; |
| 83 |
#my $oid_upsEnvSensorHumidity = '.1.3.6.1.4.1.54661.1.1.1.2.2.1.3'; |
| 84 |
|
| 85 |
# Each sensor will provide a temperature (in 100th of degrees) and a humidity percentage |
| 86 |
my $mapping = { |
| 87 |
upsEnvSensorTemperature => { oid => $oid_upsEnvSensors.'.2' }, |
| 88 |
upsEnvSensorHumidity => { oid => $oid_upsEnvSensors.'.3' } |
| 89 |
}; |
| 90 |
my $snmp_result = $options{snmp}->get_table( |
| 91 |
oid => $oid_upsEnvSensors, |
| 92 |
nothing_quit => 1 |
| 93 |
); |
| 94 |
|
| 95 |
$self->{sensors} = {}; |
| 96 |
foreach my $oid (sort(keys %{$snmp_result})) { |
| 97 |
next if ($oid !~ /^$oid_upsEnvSensors\.2\.(.*)$/); |
| 98 |
# The index of the sensor will be used in the instance name |
| 99 |
my $sensor_index = $1; |
| 100 |
|
| 101 |
# Skip if a filter is defined and the current sensor does not match |
| 102 |
if (defined($self->{option_results}->{filter_id}) && $sensor_index ne '' && $sensor_index !~ /$self->{option_results}->{filter_id}/ ) { |
| 103 |
$self->{output}->output_add( |
| 104 |
long_msg => "With filter-id: '$self->{option_results}->{filter_id}' - Skipping sensor '$sensor_index'.", |
| 105 |
debug => 1 |
| 106 |
); |
| 107 |
next; |
| 108 |
} |
| 109 |
|
| 110 |
# Get all the metrics for the current instance |
| 111 |
my $result = $options{snmp}->map_instance( |
| 112 |
mapping => $mapping, |
| 113 |
results => $snmp_result, |
| 114 |
instance => $sensor_index |
| 115 |
); |
| 116 |
|
| 117 |
# The temperature is given multiplied by 100, so we have to divide it by 100 |
| 118 |
# cf MIB: UNITS "0.01 degrees Centigrade" |
| 119 |
$self->{sensors}->{$sensor_index} = { |
| 120 |
display => 'Sensor '.$sensor_index, |
| 121 |
temperature => $result->{upsEnvSensorTemperature} / 100, |
| 122 |
humidity => $result->{upsEnvSensorHumidity} |
| 123 |
}; |
| 124 |
} |
| 125 |
|
| 126 |
# No results is not OK |
| 127 |
if (scalar(keys %{$self->{sensors}}) <= 0) { |
| 128 |
$self->{output}->add_option_msg(short_msg => "No sensors found."); |
| 129 |
$self->{output}->option_exit(); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
1; |
| 134 |
|
| 135 |
__END__ |
| 136 |
|
| 137 |
=head1 MODE |
| 138 |
|
| 139 |
Monitor temperature and humidity using the device's environment sensors. |
| 140 |
|
| 141 |
=over 8 |
| 142 |
|
| 143 |
=item B<--warning-*> B<--critical-*> |
| 144 |
|
| 145 |
Thresholds. Can be: 'humidity' (%), 'temperature' (C). |
| 146 |
|
| 147 |
=item B<--filter-id> |
| 148 |
|
| 149 |
Define which sensors should be monitored based on their IDs. This option will be treated as a regular expression. |
| 150 |
|
| 151 |
=back |
| 152 |
|
| 153 |
=cut |