| 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 centreon::common::sun::snmp::mode::components::entity; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my %map_class = ( |
| 27 |
1 => 'other', 2 => 'unknown', 3 => 'chassis', |
| 28 |
4 => 'backplane', 5 => 'container', 6 => 'powerSupply', |
| 29 |
7 => 'fan', 8 => 'sensor', 9 => 'module', |
| 30 |
10 => 'port', 11 => 'stack', |
| 31 |
); |
| 32 |
my %map_oper_state = (1 => 'disabled', 2 => 'enabled'); |
| 33 |
my %map_alarm = ( |
| 34 |
1 => 'critical', 2 => 'major', 3 => 'minor', 4 => 'indeterminate', |
| 35 |
5 => 'warning', 6 => 'pending', 7 => 'cleared' |
| 36 |
); |
| 37 |
my %map_sensor_type = (1 => 'other', |
| 38 |
2 => 'unknown', 3 => 'temperature', 4 => 'voltage', 5 => 'current', 6 => 'tachometer', |
| 39 |
7 => 'counter', 8 => 'switch', 9 => 'lock', 10 => 'humidity', |
| 40 |
11 => 'smokeDetection', 12 => 'presence', 13 => 'airFlow'); |
| 41 |
my %mapping_units = ( |
| 42 |
1 => 'unknown', 2 => 'unknown', |
| 43 |
3 => 'celsius', |
| 44 |
4 => 'fahrenheit', |
| 45 |
5 => 'kelvin', |
| 46 |
6 => 'volt', |
| 47 |
7 => 'ampere', |
| 48 |
8 => 'watt', |
| 49 |
9 => 'Joules', 10 => 'Coulombs', 11 => 'VA', 12 => 'Nits', |
| 50 |
13 => 'Lumens', 14 => 'Lux', 15 => 'Candelas', |
| 51 |
16 => 'kPa', 17 => 'PSI', 18 => 'Newtons', |
| 52 |
19 => 'CFM', 20 => 'rpm', |
| 53 |
21 => 'Hz', # Hertz |
| 54 |
22 => 'Seconds', 23 => 'Minutes', 24 => 'Hours', |
| 55 |
25 => 'Days', 26 => 'Weeks', 27 => 'Mils', |
| 56 |
28 => 'Inches', 29 => 'Feet', 30 => 'Cubic_Inches', |
| 57 |
31 => 'CubicFeet', 32 => 'Meters', 33 => 'CubicCentimeters', |
| 58 |
34 => 'CubicMeters', 35 => 'Liters', 36 => 'FluidOunces', |
| 59 |
37 => 'Radians', 38 => 'Steradians', 39 => 'Revolutions', |
| 60 |
40 => 'Cycles', 41 => 'Gravities', 42 => 'Ounces', |
| 61 |
43 => 'Pounds', 44 => 'FootPounds', 45 => 'OunceInches', |
| 62 |
46 => 'Gauss', 47 => 'Gilberts', 48 => 'Henries', |
| 63 |
49 => 'Farads', 50 => 'Ohms', 51 => 'Siemens', |
| 64 |
52 => 'Moles', 53 => 'Becquerels', 54 => 'PPM', |
| 65 |
55 => 'Decibels', 56 => 'DbA', 57 => 'DbC', |
| 66 |
58 => 'Grays', 59 => 'Sieverts', 60 => 'ColorTemperatureDegreesKelvin', |
| 67 |
61 => 'bits', |
| 68 |
62 => 'bytes', |
| 69 |
63 => 'Words', 64 => 'DoubleWords', 65 => 'QuadWords', |
| 70 |
66 => 'percentage', |
| 71 |
67 => 'Pascals', |
| 72 |
); |
| 73 |
|
| 74 |
my $mapping = { |
| 75 |
entPhysicalClass => { oid => '.1.3.6.1.2.1.47.1.1.1.1.5', map => \%map_class }, |
| 76 |
entPhysicalName => { oid => '.1.3.6.1.2.1.47.1.1.1.1.7' }, |
| 77 |
sunPlatEquipmentOperationalState => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.2.1.2', map => \%map_oper_state }, |
| 78 |
sunPlatEquipmentAlarmStatus => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.2.1.3', map => \%map_alarm }, |
| 79 |
sunPlatSensorType => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.6.1.2', map => \%map_sensor_type }, |
| 80 |
sunPlatNumericSensorBaseUnits => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.8.1.1', map => \%mapping_units }, |
| 81 |
sunPlatNumericSensorExponent => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.8.1.2' }, |
| 82 |
sunPlatNumericSensorCurrent => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.8.1.4' }, |
| 83 |
}; |
| 84 |
my $oid_sunPlatEquipmentEntry = '.1.3.6.1.4.1.42.2.70.101.1.1.2.1'; |
| 85 |
my $oid_sunPlatNumericSensorEntry = '.1.3.6.1.4.1.42.2.70.101.1.1.8.1'; |
| 86 |
|
| 87 |
sub load { |
| 88 |
my ($self) = @_; |
| 89 |
|
| 90 |
push @{$self->{request}}, { oid => $mapping->{entPhysicalName}->{oid} }, { oid => $mapping->{entPhysicalClass}->{oid} }, |
| 91 |
{ oid => $oid_sunPlatEquipmentEntry }, { oid => $oid_sunPlatNumericSensorEntry }, |
| 92 |
{ oid => $mapping->{sunPlatSensorType}->{oid} }; |
| 93 |
} |
| 94 |
|
| 95 |
sub check { |
| 96 |
my ($self) = @_; |
| 97 |
|
| 98 |
$self->{output}->output_add(long_msg => "Checking entities"); |
| 99 |
$self->{components}->{entity} = {name => 'entity', total => 0, skip => 0}; |
| 100 |
return if ($self->check_filter(section => 'entity')); |
| 101 |
|
| 102 |
my ($exit, $warn, $crit, $checked); |
| 103 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { |
| 104 |
next if ($oid !~ /^$mapping->{entPhysicalName}->{oid}\.(.*)$/); |
| 105 |
my $instance = $1; |
| 106 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); |
| 107 |
|
| 108 |
next if ($self->check_filter(section => 'entity', instance => $result->{entPhysicalClass} . '.' . $instance)); |
| 109 |
next if ($result->{sunPlatEquipmentOperationalState} eq 'disabled'); |
| 110 |
|
| 111 |
if (defined($result->{sunPlatNumericSensorCurrent})) { |
| 112 |
$result->{sunPlatNumericSensorCurrent} *= 10 ** $result->{sunPlatNumericSensorExponent} |
| 113 |
} |
| 114 |
|
| 115 |
$self->{components}->{entity}->{total}++; |
| 116 |
$self->{output}->output_add(long_msg => sprintf("%s '%s' status is '%s' [instance = %s, value = %s]", |
| 117 |
$result->{entPhysicalClass}, $result->{entPhysicalName}, |
| 118 |
$result->{sunPlatEquipmentAlarmStatus}, $result->{entPhysicalClass} . '.' . $instance, |
| 119 |
defined($result->{sunPlatNumericSensorCurrent}) ? $result->{sunPlatNumericSensorCurrent} : '-')); |
| 120 |
$exit = $self->get_severity(label => 'default', section => 'entity', instance => $result->{entPhysicalClass} . '.' . $instance, value => $result->{sunPlatEquipmentAlarmStatus}); |
| 121 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 122 |
$self->{output}->output_add(severity => $exit, |
| 123 |
short_msg => sprintf("%s '%s' status is '%s'", $result->{entPhysicalClass}, $result->{entPhysicalName}, $result->{sunPlatEquipmentAlarmStatus})); |
| 124 |
} |
| 125 |
|
| 126 |
next if (!defined($result->{sunPlatNumericSensorCurrent})); |
| 127 |
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => $result->{sunPlatSensorType}, instance => $result->{entPhysicalClass} . '.' . $instance,, value => $result->{sunPlatNumericSensorCurrent}); |
| 128 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 129 |
$self->{output}->output_add(severity => $exit, |
| 130 |
short_msg => sprintf("%s '%s' is '%s' %s", $result->{sunPlatSensorType}, |
| 131 |
$result->{entPhysicalName}, $result->{sunPlatNumericSensorCurrent}, $result->{sunPlatNumericSensorBaseUnits})); |
| 132 |
} |
| 133 |
$self->{output}->perfdata_add( |
| 134 |
label => $result->{sunPlatSensorType}, unit => $result->{sunPlatNumericSensorBaseUnits}, |
| 135 |
nlabel => 'hardware.entity.' . $result->{sunPlatSensorType} . '.' . lc($result->{sunPlatNumericSensorBaseUnits}), |
| 136 |
instances => $result->{entPhysicalName}, |
| 137 |
value => $result->{sunPlatNumericSensorCurrent}, |
| 138 |
warning => $warn, |
| 139 |
critical => $crit |
| 140 |
); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
1; |