enhance hardware junos

This commit is contained in:
garnier-quentin 2019-05-22 14:23:58 +02:00
parent 0420758dc4
commit c73f4da0ba
5 changed files with 114 additions and 33 deletions

View File

@ -0,0 +1,73 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::juniper::common::junos::mode::components::alarm;
use strict;
use warnings;
my %map_alarm_states = (
1 => 'other',
2 => 'off',
3 => 'on',
);
sub check_alarm {
my ($self, %options) = @_;
return if ($self->check_filter(section => 'alarm', instance => $options{instance}, name => $options{name}));
$self->{components}->{alarm}->{total}++;
$self->{output}->output_add(long_msg =>
sprintf(
"alarm '%s' state is %s [instance: %s]",
$options{name}, $options{value}, $options{instance}
)
);
my $exit = $self->get_severity(section => 'alarm', value => $options{value});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Alarm '%s' state is %s",
$options{name}, $options{value}
)
);
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking alarms");
$self->{components}->{alarm} = { name => 'alarm', total => 0, skip => 0 };
return if ($self->check_filter(section => 'alarm'));
my $oid_jnxYellowAlarmState = '.1.3.6.1.4.1.2636.3.4.2.2.1.0';
my $oid_jnxRedAlarmState = '.1.3.6.1.4.1.2636.3.4.2.3.1.0';
my $results = $self->{snmp}->get_leef(oids => [$oid_jnxYellowAlarmState, $oid_jnxRedAlarmState]);
check_alarm($self, instance => 0, name => 'yellow', value => $map_alarm_states{$results->{$oid_jnxYellowAlarmState}})
if (defined($results->{$oid_jnxYellowAlarmState}));
check_alarm($self, instance => 0, name => 'red', value => $map_alarm_states{$results->{$oid_jnxRedAlarmState}})
if (defined($results->{$oid_jnxRedAlarmState}));
}
1;

View File

@ -69,7 +69,7 @@ sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking frus");
$self->{components}->{fru} = {name => 'frus', total => 0, skip => 0};
$self->{components}->{fru} = { name => 'frus', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fru'));
my $mapping = {
@ -82,15 +82,15 @@ sub check {
foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName})) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
next if ($self->check_filter(section => 'fru', instance => $instance));
my $name = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName}, instance => $instance);
next if ($self->check_filter(section => 'fru', instance => $instance, name => $name));
next if ($result->{jnxFruState} =~ /empty/i &&
$self->absent_problem(section => 'fru', instance => $instance));
$self->absent_problem(section => 'fru', instance => $instance, name => $name));
$self->{components}->{fru}->{total}++;
my $name = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName}, instance => $instance);
my $type = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruType}, instance => $instance);
$self->{output}->output_add(long_msg => sprintf("Fru '%s' state is %s [instance: %s, type: %s, offline reason: %s]",
$self->{output}->output_add(long_msg => sprintf("fru '%s' state is %s [instance: %s, type: %s, offline reason: %s]",
$name, $result->{jnxFruState},
$instance, $map_fru_type{$type}, $result->{jnxFruOfflineReason}));
my $exit = $self->get_severity(section => 'fru', value => $result->{jnxFruState});
@ -101,7 +101,7 @@ sub check {
}
if (defined($result->{jnxFruTemp}) && $result->{jnxFruTemp} != 0) {
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fru-temperature', instance => $instance, value => $result->{jnxFruTemp});
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fru-temperature', instance => $instance, name => $name, value => $result->{jnxFruTemp});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("Fru '%s' temperature is %s degree centigrade", $name, $result->{jnxFruTemp}));

View File

@ -37,7 +37,7 @@ sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking operatings");
$self->{components}->{operating} = {name => 'operatings', total => 0, skip => 0};
$self->{components}->{operating} = { name => 'operatings', total => 0, skip => 0 };
return if ($self->check_filter(section => 'operating'));
my $mapping = {
@ -48,12 +48,12 @@ sub check {
foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, oid_name => $self->{oids_operating}->{jnxOperatingDescr})) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
next if ($self->check_filter(section => 'operating', instance => $instance));
my $desc = $self->get_cache(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, oid_name => $self->{oids_operating}->{jnxOperatingDescr}, instance => $instance);
next if ($self->check_filter(section => 'operating', instance => $instance, name => $desc));
$self->{components}->{operating}->{total}++;
my $desc = $self->get_cache(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, oid_name => $self->{oids_operating}->{jnxOperatingDescr}, instance => $instance);
$self->{output}->output_add(long_msg => sprintf("Operating '%s' state is %s [instance: %s]",
$self->{output}->output_add(long_msg => sprintf("operating '%s' state is %s [instance: %s]",
$desc, $result->{jnxOperatingState}, $instance));
my $exit = $self->get_severity(section => 'operating', value => $result->{jnxOperatingState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
@ -64,4 +64,4 @@ sub check {
}
}
1;
1;

View File

@ -29,7 +29,7 @@ use centreon::plugins::statefile;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fru|operating)$';
$self->{regexp_threshold_overload_check_section_option} = '^(fru|operating|alarm)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(fru-temperature)$';
$self->{cb_hook1} = 'init_cache';
@ -58,10 +58,15 @@ sub set_system {
['down', 'CRITICAL'],
['standby', 'OK'],
],
alarm => [
['other', 'OK'],
['off', 'OK'],
['on', 'CRITICAL'],
],
};
$self->{components_path} = 'network::juniper::common::junos::mode::components';
$self->{components_module} = ['fru', 'operating'];
$self->{components_module} = ['fru', 'operating', 'alarm'];
}
sub snmp_execute {
@ -78,10 +83,9 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
});
$options{options}->add_options(arguments => {
'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
@ -163,7 +167,7 @@ sub get_type {
my $result = $options{snmp}->get_leef(oids => [$oid_jnxBoxDescr]);
$self->{env_type} = defined($result->{$oid_jnxBoxDescr}) ? $result->{$oid_jnxBoxDescr} : 'unknown';
$self->{output}->output_add(long_msg => sprintf("Environment type: %s", $self->{env_type}));
$self->{output}->output_add(long_msg => sprintf("environment type: %s", $self->{env_type}));
}
sub load_components {
@ -204,7 +208,11 @@ Check Hardware (JUNIPER-MIB) (frus, operating).
=item B<--component>
Which component to check (Default: '.*').
Can be: 'fru', 'operating'.
Can be: 'fru', 'operating', 'alarm'.
=item B<--add-name-instance>
Add literal description for instance value (used in filter, absent-problem and threshold options).
=item B<--filter>
@ -245,4 +253,4 @@ Use '-1' to disable cache reload.
=back
=cut

View File

@ -31,17 +31,17 @@ sub new {
$self->{version} = '1.0';
%{$self->{modes}} = (
'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine
'hardware' => 'network::juniper::common::junos::mode::hardware',
'interfaces' => 'snmp_standard::mode::interfaces',
'ldp-session-status' => 'network::juniper::common::junos::mode::ldpsessionstatus',
'lsp-status' => 'network::juniper::common::junos::mode::lspstatus',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-storages' => 'snmp_standard::mode::liststorages',
'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine
'rsvp-session-status' => 'network::juniper::common::junos::mode::rsvpsessionstatus',
'storage' => 'snmp_standard::mode::storage',
);
'cpu-routing' => 'network::juniper::common::junos::mode::cpurouting', # routing engine
'hardware' => 'network::juniper::common::junos::mode::hardware',
'interfaces' => 'snmp_standard::mode::interfaces',
'ldp-session-status' => 'network::juniper::common::junos::mode::ldpsessionstatus',
'lsp-status' => 'network::juniper::common::junos::mode::lspstatus',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-storages' => 'snmp_standard::mode::liststorages',
'memory-routing' => 'network::juniper::common::junos::mode::memoryrouting', # routing engine
'rsvp-session-status' => 'network::juniper::common::junos::mode::rsvpsessionstatus',
'storage' => 'snmp_standard::mode::storage',
);
return $self;
}