| 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::viptela::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)$'; |
| 32 |
|
| 33 |
$self->{cb_hook2} = 'snmp_execute'; |
| 34 |
|
| 35 |
$self->{thresholds} = { |
| 36 |
default => [ |
| 37 |
['ok', 'OK'], |
| 38 |
['down', 'CRITICAL'], |
| 39 |
['failed', 'CRITICAL'] |
| 40 |
] |
| 41 |
}; |
| 42 |
|
| 43 |
$self->{components_path} = 'network::viptela::snmp::mode::components'; |
| 44 |
$self->{components_module} = ['fan', 'led', 'nim', 'pem', 'pim', 'temperature', 'usb']; |
| 45 |
} |
| 46 |
|
| 47 |
sub snmp_execute { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
my $map_status = { |
| 51 |
0 => 'ok', 1 => 'down', 2 => 'failed' |
| 52 |
}; |
| 53 |
my $map_type = { |
| 54 |
0 => 'temperature', 1 => 'fan', 2 => 'pem', 3 => 'pim', 4 => 'usb', 5 => 'led', 6 => 'nim' |
| 55 |
}; |
| 56 |
my $mapping = { |
| 57 |
status => { oid => '.1.3.6.1.4.1.41916.3.1.2.1.4', map => $map_status }, # hardwareEnvironmentStatus |
| 58 |
measure => { oid => '.1.3.6.1.4.1.41916.3.1.2.1.5' } # hardwareEnvironmentMeasurement |
| 59 |
}; |
| 60 |
my $table = '.1.3.6.1.4.1.41916.3.1.2'; # hardwareEnvironmentTable |
| 61 |
|
| 62 |
$self->{results} = []; |
| 63 |
my $snmp_result = $options{snmp}->get_table(oid => $table, start => $mapping->{status}->{oid}); |
| 64 |
foreach (keys %$snmp_result) { |
| 65 |
next if (! /^$mapping->{status}->{oid}\.(\d+).(\d+)\.(.*?)\.(\d+)$/); |
| 66 |
my $type = $map_type->{$1}; |
| 67 |
my $instance = $1 . '.' . $2 . '.' . $3 . '.' . $4; |
| 68 |
my $result = $options{snmp}->map_instance( |
| 69 |
mapping => $mapping, |
| 70 |
results => $snmp_result, |
| 71 |
instance => $1 . '.' . $2 . '.' . $3 . '.' . $4 |
| 72 |
); |
| 73 |
push @{$self->{results}}, { |
| 74 |
name => $self->{output}->decode(join('', map(chr($_), split(/\./, $3)))), |
| 75 |
type => $type, |
| 76 |
status => $result->{status}, |
| 77 |
measure => $result->{measure} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
sub new { |
| 83 |
my ($class, %options) = @_; |
| 84 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); |
| 85 |
bless $self, $class; |
| 86 |
|
| 87 |
$options{options}->add_options(arguments => {}); |
| 88 |
|
| 89 |
return $self; |
| 90 |
} |
| 91 |
|
| 92 |
1; |
| 93 |
|
| 94 |
__END__ |
| 95 |
|
| 96 |
=head1 MODE |
| 97 |
|
| 98 |
Check hardware. |
| 99 |
|
| 100 |
=over 8 |
| 101 |
|
| 102 |
=item B<--component> |
| 103 |
|
| 104 |
Which component to check (default: '.*'). |
| 105 |
Can be: 'fan', 'led', 'nim', 'pem', 'pim', 'temperature', 'usb'. |
| 106 |
|
| 107 |
=item B<--filter> |
| 108 |
|
| 109 |
Exclude the items given as a comma-separated list (example: --filter=temperature). |
| 110 |
You can also exclude items from specific instances: --filter=temperature,Board |
| 111 |
|
| 112 |
=item B<--no-component> |
| 113 |
|
| 114 |
Define the expected status if no components are found (default: critical). |
| 115 |
|
| 116 |
|
| 117 |
=item B<--threshold-overload> |
| 118 |
|
| 119 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 120 |
Example: --threshold-overload='temperature,OK,down' |
| 121 |
|
| 122 |
=item B<--warning> |
| 123 |
|
| 124 |
Set warning threshold for 'temperature' (syntax: type,regexp,threshold) |
| 125 |
Example: --warning='temperature,.*,40' |
| 126 |
|
| 127 |
=item B<--critical> |
| 128 |
|
| 129 |
Set critical threshold for 'temperature' (syntax: type,regexp,threshold) |
| 130 |
Example: --critical='temperature,.*,50' |
| 131 |
|
| 132 |
=back |
| 133 |
|
| 134 |
=cut |