| 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::brocade::snmp::mode::hardware; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::hardware); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_system { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$'; |
| 32 |
|
| 33 |
$self->{cb_hook2} = 'snmp_execute'; |
| 34 |
|
| 35 |
$self->{thresholds} = { |
| 36 |
sensor => [ |
| 37 |
['unknown', 'UNKNOWN'], |
| 38 |
['faulty', 'CRITICAL'], |
| 39 |
['below-min', 'WARNING'], |
| 40 |
['nominal', 'OK'], |
| 41 |
['above-max', 'CRITICAL'], |
| 42 |
['absent', 'OK'] |
| 43 |
], |
| 44 |
switch => [ |
| 45 |
['online', 'OK'], |
| 46 |
['offline', 'WARNING'], |
| 47 |
['testing', 'WARNING'], |
| 48 |
['faulty', 'CRITICAL'], |
| 49 |
['absent', 'OK'] |
| 50 |
] |
| 51 |
}; |
| 52 |
|
| 53 |
$self->{components_path} = 'network::brocade::snmp::mode::components'; |
| 54 |
$self->{components_module} = ['switch', 'sensor']; |
| 55 |
} |
| 56 |
|
| 57 |
sub new { |
| 58 |
my ($class, %options) = @_; |
| 59 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1, force_new_perfdata => 1); |
| 60 |
bless $self, $class; |
| 61 |
|
| 62 |
$options{options}->add_options(arguments => {}); |
| 63 |
|
| 64 |
return $self; |
| 65 |
} |
| 66 |
|
| 67 |
sub snmp_execute { |
| 68 |
my ($self, %options) = @_; |
| 69 |
|
| 70 |
$self->{snmp} = $options{snmp}; |
| 71 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); |
| 72 |
} |
| 73 |
|
| 74 |
1; |
| 75 |
|
| 76 |
=head1 MODE |
| 77 |
|
| 78 |
Check brocade operational status and hardware sensors (SW.mib). |
| 79 |
|
| 80 |
=over 8 |
| 81 |
|
| 82 |
=item B<--component> |
| 83 |
|
| 84 |
Which component to check (default: '.*'). |
| 85 |
Can be: 'switch', 'sensor'. |
| 86 |
|
| 87 |
=item B<--filter> |
| 88 |
|
| 89 |
Exclude some parts (comma separated list) |
| 90 |
You can also exclude items from specific instances: --filter=sensor,1.1 |
| 91 |
|
| 92 |
=item B<--absent-problem> |
| 93 |
|
| 94 |
Return an error if an entity is not 'present' (default is skipping) |
| 95 |
Can be specific or global: --absent-problem=sensor,1.2 |
| 96 |
|
| 97 |
=item B<--no-component> |
| 98 |
|
| 99 |
Define the expected status if no components are found (default: critical). |
| 100 |
|
| 101 |
|
| 102 |
=item B<--threshold-overload> |
| 103 |
|
| 104 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 105 |
Example: --threshold-overload='sensor,OK,unknown' |
| 106 |
|
| 107 |
=item B<--warning> |
| 108 |
|
| 109 |
Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold) |
| 110 |
Example: --warning='temperature,.*,40' |
| 111 |
|
| 112 |
=item B<--critical> |
| 113 |
|
| 114 |
Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold) |
| 115 |
Example: --critical='temperature,.*,50' |
| 116 |
|
| 117 |
=back |
| 118 |
|
| 119 |
=cut |
| 120 |
|
| 121 |
package network::brocade::snmp::mode::components::sensor; |
| 122 |
|
| 123 |
use strict; |
| 124 |
use warnings; |
| 125 |
use centreon::plugins::misc; |
| 126 |
|
| 127 |
my %map_status = (1 => 'unknown', 2 => 'faulty', 3 => 'below-min', 4 => 'nominal', 5 => 'above-max', 6 => 'absent'); |
| 128 |
my %map_type = (1 => 'temperature', 2 => 'fan', 3 => 'power-supply'); |
| 129 |
my %map_unit = (temperature => 'celsius', fan => 'rpm'); # No voltage value available |
| 130 |
|
| 131 |
my $mapping = { |
| 132 |
swSensorType => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.2', map => \%map_type }, |
| 133 |
swSensorStatus => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.3', map => \%map_status }, |
| 134 |
swSensorValue => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4' }, |
| 135 |
swSensorInfo => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.5' } |
| 136 |
}; |
| 137 |
my $oid_swSensorEntry = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1'; |
| 138 |
|
| 139 |
sub load { |
| 140 |
my ($self) = @_; |
| 141 |
|
| 142 |
push @{$self->{request}}, { oid => $oid_swSensorEntry }; |
| 143 |
} |
| 144 |
|
| 145 |
sub check { |
| 146 |
my ($self) = @_; |
| 147 |
|
| 148 |
$self->{output}->output_add(long_msg => "Checking sensors"); |
| 149 |
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; |
| 150 |
return if ($self->check_filter(section => 'sensor')); |
| 151 |
|
| 152 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swSensorEntry}})) { |
| 153 |
next if ($oid !~ /^$mapping->{swSensorStatus}->{oid}\.(.*)$/); |
| 154 |
my $instance = $1; |
| 155 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swSensorEntry}, instance => $instance); |
| 156 |
|
| 157 |
next if ($self->check_filter(section => 'sensor', instance => $instance)); |
| 158 |
next if ($result->{swSensorStatus} =~ /absent/i && |
| 159 |
$self->absent_problem(section => 'sensor', instance => $instance)); |
| 160 |
|
| 161 |
$result->{swSensorInfo} = centreon::plugins::misc::trim($result->{swSensorInfo}); |
| 162 |
$self->{components}->{sensor}->{total}++; |
| 163 |
$self->{output}->output_add( |
| 164 |
long_msg => sprintf( |
| 165 |
"%s sensor '%s' status is '%s' [instance = %s]", |
| 166 |
$result->{swSensorType}, $result->{swSensorInfo}, $result->{swSensorStatus}, $instance |
| 167 |
) |
| 168 |
); |
| 169 |
my $exit = $self->get_severity(section => 'sensor', value => $result->{swSensorStatus}); |
| 170 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 171 |
$self->{output}->output_add( |
| 172 |
severity => $exit, |
| 173 |
short_msg => sprintf("%s sensor '%s' status is '%s'", $result->{swSensorType}, $result->{swSensorInfo}, $result->{swSensorStatus}) |
| 174 |
); |
| 175 |
} |
| 176 |
|
| 177 |
if ($result->{swSensorValue} > 0 && $result->{swSensorType} ne 'power-supply') { |
| 178 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $result->{swSensorType}, instance => $instance, value => $result->{swSensorValue}); |
| 179 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 180 |
$self->{output}->output_add( |
| 181 |
severity => $exit2, |
| 182 |
short_msg => sprintf( |
| 183 |
"%s sensor '%s' is %s %s", |
| 184 |
$result->{swSensorType}, $result->{swSensorInfo}, $result->{swSensorValue}, |
| 185 |
$map_unit{$result->{swSensorType}} |
| 186 |
) |
| 187 |
); |
| 188 |
} |
| 189 |
|
| 190 |
$self->{output}->perfdata_add( |
| 191 |
nlabel => 'hardware.sensor.' . $result->{swSensorType} . '.' . $map_unit{$result->{swSensorType}}, |
| 192 |
unit => $map_unit{$result->{swSensorType}}, |
| 193 |
instances => $result->{swSensorInfo}, |
| 194 |
value => $result->{swSensorValue}, |
| 195 |
warning => $warn, |
| 196 |
critical => $crit |
| 197 |
); |
| 198 |
} |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
1; |
| 203 |
|
| 204 |
package network::brocade::snmp::mode::components::switch; |
| 205 |
|
| 206 |
use strict; |
| 207 |
use warnings; |
| 208 |
|
| 209 |
my %map_oper_status = (1 => 'online', 2 => 'offline', 3 => 'testing', 4 => 'faulty'); |
| 210 |
|
| 211 |
my $mapping_global = { |
| 212 |
swFirmwareVersion => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.6' }, |
| 213 |
swOperStatus => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.7', map => \%map_oper_status } |
| 214 |
}; |
| 215 |
my $oid_swSystem = '.1.3.6.1.4.1.1588.2.1.1.1.1'; |
| 216 |
|
| 217 |
sub load { |
| 218 |
my ($self) = @_; |
| 219 |
|
| 220 |
push @{$self->{request}}, { oid => $oid_swSystem, start => $mapping_global->{swFirmwareVersion}->{oid}, end => $mapping_global->{swOperStatus}->{oid} }; |
| 221 |
} |
| 222 |
|
| 223 |
sub check { |
| 224 |
my ($self) = @_; |
| 225 |
|
| 226 |
$self->{output}->output_add(long_msg => "Checking switch"); |
| 227 |
$self->{components}->{switch} = {name => 'switch', total => 0, skip => 0}; |
| 228 |
return if ($self->check_filter(section => 'switch')); |
| 229 |
|
| 230 |
my $result = $self->{snmp}->map_instance(mapping => $mapping_global, results => $self->{results}->{$oid_swSystem}, instance => '0'); |
| 231 |
return if (!defined($result->{swOperStatus})); |
| 232 |
|
| 233 |
$self->{components}->{switch}->{total}++; |
| 234 |
|
| 235 |
$self->{output}->output_add( |
| 236 |
long_msg => sprintf( |
| 237 |
"switch operational status is '%s' [firmware: %s].", |
| 238 |
$result->{swOperStatus}, $result->{swFirmwareVersion} |
| 239 |
) |
| 240 |
); |
| 241 |
my $exit = $self->get_severity(section => 'switch', value => $result->{swOperStatus}); |
| 242 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 243 |
$self->{output}->output_add( |
| 244 |
severity => $exit, |
| 245 |
short_msg => sprintf( |
| 246 |
"switch operational status is '%s'", |
| 247 |
$result->{swOperStatus} |
| 248 |
) |
| 249 |
); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
1; |