| 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::ees::snmp::mode::temperature; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub status_custom_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"alarm status %s [type: %s]", |
| 34 |
$self->{result_values}->{alarm_status}, |
| 35 |
$self->{result_values}->{type} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub prefix_temperature_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return "Probe '" . $options{instance_value}->{name} . "' "; |
| 43 |
} |
| 44 |
|
| 45 |
sub set_counters { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
$self->{maps_counters_type} = [ |
| 49 |
{ name => 'temperatures', type => 1, cb_prefix_output => 'prefix_temperature_output', message_multiple => 'All temperatures are ok', skipped_code => { -10 => 1 } } |
| 50 |
]; |
| 51 |
|
| 52 |
$self->{maps_counters}->{temperatures} = [ |
| 53 |
{ |
| 54 |
label => 'alarm-status', |
| 55 |
unknown_default => '%{alarm_status} =~ /fail/i', |
| 56 |
warning_default => '%{alarm_status} =~ /low/i', |
| 57 |
critical_default => '%{alarm_status} =~ /high/i', |
| 58 |
type => 2, |
| 59 |
set => { |
| 60 |
key_values => [ |
| 61 |
{ name => 'alarm_status' }, { name => 'type' }, { name => 'name' } |
| 62 |
], |
| 63 |
closure_custom_threshold_check => \&catalog_status_threshold_ng, |
| 64 |
closure_custom_perfdata => sub {return 0;}, |
| 65 |
closure_custom_output => $self->can('status_custom_output') |
| 66 |
} |
| 67 |
}, |
| 68 |
{ |
| 69 |
label => 'temperature', nlabel => 'probe.temperature.celsius', |
| 70 |
set => { |
| 71 |
key_values => [ { name => 'temperature' }, { name => 'name' } ], |
| 72 |
output_template => 'temperature: %.2fC', |
| 73 |
perfdatas => [ { template => '%.2f', unit => 'C', label_extra_instance => 1, instance_use => 'name' } ] |
| 74 |
} |
| 75 |
} |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
sub new { |
| 80 |
my ($class, %options) = @_; |
| 81 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 82 |
bless $self, $class; |
| 83 |
|
| 84 |
return $self; |
| 85 |
} |
| 86 |
|
| 87 |
my $map_alarm_status = { |
| 88 |
0 => 'high', |
| 89 |
1 => 'low', |
| 90 |
2 => 'fail', |
| 91 |
3 => 'none' |
| 92 |
}; |
| 93 |
|
| 94 |
my $map_type = { |
| 95 |
0 => 'none', |
| 96 |
1 => 'ambient', |
| 97 |
2 => 'battery' |
| 98 |
}; |
| 99 |
|
| 100 |
my $mapping = { |
| 101 |
temperature => { oid => '.1.3.6.1.4.1.6302.2.1.2.7.3.1.2' }, |
| 102 |
alarm_status => { oid => '.1.3.6.1.4.1.6302.2.1.2.7.3.1.5', map => $map_alarm_status }, |
| 103 |
name => { oid => '.1.3.6.1.4.1.6302.2.1.2.7.3.1.3' }, |
| 104 |
type => { oid => '.1.3.6.1.4.1.6302.2.1.2.7.3.1.4', map => $map_type } |
| 105 |
}; |
| 106 |
|
| 107 |
sub manage_selection { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 111 |
oids => [ |
| 112 |
{ oid => $mapping->{temperature}->{oid} }, |
| 113 |
{ oid => $mapping->{alarm_status}->{oid} }, |
| 114 |
{ oid => $mapping->{name}->{oid} }, |
| 115 |
{ oid => $mapping->{type}->{oid} } |
| 116 |
], |
| 117 |
return_type => 1, |
| 118 |
nothing_quit => 1 |
| 119 |
); |
| 120 |
|
| 121 |
$self->{temperatures} = {}; |
| 122 |
foreach my $oid (keys %{$snmp_result}) { |
| 123 |
next if ($oid !~ /^$mapping->{temperature}->{oid}\.(.*)$/); |
| 124 |
my $instance = $1; |
| 125 |
my $data = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 126 |
|
| 127 |
$self->{temperatures}->{$instance} = { |
| 128 |
temperature => $data->{temperature} / 1000, |
| 129 |
alarm_status => $data->{alarm_status}, |
| 130 |
name => $data->{name}, |
| 131 |
type => $data->{type} |
| 132 |
}; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
1; |
| 137 |
|
| 138 |
__END__ |
| 139 |
|
| 140 |
=head1 MODE |
| 141 |
|
| 142 |
Check temperature. |
| 143 |
|
| 144 |
=over 8 |
| 145 |
|
| 146 |
=item B<--unknown-alarm-status> |
| 147 |
|
| 148 |
Define the conditions to match for the status to be UNKNOWN (default: '%{alarm_status} =~ /fail/i'). |
| 149 |
You can use the following variables: %{alarm_status}, %{type}, %{name} |
| 150 |
|
| 151 |
=item B<--warning-alarm-status> |
| 152 |
|
| 153 |
Define the conditions to match for the status to be WARNING (default: '%{alarm_status} =~ /low/i'). |
| 154 |
You can use the following variables: %{alarm_status}, %{type}, %{name} |
| 155 |
|
| 156 |
=item B<--critical-alarm-status> |
| 157 |
|
| 158 |
Define the conditions to match for the status to be CRITICAL (default: '%{alarm_status} =~ /high/i'). |
| 159 |
You can use the following variables: %{alarm_status}, %{type}, %{name} |
| 160 |
|
| 161 |
=item B<--warning-temperature> B<--critical-temperature> |
| 162 |
|
| 163 |
Thresholds: temperature (C) |
| 164 |
|
| 165 |
=back |
| 166 |
|
| 167 |
=cut |