| 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::devices::camera::optelecom::snmp::mode::temperatures; |
| 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 custom_alarm_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"alarm: %s", |
| 34 |
$self->{result_values}->{alarm} |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
sub device_long_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
return sprintf( |
| 42 |
"checking device '%s'", |
| 43 |
$options{instance_value}->{deviceName} |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
sub prefix_device_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return sprintf( |
| 51 |
"device '%s' ", |
| 52 |
$options{instance_value}->{deviceName} |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
sub prefix_temperature_output { |
| 57 |
my ($self, %options) = @_; |
| 58 |
|
| 59 |
return "temperature probe '" . $options{instance_value}->{probeIndex} . "' "; |
| 60 |
} |
| 61 |
|
| 62 |
sub set_counters { |
| 63 |
my ($self, %options) = @_; |
| 64 |
|
| 65 |
$self->{maps_counters_type} = [ |
| 66 |
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', |
| 67 |
indent_long_output => ' ', message_multiple => 'All devices are ok', |
| 68 |
group => [ |
| 69 |
{ name => 'temperatures', type => 1, cb_prefix_output => 'prefix_temperature_output', message_multiple => 'all temperatures are ok', skipped_code => { -10 => 1 } } |
| 70 |
] |
| 71 |
} |
| 72 |
]; |
| 73 |
|
| 74 |
$self->{maps_counters}->{temperatures} = [ |
| 75 |
{ label => 'probe-temperature', nlabel => 'probe.temperature.celsius', set => { |
| 76 |
key_values => [ { name => 'actual' }, { name => 'probeIndex' }, { name => 'deviceName' } ], |
| 77 |
output_template => 'temperature: %.2f C', |
| 78 |
closure_custom_perfdata => sub { |
| 79 |
my ($self, %options) = @_; |
| 80 |
|
| 81 |
$self->{output}->perfdata_add( |
| 82 |
nlabel => $self->{nlabel}, |
| 83 |
unit => 'C', |
| 84 |
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{probeIndex}], |
| 85 |
value => sprintf('%.2f', $self->{result_values}->{actual}), |
| 86 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 87 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 88 |
); |
| 89 |
} |
| 90 |
} |
| 91 |
}, |
| 92 |
{ |
| 93 |
label => 'alarm-status', |
| 94 |
type => 2, |
| 95 |
critical_default => '%{alarm} eq "enabled"', |
| 96 |
set => { |
| 97 |
key_values => [ |
| 98 |
{ name => 'alarm' }, { name => 'alarmValue' }, { name => 'probeIndex' }, { name => 'deviceName' } |
| 99 |
], |
| 100 |
closure_custom_output => $self->can('custom_alarm_output'), |
| 101 |
closure_custom_threshold_check => \&catalog_status_threshold_ng, |
| 102 |
closure_custom_perfdata => sub { |
| 103 |
my ($self, %options) = @_; |
| 104 |
|
| 105 |
$self->{output}->perfdata_add( |
| 106 |
nlabel => 'probe.temperature.alarm.enabled.count', |
| 107 |
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{probeIndex}], |
| 108 |
value => sprintf('%s', $self->{result_values}->{alarmValue}) |
| 109 |
); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
]; |
| 114 |
} |
| 115 |
|
| 116 |
sub new { |
| 117 |
my ($class, %options) = @_; |
| 118 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 119 |
bless $self, $class; |
| 120 |
|
| 121 |
$options{options}->add_options(arguments => { |
| 122 |
'filter-device-name:s' => { name => 'filter_device_name' } |
| 123 |
}); |
| 124 |
|
| 125 |
return $self; |
| 126 |
} |
| 127 |
|
| 128 |
my $mapping_device = { |
| 129 |
serial => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.6' }, # optcSerialNumber |
| 130 |
userLabel1 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.8' }, # optcUserLabel1 |
| 131 |
userLabel2 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.9' } # optcUserLabel2 |
| 132 |
}; |
| 133 |
|
| 134 |
my $mapping_temperature = { |
| 135 |
actual => { oid => '.1.3.6.1.4.1.17534.2.2.1.3.1.1.2' }, # optcActualTemperature |
| 136 |
alarm => { oid => '.1.3.6.1.4.1.17534.2.2.1.3.1.1.5' }, # optcTemperatureAlarm |
| 137 |
}; |
| 138 |
|
| 139 |
sub manage_selection { |
| 140 |
my ($self, %options) = @_; |
| 141 |
|
| 142 |
my $oid_deviceTable = '.1.3.6.1.4.1.17534.2.2.1.1.1'; # optcSysInfoEntry |
| 143 |
my $snmp_result = $options{snmp}->get_table( |
| 144 |
oid => $oid_deviceTable, |
| 145 |
start => $mapping_device->{serial}->{oid}, |
| 146 |
end => $mapping_device->{userLabel2}->{oid}, |
| 147 |
nothing_quit => 1 |
| 148 |
); |
| 149 |
|
| 150 |
$self->{devices} = {}; |
| 151 |
foreach (keys %$snmp_result) { |
| 152 |
next if (! /^$mapping_device->{serial}->{oid}\.(.*)$/); |
| 153 |
my $instance = $1; |
| 154 |
my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance); |
| 155 |
|
| 156 |
my $name = defined($result->{userLabel1}) && $result->{userLabel1} ne '' ? $result->{userLabel1} : $result->{serial}; |
| 157 |
next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' && |
| 158 |
$name !~ /$self->{option_results}->{filter_device_name}/); |
| 159 |
|
| 160 |
$self->{devices}->{$instance} = { deviceName => $name, temperatures => {} }; |
| 161 |
} |
| 162 |
|
| 163 |
my $oid_temperatureTable = '.1.3.6.1.4.1.17534.2.2.1.3.1.1'; # optcTemperatureEntry |
| 164 |
$snmp_result = $options{snmp}->get_table(oid => $oid_temperatureTable); |
| 165 |
foreach (keys %$snmp_result) { |
| 166 |
next if (! /^$mapping_temperature->{actual}->{oid}\.(\d+).(\d+)$/); |
| 167 |
my ($deviceIndex, $probeIndex) = ($1, $2); |
| 168 |
|
| 169 |
next if (!defined($self->{devices}->{$deviceIndex})); |
| 170 |
|
| 171 |
my $result = $options{snmp}->map_instance(mapping => $mapping_temperature, results => $snmp_result, instance => $deviceIndex . '.' . $probeIndex); |
| 172 |
|
| 173 |
$self->{devices}->{$deviceIndex}->{temperatures}->{$probeIndex} = { |
| 174 |
probeIndex => $probeIndex, |
| 175 |
deviceName => $self->{devices}->{$deviceIndex}->{deviceName}, |
| 176 |
actual => $result->{actual}, |
| 177 |
alarmValue => $result->{alarm} =~ /1|true/i ? 1 : 0, |
| 178 |
alarm => $result->{alarm} =~ /1|true/i ? 'enabled' : 'disabled' |
| 179 |
}; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
1; |
| 184 |
|
| 185 |
__END__ |
| 186 |
|
| 187 |
=head1 MODE |
| 188 |
|
| 189 |
Check temperatures. |
| 190 |
|
| 191 |
=over 8 |
| 192 |
|
| 193 |
=item B<--filter-device-name> |
| 194 |
|
| 195 |
Filter devices by name (can be a regexp). |
| 196 |
|
| 197 |
=item B<--unknown-alarm-status> |
| 198 |
|
| 199 |
Define the conditions to match for the status to be UNKNOWN. |
| 200 |
You can use the following variables: %{alarm}, %{probeIndex}, %{deviceName} |
| 201 |
|
| 202 |
=item B<--warning-alarm-status> |
| 203 |
|
| 204 |
Define the conditions to match for the status to be WARNING. |
| 205 |
You can use the following variables: %{alarm}, %{probeIndex}, %{deviceName} |
| 206 |
|
| 207 |
=item B<--critical-alarm-status> |
| 208 |
|
| 209 |
Define the conditions to match for the status to be CRITICAL (default: '%{alarm} eq "enabled"'). |
| 210 |
You can use the following variables: %{alarm}, %{probeIndex}, %{deviceName} |
| 211 |
|
| 212 |
=item B<--warning-*> B<--critical-*> |
| 213 |
|
| 214 |
Thresholds. |
| 215 |
Can be: 'probe-temperature'. |
| 216 |
|
| 217 |
=back |
| 218 |
|
| 219 |
=cut |