| 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 network::hirschmann::standard::snmp::mode::components::led; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_hios_led_type = { |
| 27 |
1 => 'power', 2 => 'status', 3 => 'rm', |
| 28 |
4 => 'envm', 5 => 'i1', 6 => 'i2' |
| 29 |
}; |
| 30 |
my $map_hios_led_status = { |
| 31 |
1 => 'off', 2 => 'greenSolid', 3 => 'greenBlink1', 4 => 'greenBlink3', |
| 32 |
5 => 'greenBlink4', 6 => 'greenBlink5', 7 => 'greenBlink5i', 8 => 'yellowSolid', |
| 33 |
9 => 'yellowBlink1',10 => 'yellowBlink3', 11 => 'yellowBlink4', 12 => 'yellowBlink5', |
| 34 |
13 => 'redSolid', 14 => 'redBlink1', 15 => 'redBlink3', 16 => 'redBlink4', 17 => 'redBlink5' |
| 35 |
}; |
| 36 |
my $map_classic_led_status = { |
| 37 |
1 => 'off', |
| 38 |
2 => 'green', |
| 39 |
3 => 'yellow', |
| 40 |
4 => 'red' |
| 41 |
}; |
| 42 |
my $mapping_hios_led = { |
| 43 |
led_status => { oid => '.1.3.6.1.4.1.248.11.22.1.4.1.1.2', map => $map_hios_led_status } # hm2LedGlobalStatus |
| 44 |
}; |
| 45 |
my $oid_classic_led_group = '.1.3.6.1.4.1.248.14.1.1.35'; # hmLEDGroup |
| 46 |
|
| 47 |
sub load { |
| 48 |
my ($self) = @_; |
| 49 |
|
| 50 |
push @{$self->{myrequest}->{classic}}, |
| 51 |
{ oid => $oid_classic_led_group }; |
| 52 |
push @{$self->{myrequest}->{hios}}, |
| 53 |
{ oid => $mapping_hios_led->{led_status}->{oid} }; |
| 54 |
} |
| 55 |
|
| 56 |
sub check_hios_led { |
| 57 |
my ($self) = @_; |
| 58 |
|
| 59 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_hios_led->{led_status}->{oid} }})) { |
| 60 |
next if ($oid !~ /^$mapping_hios_led->{led_status}->{oid}\.(.*)$/); |
| 61 |
my $instance = $1; |
| 62 |
|
| 63 |
my $result = $self->{snmp}->map_instance( |
| 64 |
mapping => $mapping_hios_led, |
| 65 |
results => $self->{results}->{ $mapping_hios_led->{led_status}->{oid} }, |
| 66 |
instance => $instance |
| 67 |
); |
| 68 |
|
| 69 |
next if ($self->check_filter(section => 'led', instance => $instance)); |
| 70 |
$self->{components}->{led}->{total}++; |
| 71 |
|
| 72 |
$self->{output}->output_add( |
| 73 |
long_msg => sprintf( |
| 74 |
"led '%s' status is %s [instance: %s].", |
| 75 |
$map_hios_led_type->{$instance}, |
| 76 |
$result->{led_status}, |
| 77 |
$instance |
| 78 |
) |
| 79 |
); |
| 80 |
my $exit = $self->get_severity(section => 'led', value => $result->{led_status}); |
| 81 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 82 |
$self->{output}->output_add( |
| 83 |
severity => $exit, |
| 84 |
short_msg => sprintf( |
| 85 |
"Led '%s' status is %s", |
| 86 |
$map_hios_led_type->{$instance}, $result->{led_status} |
| 87 |
) |
| 88 |
); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
sub check_classic_led_group { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$oid_classic_led_group}, instance => 0); |
| 97 |
foreach my $name (sort keys %{$options{mapping}}) { |
| 98 |
next if (!defined($result->{$name})); |
| 99 |
|
| 100 |
$options{mapping}->{$name}->{oid} =~ /\.(\d+)$/; |
| 101 |
my $instance = $1; |
| 102 |
|
| 103 |
next if ($self->check_filter(section => 'led', instance => $instance)); |
| 104 |
$self->{components}->{led}->{total}++; |
| 105 |
|
| 106 |
$self->{output}->output_add( |
| 107 |
long_msg => sprintf( |
| 108 |
"led '%s' status is %s [instance: %s].", |
| 109 |
$instance, $result->{$name}, |
| 110 |
$instance |
| 111 |
) |
| 112 |
); |
| 113 |
my $exit = $self->get_severity(section => 'led', value => $result->{$name}); |
| 114 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 115 |
$self->{output}->output_add( |
| 116 |
severity => $exit, |
| 117 |
short_msg => sprintf( |
| 118 |
"Led '%s' status is %s", |
| 119 |
$instance, $result->{$name} |
| 120 |
) |
| 121 |
); |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
sub check_classic_led { |
| 127 |
my ($self, %options) = @_; |
| 128 |
|
| 129 |
my $mapping; |
| 130 |
if (defined($self->{results}->{$oid_classic_led_group}->{$oid_classic_led_group . '.1.1.0'})) { |
| 131 |
$mapping = { |
| 132 |
hmLEDRSPowerSupply => { oid => '.1.3.6.1.4.1.248.14.1.1.35.1.1', map => $map_classic_led_status, desc => 'PowerSupply' }, |
| 133 |
hmLEDRStandby => { oid => '.1.3.6.1.4.1.248.14.1.1.35.1.2', map => $map_classic_led_status, desc => 'Standby' }, |
| 134 |
hmLEDRSRedundancyManager => { oid => '.1.3.6.1.4.1.248.14.1.1.35.1.3', map => $map_classic_led_status, desc => 'RedundancyManager' }, |
| 135 |
hmLEDRSFault => { oid => '.1.3.6.1.4.1.248.14.1.1.35.1.4', map => $map_classic_led_status, desc => 'Fault' } |
| 136 |
}; |
| 137 |
} elsif (defined($self->{results}->{$oid_classic_led_group}->{$oid_classic_led_group . '.2.1.0'})) { |
| 138 |
$mapping = { |
| 139 |
hmLEDOctPowerSupply1 => { oid => '.1.3.6.1.4.1.248.14.1.1.35.2.1', map => $map_classic_led_status, desc => 'PowerSupply1' }, |
| 140 |
hmLEDOctPowerSupply2 => { oid => '.1.3.6.1.4.1.248.14.1.1.35.2.2', map => $map_classic_led_status, desc => 'PowerSupply2' }, |
| 141 |
hmLEDOctRedundancyManager => { oid => '.1.3.6.1.4.1.248.14.1.1.35.2.3', map => $map_classic_led_status, desc => 'RedundancyManager' }, |
| 142 |
hmLEDOctFault => { oid => '.1.3.6.1.4.1.248.14.1.1.35.2.4', map => $map_classic_led_status, desc => 'Fault' } |
| 143 |
}; |
| 144 |
} elsif (defined($self->{results}->{$oid_classic_led_group}->{$oid_classic_led_group . '.3.1.0'})) { |
| 145 |
$mapping = { |
| 146 |
hmLEDRSRPowerSupply => { oid => '.1.3.6.1.4.1.248.14.1.1.35.3.1', map => $map_classic_led_status, desc => 'PowerSupply' }, |
| 147 |
hmLEDRSRStandby => { oid => '.1.3.6.1.4.1.248.14.1.1.35.3.2', map => $map_classic_led_status, desc => 'Standby' }, |
| 148 |
hmLEDRSRRedundancyManager => { oid => '.1.3.6.1.4.1.248.14.1.1.35.3.3', map => $map_classic_led_status, desc => 'RedundancyManager' }, |
| 149 |
hmLEDRSRFault => { oid => '.1.3.6.1.4.1.248.14.1.1.35.3.4', map => $map_classic_led_status, desc => 'Fault' }, |
| 150 |
hmLEDRSRRelay1 => { oid => '.1.3.6.1.4.1.248.14.1.1.35.3.5', map => $map_classic_led_status, desc => 'Relay1' }, |
| 151 |
hmLEDRSRRelay2 => { oid => '.1.3.6.1.4.1.248.14.1.1.35.3.6', map => $map_classic_led_status, desc => 'Relay2' } |
| 152 |
}; |
| 153 |
} else { |
| 154 |
return ; |
| 155 |
} |
| 156 |
|
| 157 |
check_classic_led_group($self, mapping => $mapping); |
| 158 |
} |
| 159 |
|
| 160 |
sub check { |
| 161 |
my ($self) = @_; |
| 162 |
|
| 163 |
$self->{output}->output_add(long_msg => 'Checking leds'); |
| 164 |
$self->{components}->{led} = { name => 'leds', total => 0, skip => 0 }; |
| 165 |
return if ($self->check_filter(section => 'led')); |
| 166 |
|
| 167 |
check_classic_led($self) if ($self->{os_type} eq 'classic'); |
| 168 |
check_hios_led($self) if ($self->{os_type} eq 'hios'); |
| 169 |
} |
| 170 |
|
| 171 |
1; |