+ Enhance interfaces standard snmp
This commit is contained in:
parent
8733f31caf
commit
3314d61535
|
@ -256,18 +256,18 @@ sub custom_errors_calc {
|
|||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters} = {
|
||||
int => {
|
||||
'000_status' => { filter => 'add_status', threshold => 0,
|
||||
set => {
|
||||
key_values => $self->set_key_values_status(),
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_threshold_output'),
|
||||
}
|
||||
},
|
||||
'010_in-traffic' => { filter => 'add_traffic',
|
||||
$self->{maps_counters} = { int => {}, global => {} };
|
||||
$self->{maps_counters}->{int}->{'000_status'} = { filter => 'add_status', threshold => 0,
|
||||
set => {
|
||||
key_values => $self->set_key_values_status(),
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_threshold_output'),
|
||||
}
|
||||
};
|
||||
if ($self->{no_traffic} == 0 && $self->{no_set_traffic} == 0) {
|
||||
$self->{maps_counters}->{int}->{'020_in-traffic'} = { filter => 'add_traffic',
|
||||
set => {
|
||||
key_values => $self->set_key_values_in_traffic(),
|
||||
per_second => 1,
|
||||
|
@ -276,8 +276,8 @@ sub set_counters {
|
|||
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
|
||||
}
|
||||
},
|
||||
'011_out-traffic' => { filter => 'add_traffic',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'021_out-traffic'} = { filter => 'add_traffic',
|
||||
set => {
|
||||
key_values => $self->set_key_values_out_traffic(),
|
||||
per_second => 1,
|
||||
|
@ -286,44 +286,48 @@ sub set_counters {
|
|||
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
|
||||
}
|
||||
},
|
||||
'020_in-discard' => { filter => 'add_errors',
|
||||
};
|
||||
}
|
||||
if ($self->{no_errors} == 0 && $self->{no_set_errors} == 0) {
|
||||
$self->{maps_counters}->{int}->{'040_in-discard'} = { filter => 'add_errors',
|
||||
set => {
|
||||
key_values => [ { name => 'indiscard', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'discard' },
|
||||
closure_custom_output => \&custom_errors_output, output_error_template => 'Packets In Discard : %s',
|
||||
closure_custom_perfdata => \&custom_errors_perfdata,
|
||||
closure_custom_threshold_check => \&custom_errors_threshold,
|
||||
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'discard' },
|
||||
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Discard : %s',
|
||||
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
|
||||
}
|
||||
},
|
||||
'021_in-error' => { filter => 'add_errors',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'041_in-error'} = { filter => 'add_errors',
|
||||
set => {
|
||||
key_values => [ { name => 'inerror', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'error' },
|
||||
closure_custom_output => \&custom_errors_output, output_error_template => 'Packets In Error : %s',
|
||||
closure_custom_perfdata => \&custom_errors_perfdata,
|
||||
closure_custom_threshold_check => \&custom_errors_threshold,
|
||||
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'error' },
|
||||
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Error : %s',
|
||||
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
|
||||
}
|
||||
},
|
||||
'022_out-discard' => { filter => 'add_errors',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'042_out-discard'} = { filter => 'add_errors',
|
||||
set => {
|
||||
key_values => [ { name => 'outdiscard', diff => 1 }, { name => 'total_out_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'discard' },
|
||||
closure_custom_output => \&custom_errors_output, output_error_template => 'Packets Out Discard : %s',
|
||||
closure_custom_perfdata => \&custom_errors_perfdata,
|
||||
closure_custom_threshold_check => \&custom_errors_threshold,
|
||||
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'discard' },
|
||||
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Discard : %s',
|
||||
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
|
||||
}
|
||||
},
|
||||
'023_out-error' => { filter => 'add_errors',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'043_out-error'} = { filter => 'add_errors',
|
||||
set => {
|
||||
key_values => [ { name => 'outerror', diff => 1 }, { name => 'total_out_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_errors_calc, closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'error' },
|
||||
closure_custom_output => \&custom_errors_output, output_error_template => 'Packets Out Error : %s',
|
||||
closure_custom_perfdata => \&custom_errors_perfdata,
|
||||
closure_custom_threshold_check => \&custom_errors_threshold,
|
||||
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'error' },
|
||||
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Error : %s',
|
||||
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
|
||||
}
|
||||
},
|
||||
'030_in-ucast' => { filter => 'add_cast',
|
||||
};
|
||||
}
|
||||
if ($self->{no_cast} == 0 && $self->{no_set_cast} == 0) {
|
||||
$self->{maps_counters}->{int}->{'060_in-ucast'} = { filter => 'add_cast',
|
||||
set => {
|
||||
key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'iucast', total_ref1 => 'ibcast', total_ref2 => 'imcast' },
|
||||
|
@ -334,8 +338,8 @@ sub set_counters {
|
|||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'031_in-bcast' => { filter => 'add_cast',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'061_in-bcast'} = { filter => 'add_cast',
|
||||
set => {
|
||||
key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'ibcast', total_ref1 => 'iucast', total_ref2 => 'imcast' },
|
||||
|
@ -346,8 +350,8 @@ sub set_counters {
|
|||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'032_in-mcast' => { filter => 'add_cast',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'062_in-mcast'} = { filter => 'add_cast',
|
||||
set => {
|
||||
key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'imcast', total_ref1 => 'iucast', total_ref2 => 'ibcast' },
|
||||
|
@ -358,8 +362,8 @@ sub set_counters {
|
|||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'033_out-ucast' => { filter => 'add_cast',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'063_out-ucast'} = { filter => 'add_cast',
|
||||
set => {
|
||||
key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'oucast', total_ref1 => 'omcast', total_ref2 => 'obcast' },
|
||||
|
@ -370,8 +374,8 @@ sub set_counters {
|
|||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'034_out-bcast' => { filter => 'add_cast',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'064_out-bcast'} = { filter => 'add_cast',
|
||||
set => {
|
||||
key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'obcast', total_ref1 => 'omcast', total_ref2 => 'oucast' },
|
||||
|
@ -382,8 +386,8 @@ sub set_counters {
|
|||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'035_out-mcast' => { filter => 'add_cast',
|
||||
};
|
||||
$self->{maps_counters}->{int}->{'065_out-mcast'} = { filter => 'add_cast',
|
||||
set => {
|
||||
key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
|
||||
closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'ibcast', total_ref1 => 'iucast', total_ref2 => 'imcast' },
|
||||
|
@ -394,8 +398,8 @@ sub set_counters {
|
|||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
}};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
sub set_key_values_status {
|
||||
|
@ -498,7 +502,6 @@ sub check_oids_label {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (defined($self->{option_results}->{oid_extra_display})) {
|
||||
$self->{option_results}->{oid_extra_display} = lc($self->{option_results}->{oid_extra_display});
|
||||
if (!defined($self->{oids_label}->{$self->{option_results}->{oid_extra_display}})) {
|
||||
|
@ -534,23 +537,24 @@ sub default_oid_display_name {
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => defined($options{package}) ? $options{package} : __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{no_oid_options} = defined($options{no_oid_options}) && $options{no_oid_options} =~ /^[01]$/ ? $options{no_oid_options} : 0;
|
||||
$self->{no_interfaceid_options} = defined($options{no_interfaceid_options}) && $options{no_interfaceid_options} =~ /^[01]$/ ?
|
||||
$options{no_interfaceid_options} : 0;
|
||||
foreach (('traffic', 'errors', 'cast')) {
|
||||
$self->{'no_' . $_} = defined($options{'no_' . $_}) && $options{'no_' . $_} =~ /^[01]$/ ? $options{'no_' . $_} : 0;
|
||||
$self->{'no_set_' . $_} = defined($options{'no_set_' . $_}) && $options{'no_set_' . $_} =~ /^[01]$/ ? $options{'no_set_' . $_} : 0;
|
||||
}
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"add-status" => { name => 'add_status' },
|
||||
"add-traffic" => { name => 'add_traffic' },
|
||||
"add-errors" => { name => 'add_errors' },
|
||||
"add-cast" => { name => 'add_cast' },
|
||||
"warning-status:s" => { name => 'warning_status', default => $self->default_warning_status() },
|
||||
"critical-status:s" => { name => 'critical_status', default => $self->default_critical_status() },
|
||||
"oid-filter:s" => { name => 'oid_filter', default => $self->default_oid_filter_name() },
|
||||
"oid-display:s" => { name => 'oid_display', default => $self->default_oid_display_name() },
|
||||
"oid-extra-display:s" => { name => 'oid_extra_display' },
|
||||
"interface:s" => { name => 'interface' },
|
||||
"name" => { name => 'use_name' },
|
||||
"units-traffic:s" => { name => 'units_traffic', default => '%' },
|
||||
"units-errors:s" => { name => 'units_errors', default => '%' },
|
||||
"speed:s" => { name => 'speed' },
|
||||
|
@ -561,7 +565,33 @@ sub new {
|
|||
"show-cache" => { name => 'show_cache' },
|
||||
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
|
||||
"nagvis-perfdata" => { name => 'nagvis_perfdata' },
|
||||
});
|
||||
});
|
||||
if ($self->{no_traffic} == 0) {
|
||||
$options{options}->add_options(arguments => { "add-traffic" => { name => 'add_traffic' } });
|
||||
}
|
||||
if ($self->{no_errors} == 0) {
|
||||
$options{options}->add_options(arguments => { "add-errors" => { name => 'add_errors' } });
|
||||
}
|
||||
if ($self->{no_cast} == 0) {
|
||||
$options{options}->add_options(arguments => { "add-cast" => { name => 'add_cast' }, });
|
||||
}
|
||||
if ($self->{no_oid_options} == 0) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"oid-filter:s" => { name => 'oid_filter', default => $self->default_oid_filter_name() },
|
||||
"oid-display:s" => { name => 'oid_display', default => $self->default_oid_display_name() },
|
||||
"oid-extra-display:s" => { name => 'oid_extra_display' },
|
||||
}
|
||||
);
|
||||
}
|
||||
if ($self->{no_interfaceid_options} == 0) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"name" => { name => 'use_name' },
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
$self->set_counters();
|
||||
|
@ -637,7 +667,6 @@ sub check_options {
|
|||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
@ -771,7 +800,7 @@ sub reload_cache {
|
|||
|
||||
my $result = $self->{snmp}->get_multiple_table(oids => $snmp_get);
|
||||
foreach ($self->{snmp}->oid_lex_sort(keys %{$result->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}})) {
|
||||
/\.([0-9]+)$/;
|
||||
/^$self->{oids_label}->{$self->{option_results}->{oid_filter}}\.(.*)$/;
|
||||
push @{$datas->{all_ids}}, $1;
|
||||
$datas->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}->{$_});
|
||||
}
|
||||
|
@ -783,14 +812,14 @@ sub reload_cache {
|
|||
|
||||
if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) {
|
||||
foreach ($self->{snmp}->oid_lex_sort(keys %{$result->{$self->{oids_label}->{$self->{option_results}->{oid_display}}}})) {
|
||||
/\.([0-9]+)$/;
|
||||
/^$self->{oids_label}->{$self->{option_results}->{oid_display}}\.(.*)$/;
|
||||
$datas->{$self->{option_results}->{oid_display} . "_" . $1} = $self->{output}->to_utf8($result->{$self->{oids_label}->{$self->{option_results}->{oid_display}}}->{$_});
|
||||
}
|
||||
}
|
||||
if (defined($self->{option_results}->{oid_extra_display}) && $self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_display} &&
|
||||
$self->{option_results}->{oid_extra_display} ne $self->{option_results}->{oid_filter}) {
|
||||
foreach ($self->{snmp}->oid_lex_sort(keys %{$result->{$self->{oids_label}->{$self->{option_results}->{oid_extra_display}}}})) {
|
||||
/\.([0-9]+)$/;
|
||||
/^$self->{oids_label}->{$self->{option_results}->{oid_extra_display}}\.(.*)$/;
|
||||
$datas->{$self->{option_results}->{oid_extra_display} . "_" . $1} = $self->{output}->to_utf8($result->{$self->{oids_label}->{$self->{option_results}->{oid_extra_display}}}->{$_});
|
||||
}
|
||||
}
|
||||
|
@ -827,7 +856,8 @@ sub get_selection {
|
|||
}
|
||||
|
||||
my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
|
||||
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
|
||||
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})
|
||||
&& $self->{no_interfaceid_options} == 0) {
|
||||
foreach (@{$all_ids}) {
|
||||
if ($self->{option_results}->{interface} =~ /(^|\s|,)$_(\s*,|$)/) {
|
||||
$self->add_selected_interface(id => $_);
|
||||
|
|
|
@ -25,21 +25,61 @@ use base qw(centreon::plugins::mode);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my @operstatus = ("up", "down", "testing", "unknown", "dormant", "notPresent", "lowerLayerDown");
|
||||
my %oids_iftable = (
|
||||
'ifdesc' => '.1.3.6.1.2.1.2.2.1.2',
|
||||
'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18',
|
||||
'ifname' => '.1.3.6.1.2.1.31.1.1.1.1'
|
||||
);
|
||||
|
||||
my $oid_adminstatus = '.1.3.6.1.2.1.2.2.1.7';
|
||||
my $oid_operstatus = '.1.3.6.1.2.1.2.2.1.8';
|
||||
my $oid_speed32 = '.1.3.6.1.2.1.2.2.1.5'; # in b/s
|
||||
my $oid_speed64 = '.1.3.6.1.2.1.31.1.1.1.15';
|
||||
|
||||
sub set_oids_status {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{oid_adminstatus} = '.1.3.6.1.2.1.2.2.1.7';
|
||||
$self->{oid_adminstatus_mapping} = {
|
||||
1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown',
|
||||
};
|
||||
$self->{oid_opstatus} = '.1.3.6.1.2.1.2.2.1.8';
|
||||
$self->{oid_opstatus_mapping} = {
|
||||
1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown',
|
||||
};
|
||||
}
|
||||
|
||||
sub check_oids_label {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (('oid_filter', 'oid_display')) {
|
||||
$self->{option_results}->{$_} = lc($self->{option_results}->{$_}) if (defined($self->{option_results}->{$_}));
|
||||
if (!defined($self->{oids_label}->{$self->{option_results}->{$_}})) {
|
||||
my $label = $_;
|
||||
$label =~ s/_/-/g;
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported oid in --" . $label . " option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub set_oids_label {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{oids_label} = {
|
||||
'ifdesc' => '.1.3.6.1.2.1.2.2.1.2',
|
||||
'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18',
|
||||
'ifname' => '.1.3.6.1.2.1.31.1.1.1.1',
|
||||
};
|
||||
}
|
||||
|
||||
sub default_oid_filter_name {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 'ifname';
|
||||
}
|
||||
|
||||
sub default_oid_display_name {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 'ifname';
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => defined($options{package}) ? $options{package} : __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
|
@ -51,12 +91,11 @@ sub new {
|
|||
"filter-status:s" => { name => 'filter_status' },
|
||||
"skip-speed0" => { name => 'skip_speed0' },
|
||||
"use-adminstatus" => { name => 'use_adminstatus' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
"oid-filter:s" => { name => 'oid_filter', default => 'ifname'},
|
||||
"oid-display:s" => { name => 'oid_display', default => 'ifname'},
|
||||
"oid-filter:s" => { name => 'oid_filter', default => $self->default_oid_filter_name() },
|
||||
"oid-display:s" => { name => 'oid_display', default => $self->default_oid_display_name() },
|
||||
"display-transform-src:s" => { name => 'display_transform_src' },
|
||||
"display-transform-dst:s" => { name => 'display_transform_dst' },
|
||||
"add-extra-oid:s@" => { name => 'add_extra_oid' },
|
||||
});
|
||||
|
||||
$self->{interface_id_selected} = [];
|
||||
|
@ -68,21 +107,24 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
$self->{option_results}->{oid_filter} = lc($self->{option_results}->{oid_filter});
|
||||
if ($self->{option_results}->{oid_filter} !~ /^(ifdesc|ifalias|ifname)$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported --oid-filter option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{option_results}->{oid_display} = lc($self->{option_results}->{oid_display});
|
||||
if ($self->{option_results}->{oid_display} !~ /^(ifdesc|ifalias|ifname)$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported --oid-display option.");
|
||||
$self->{output}->option_exit();
|
||||
$self->set_oids_label();
|
||||
$self->check_oids_label();
|
||||
$self->set_oids_status();
|
||||
|
||||
$self->{extra_oids} = {};
|
||||
foreach (@{$self->{option_results}->{add_extra_oid}}) {
|
||||
next if ($_ eq '');
|
||||
my ($name, $oid) = split /,/;
|
||||
if (!defined($oid) || $oid !~ /^(\.\d+){1,}$/ || $name eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong syntax for add-extra-oid '" . $_ . "' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{extra_oids}->{$name} = $oid;
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
$self->manage_selection();
|
||||
|
@ -101,16 +143,24 @@ sub run {
|
|||
$self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': interface speed is 0 and option --skip-speed0 is set");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_status}) && $operstatus[$result->{$oid_operstatus . "." . $_} - 1] !~ /$self->{option_results}->{filter_status}/i) {
|
||||
if (defined($self->{option_results}->{filter_status}) && defined($result->{$self->{oid_opstatus} . "." . $_}) &&
|
||||
$self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} !~ /$self->{option_results}->{filter_status}/i) {
|
||||
$self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': no matching filter status");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_adminstatus}) && $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] ne 'up') {
|
||||
if (defined($self->{option_results}->{use_adminstatus}) && defined($result->{$self->{oid_adminstatus} . "." . $_}) &&
|
||||
$self->{oid_adminstatus_mapping}->{$result->{$self->{oid_adminstatus} . "." . $_}} ne 'up') {
|
||||
$self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': adminstatus is not 'up' and option --use-adminstatus is set");
|
||||
next;
|
||||
}
|
||||
my $extra_display = '';
|
||||
my $extra_display_append = ' ';
|
||||
foreach my $name (keys %{$self->{extra_oids}}) {
|
||||
$extra_display .= $extra_display_append . $name . ' = ' . (defined($result->{$self->{extra_oids}->{$name} . "." . $_}) ? $result->{$self->{extra_oids}->{$name} . "." . $_} : '');
|
||||
$extra_display_append = ', ';
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "'" . $display_value . "' [speed = $interface_speed, status = " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1] . ", id = $_]");
|
||||
$self->{output}->output_add(long_msg => "'" . $display_value . "' [speed = $interface_speed, status = " . $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} . ', id = ' . $_ . $extra_display . ']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
|
@ -122,9 +172,12 @@ sub run {
|
|||
sub get_additional_information {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $oids = [$oid_adminstatus, $oid_operstatus, $oid_speed32];
|
||||
if (!$self->{snmp}->is_snmpv1()) {
|
||||
push @$oids, $oid_speed64;
|
||||
my $oids = [$oid_speed32];
|
||||
push @$oids, $self->{oid_adminstatus} if (defined($self->{oid_adminstatus}));
|
||||
push @$oids, $self->{oid_opstatus} if (defined($self->{oid_opstatus}));
|
||||
push @$oids, $oid_speed64 if (!$self->{snmp}->is_snmpv1());
|
||||
if (scalar(keys %{$self->{extra_oids}}) > 0) {
|
||||
push @$oids, values %{$self->{extra_oids}};
|
||||
}
|
||||
|
||||
$self->{snmp}->load(oids => $oids, instances => $self->{interface_id_selected});
|
||||
|
@ -146,12 +199,10 @@ sub manage_selection {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{datas} = {};
|
||||
$self->{datas}->{oid_filter} = $self->{option_results}->{oid_filter};
|
||||
$self->{datas}->{oid_display} = $self->{option_results}->{oid_display};
|
||||
my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}});
|
||||
my $result = $self->{snmp}->get_table(oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}});
|
||||
$self->{datas}->{all_ids} = [];
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
next if ($key !~ /^$self->{oids_label}->{$self->{option_results}->{oid_filter}}\.(.*)$/);
|
||||
$self->{datas}->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$key});
|
||||
push @{$self->{datas}->{all_ids}}, $1;
|
||||
}
|
||||
|
@ -162,60 +213,52 @@ sub manage_selection {
|
|||
}
|
||||
|
||||
if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) {
|
||||
$result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_display}});
|
||||
$result = $self->{snmp}->get_table(oid => $self->{oids_label}->{$self->{option_results}->{oid_display}});
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
next if ($key !~ /^$self->{oids_label}->{$self->{option_results}->{oid_display}}\.(.*)$/);
|
||||
$self->{datas}->{$self->{option_results}->{oid_display} . "_" . $1} = $self->{output}->to_utf8($result->{$key});
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
|
||||
# get by ID
|
||||
push @{$self->{interface_id_selected}}, $self->{option_results}->{interface};
|
||||
my $name = $self->{datas}->{$self->{option_results}->{oid_display} . "_" . $self->{option_results}->{interface}};
|
||||
if (!defined($name)) {
|
||||
$self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
foreach (@{$self->{datas}->{all_ids}}) {
|
||||
if ($self->{option_results}->{interface} =~ /(^|\s|,)$_(\s*,|$)/) {
|
||||
push @{$self->{interface_id_selected}}, $_;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach my $i (@{$self->{datas}->{all_ids}}) {
|
||||
my $filter_name = $self->{datas}->{$self->{option_results}->{oid_filter} . "_" . $i};
|
||||
foreach (@{$self->{datas}->{all_ids}}) {
|
||||
my $filter_name = $self->{datas}->{$self->{option_results}->{oid_filter} . "_" . $_};
|
||||
next if (!defined($filter_name));
|
||||
|
||||
if (!defined($self->{option_results}->{interface})) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
push @{$self->{interface_id_selected}}, $_;
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
}
|
||||
if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
if ($filter_name =~ /$self->{option_results}->{interface}/) {
|
||||
push @{$self->{interface_id_selected}}, $_;
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{interface_id_selected}}) <= 0 && !defined($options{disco})) {
|
||||
if (defined($self->{option_results}->{interface})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No interface found.");
|
||||
}
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{interface_id_selected}}) <= 0 && !defined($options{disco})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['name', 'total', 'status', 'interfaceid']);
|
||||
my $names = ['name', 'total', 'status', 'interfaceid'];
|
||||
if (scalar(keys %{$self->{extra_oids}}) > 0) {
|
||||
push @$names, keys %{$self->{extra_oids}};
|
||||
}
|
||||
$self->{output}->add_disco_format(elements => $names);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
$self->manage_selection(disco => 1);
|
||||
|
@ -230,17 +273,22 @@ sub disco_show {
|
|||
$interface_speed = $self->{option_results}->{speed};
|
||||
}
|
||||
next if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0);
|
||||
if (defined($self->{option_results}->{filter_status}) && $operstatus[$result->{$oid_operstatus . "." . $_} - 1] !~ /$self->{option_results}->{filter_status}/i) {
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_adminstatus}) && $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] ne 'up') {
|
||||
next;
|
||||
next if (defined($self->{option_results}->{filter_status}) && defined($result->{$self->{oid_opstatus} . "." . $_}) &&
|
||||
$self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} !~ /$self->{option_results}->{filter_status}/i);
|
||||
next if (defined($self->{option_results}->{use_adminstatus}) && defined($result->{$self->{oid_adminstatus} . "." . $_}) &&
|
||||
$self->{oid_adminstatus_mapping}->{$result->{$self->{oid_adminstatus} . "." . $_}} ne 'up');
|
||||
|
||||
my %extra_values = ();
|
||||
foreach my $name (keys %{$self->{extra_oids}}) {
|
||||
$extra_values{$name} = defined($result->{$self->{extra_oids}->{$name} . "." . $_}) ?
|
||||
$result->{$self->{extra_oids}->{$name} . "." . $_} : '';
|
||||
}
|
||||
|
||||
$self->{output}->add_disco_entry(name => $display_value,
|
||||
total => $interface_speed,
|
||||
status => $result->{$oid_operstatus . "." . $_},
|
||||
interfaceid => $_);
|
||||
status => $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}},
|
||||
interfaceid => $_,
|
||||
%extra_values);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,19 +302,11 @@ __END__
|
|||
|
||||
=item B<--interface>
|
||||
|
||||
Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface').
|
||||
Set the interface (number expected) ex: 1,2,... (empty means 'check all interface').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use interface name with option --interface instead of interface oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter interfaces (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
Allows to use interface name with option --interface instead of interface oid index (Can be a regexp)
|
||||
|
||||
=item B<--speed>
|
||||
|
||||
|
@ -300,6 +340,10 @@ Regexp src to transform display value. (security risk!!!)
|
|||
|
||||
Regexp dst to transform display value. (security risk!!!)
|
||||
|
||||
=item B<--add-extra-oid>
|
||||
|
||||
Display an OID. Example: --add-extra-oid='alias,.1.3.6.1.2.1.31.1.1.1.18'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
Loading…
Reference in New Issue