migrate interfaces mode to counter class

This commit is contained in:
garnier-quentin 2019-06-03 11:04:57 +02:00
parent 577eaab82d
commit deddea9211
6 changed files with 598 additions and 651 deletions

View File

@ -35,22 +35,21 @@ sub set_oids_errors {
$self->{oid_ifInCrc} = '.1.3.6.1.4.1.9.2.2.1.1.12';
}
sub set_counters {
sub set_counters_errors {
my ($self, %options) = @_;
$self->{maps_counters} = { int => {}, global => {} };
$self->SUPER::set_counters_errors(%options);
$self->{maps_counters}->{int}->{'045_in-crc'} = { filter => 'add_errors',
set => {
key_values => [ { name => 'incrc', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' },
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %s',
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
}
};
$self->SUPER::set_counters(%options);
push @{$self->{maps_counters}->{int}},
{ label => 'in-crc', filter => 'add_errors', set => {
key_values => [ { name => 'incrc', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' },
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %s',
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
}
},
;
}
sub new {
@ -78,11 +77,11 @@ sub load_errors {
sub add_result_errors {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{indiscard} = $self->{results}->{$self->{oid_ifInDiscards} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{inerror} = $self->{results}->{$self->{oid_ifInErrors} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{outdiscard} = $self->{results}->{$self->{oid_ifOutDiscards} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{outerror} = $self->{results}->{$self->{oid_ifOutErrors} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{incrc} = $self->{results}->{$self->{oid_ifInCrc} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{indiscard} = $self->{results}->{$self->{oid_ifInDiscards} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{inerror} = $self->{results}->{$self->{oid_ifInErrors} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{outdiscard} = $self->{results}->{$self->{oid_ifOutDiscards} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{outerror} = $self->{results}->{$self->{oid_ifOutErrors} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{incrc} = $self->{results}->{$self->{oid_ifInCrc} . '.' . $options{instance}};
}
1;

View File

@ -66,6 +66,16 @@ sub set_counters {
#};
}
sub get_callback {
my ($self, %options) = @_;
if (defined($options{method_name})) {
return $self->can($options{method_name});
}
return undef;
}
sub call_object_callback {
my ($self, %options) = @_;
@ -121,7 +131,7 @@ sub new {
}
$self->{maps_counters} = {} if (!defined($self->{maps_counters}));
$self->set_counters();
$self->set_counters(%options);
foreach my $key (keys %{$self->{maps_counters}}) {
foreach (@{$self->{maps_counters}->{$key}}) {
@ -270,6 +280,7 @@ sub run_instances {
my ($self, %options) = @_;
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $cb_init_counters = $self->get_callback(method_name => $options{config}->{cb_init_counters});
my $display_status_lo = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0;
my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0;
my $no_message_multiple = 1;
@ -291,10 +302,11 @@ sub run_instances {
my @exits = ();
foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/);
next if ($cb_init_counters && $self->$cb_init_counters(%$_) == 1);
$no_message_multiple = 0;
$obj->set(instance => $id);

View File

@ -36,62 +36,65 @@ sub set_oids_traffic {
$self->{currentEthRxHighSpeed1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.89.1.4'; # in B
}
sub set_counters_traffic {
my ($self, %options) = @_;
push @{$self->{maps_counters}->{int}},
{ label => 'traffic-in', filter => 'add_traffic', set => {
key_values => [ { name => 'traffic_in_15min', diff => 1 }, { name => 'traffic_in_1day', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'traffic-out', filter => 'add_traffic', set => {
key_values => [ { name => 'traffic_out_15min', diff => 1 }, { name => 'traffic_out_1day', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters} = { int => {}, global => {} };
$self->{maps_counters}->{int}->{'030_traffic-in'} = { filter => 'add_traffic',
set => {
key_values => [ { name => 'traffic_in_15min', diff => 1 }, { name => 'traffic_in_1day', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'031_traffic-out'} = { filter => 'add_traffic',
set => {
key_values => [ { name => 'traffic_out_15min', diff => 1 }, { name => 'traffic_out_1day', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'090_laser-temp'} = { filter => 'add_optical',
set => {
key_values => [ { name => 'laser_temp' }, { name => 'display' } ],
output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f',
perfdatas => [
{ label => 'laser_temp', value => 'laser_temp_absolute', template => '%.2f',
unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
};
$self->{maps_counters}->{int}->{'091_input-power'} = { filter => 'add_optical',
set => {
key_values => [ { name => 'input_power' }, { name => 'display' } ],
output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s',
perfdatas => [
{ label => 'input_power', value => 'input_power_absolute', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
};
$self->{maps_counters}->{int}->{'091_output-power'} = { filter => 'add_optical',
set => {
key_values => [ { name => 'output_power' }, { name => 'display' } ],
output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s',
perfdatas => [
{ label => 'output_power', value => 'output_power_absolute', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
};
$self->SUPER::set_counters(%options);
push @{$self->{maps_counters}->{int}},
{ label => 'laser-temp', filter => 'add_optical', set => {
key_values => [ { name => 'laser_temp' }, { name => 'display' } ],
output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f',
perfdatas => [
{ label => 'laser_temp', value => 'laser_temp_absolute', template => '%.2f',
unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'input-power', filter => 'add_optical', set => {
key_values => [ { name => 'input_power' }, { name => 'display' } ],
output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s',
perfdatas => [
{ label => 'input_power', value => 'input_power_absolute', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'output-power', filter => 'add_optical', set => {
key_values => [ { name => 'output_power' }, { name => 'display' } ],
output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s',
perfdatas => [
{ label => 'output_power', value => 'output_power_absolute', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
;
}
sub custom_traffic_perfdata {
@ -173,15 +176,26 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_set_traffic => 1, no_errors => 1, no_cast => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"add-optical" => { name => 'add_optical' },
}
$options{options}->add_options(arguments => {
'add-optical' => { name => 'add_optical' },
}
);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->{checking} = '';
foreach (('add_global', 'add_status', 'add_traffic', 'add_speed', 'add_volume', 'add_optical')) {
if (defined($self->{option_results}->{$_})) {
$self->{checking} .= $_;
}
}
}
my $oid_opticalIfDiagLaserTemp = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.2';
my $oid_opticalIfDiagInputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.3';
my $oid_opticalIfDiagOutputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.4';
@ -197,24 +211,24 @@ sub custom_load {
sub custom_add_result {
my ($self, %options) = @_;
return if (!defined($self->{option_results}->{add_optical}));
$self->{interface_selected}->{$options{instance}}->{laser_temp} = undef;
$self->{int}->{$options{instance}}->{laser_temp} = undef;
if (defined($self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}}) &&
$self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} != -2147483648) {
$self->{interface_selected}->{$options{instance}}->{laser_temp} = $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} * 0.1;
$self->{int}->{$options{instance}}->{laser_temp} = $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} * 0.1;
}
$self->{interface_selected}->{$options{instance}}->{input_power} = undef;
$self->{int}->{$options{instance}}->{input_power} = undef;
if (defined($self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}}) &&
$self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} != -65535) {
$self->{interface_selected}->{$options{instance}}->{input_power} = $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} / 10;
$self->{int}->{$options{instance}}->{input_power} = $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} / 10;
}
$self->{interface_selected}->{$options{instance}}->{output_power} = undef;
$self->{int}->{$options{instance}}->{output_power} = undef;
if (defined($self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}}) &&
$self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} != -65535) {
$self->{interface_selected}->{$options{instance}}->{output_power} = $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} / 10;
$self->{int}->{$options{instance}}->{output_power} = $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} / 10;
}
}
@ -235,26 +249,26 @@ sub load_traffic {
sub add_result_traffic {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{traffic_in_15min} =
$self->{int}->{$options{instance}}->{traffic_in_15min} =
defined($self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}} * 8 :
(defined($self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}} * 8 : undef);
$self->{interface_selected}->{$options{instance}}->{traffic_in_1day} =
$self->{int}->{$options{instance}}->{traffic_in_1day} =
defined($self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}} * 8 :
(defined($self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}} * 8 : undef);
$self->{interface_selected}->{$options{instance}}->{traffic_out_15min} =
$self->{int}->{$options{instance}}->{traffic_out_15min} =
defined($self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}} * 8 : undef;
$self->{interface_selected}->{$options{instance}}->{traffic_out_1day} =
$self->{int}->{$options{instance}}->{traffic_out_1day} =
defined($self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}} * 8 : undef;
$self->{interface_selected}->{$options{instance}}->{speed_in} = 0;
$self->{interface_selected}->{$options{instance}}->{speed_out} = 0;
$self->{int}->{$options{instance}}->{speed_in} = 0;
$self->{int}->{$options{instance}}->{speed_out} = 0;
if ($self->{get_speed} == 0) {
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
}
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
}
}

View File

@ -142,72 +142,72 @@ sub default_oid_display_name {
return 'atrConnCepGenDescr';
}
sub set_counters {
sub set_counters_traffic {
my ($self, %options) = @_;
$self->{maps_counters} = { int => {}, global => {} };
$self->{maps_counters}->{int}->{'030_in-cir'} = { filter => 'add_traffic',
set => {
key_values => [ { name => 'in_cir', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_cir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In CIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'031_in-eir'} = { filter => 'add_traffic',
set => {
key_values => [ { name => 'in_eir', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In EIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'032_out-cir'} = { filter => 'add_traffic',
set => {
key_values => [ { name => 'out_cir', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_cir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out CIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'033_out-eir'} = { filter => 'add_traffic',
set => {
key_values => [ { name => 'out_eir', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out EIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'050_in-eir-discard'} = { filter => 'add_errors',
set => {
key_values => [ { name => 'in_eir_discard', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir_discard' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In EIR Discard : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->{maps_counters}->{int}->{'051_out-eir-discard'} = { filter => 'add_errors',
set => {
key_values => [ { name => 'out_eir_discard', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir_discard' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out EIR Discard : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
};
$self->SUPER::set_counters(%options);
push @{$self->{maps_counters}->{int}},
{ label => 'in-cir', filter => 'add_traffic', set => {
key_values => [ { name => 'in_cir', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_cir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In CIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'in-eir', filter => 'add_traffic', set => {
key_values => [ { name => 'in_eir', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In EIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'out-cir', filter => 'add_traffic', set => {
key_values => [ { name => 'out_cir', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_cir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out CIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'out-eir', filter => 'add_traffic', set => {
key_values => [ { name => 'out_eir', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out EIR : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
;
}
sub set_counters_errors {
my ($self, %options) = @_;
push @{$self->{maps_counters}->{int}},
{ label => 'in-eir-discard', filter => 'add_errors', set => {
key_values => [ { name => 'in_eir_discard', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir_discard' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In EIR Discard : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'out-eir-discard', filter => 'add_errors', set => {
key_values => [ { name => 'out_eir_discard', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir_discard' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out EIR Discard : %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
;
}
sub custom_traffic_perfdata {
@ -239,9 +239,9 @@ sub custom_traffic_threshold {
my $exit = 'ok';
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
} elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
}
return $exit;
}
@ -333,41 +333,41 @@ sub load_errors {
sub add_result_speed {
my ($self, %options) = @_;
return if (defined($self->{interface_selected}->{$options{instance}}->{speed_in}));
$self->{interface_selected}->{$options{instance}}->{speed_in} = 0;
$self->{interface_selected}->{$options{instance}}->{speed_out} = 0;
return if (defined($self->{int}->{$options{instance}}->{speed_in}));
$self->{int}->{$options{instance}}->{speed_in} = 0;
$self->{int}->{$options{instance}}->{speed_out} = 0;
if ($self->{get_speed} == 0) {
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
}
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
} else {
my $interface_speed = defined($self->{results}->{$self->{oid_speed} . "." . $options{instance}}) ? $self->{results}->{$self->{oid_speed} . "." . $options{instance}} : 0;
$interface_speed *= 1000;
$self->{interface_selected}->{$options{instance}}->{speed_in} = $interface_speed;
$self->{interface_selected}->{$options{instance}}->{speed_out} = $interface_speed;
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
$self->{int}->{$options{instance}}->{speed_in} = $interface_speed;
$self->{int}->{$options{instance}}->{speed_out} = $interface_speed;
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
}
}
sub add_result_errors {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{in_eir_discard} = $self->{results}->{$self->{oid_ing_eir_discard} . '.' . $options{instance}} * 8;
$self->{interface_selected}->{$options{instance}}->{out_eir_discard} = $self->{results}->{$self->{oid_eg_eir_discard} . '.' . $options{instance}} * 8;
$self->{int}->{$options{instance}}->{in_eir_discard} = $self->{results}->{$self->{oid_ing_eir_discard} . '.' . $options{instance}} * 8;
$self->{int}->{$options{instance}}->{out_eir_discard} = $self->{results}->{$self->{oid_eg_eir_discard} . '.' . $options{instance}} * 8;
$self->add_result_speed(%options);
}
sub add_result_traffic {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{in_cir} = $self->{results}->{$self->{oid_ing_cir} . '.' . $options{instance}} * 8;
$self->{interface_selected}->{$options{instance}}->{in_eir} = $self->{results}->{$self->{oid_ing_eir} . '.' . $options{instance}} * 8;
$self->{interface_selected}->{$options{instance}}->{out_cir} = $self->{results}->{$self->{oid_eg_cir} . '.' . $options{instance}} * 8;
$self->{interface_selected}->{$options{instance}}->{out_eir} = $self->{results}->{$self->{oid_eg_eir} . '.' . $options{instance}} * 8;
$self->{int}->{$options{instance}}->{in_cir} = $self->{results}->{$self->{oid_ing_cir} . '.' . $options{instance}} * 8;
$self->{int}->{$options{instance}}->{in_eir} = $self->{results}->{$self->{oid_ing_eir} . '.' . $options{instance}} * 8;
$self->{int}->{$options{instance}}->{out_cir} = $self->{results}->{$self->{oid_eg_cir} . '.' . $options{instance}} * 8;
$self->{int}->{$options{instance}}->{out_eir} = $self->{results}->{$self->{oid_eg_eir} . '.' . $options{instance}} * 8;
$self->add_result_speed(%options);
}

View File

@ -46,45 +46,48 @@ sub custom_status_calc {
return 0;
}
sub set_counters {
sub set_counters_global {
my ($self, %options) = @_;
$self->{maps_counters} = { int => {}, global => {} } if (!defined($self->{maps_counters}));
$self->{maps_counters}->{global}->{'005_total-link-up'} = { filter => 'add_global',
set => {
key_values => [ { name => 'global_link_up' }, { name => 'total_port' } ],
output_template => 'LinkStatus Up : %s', output_error_template => 'LinkStatus Up : %s',
output_use => 'global_link_up_absolute', threshold_use => 'global_link_up_absolute',
perfdatas => [
{ label => 'total_link_up', value => 'global_link_up_absolute', template => '%s',
min => 0, max => 'total_port_absolute' },
],
}
};
$self->{maps_counters}->{global}->{'006_total-link-down'} = { filter => 'add_global',
set => {
key_values => [ { name => 'global_link_down' }, { name => 'total_port' } ],
output_template => 'LinkStatus Down : %s', output_error_template => 'LinkStatus Down : %s',
output_use => 'global_link_down_absolute', threshold_use => 'global_link_down_absolute',
perfdatas => [
{ label => 'total_link_down', value => 'global_link_down_absolute', template => '%s',
min => 0, max => 'total_port_absolute' },
],
}
};
$self->{maps_counters}->{int}->{'045_in-crc'} = { filter => 'add_errors',
set => {
key_values => [ { name => 'incrc', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' },
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %s',
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
}
};
$self->SUPER::set_counters_global(%options);
$self->SUPER::set_counters(%options);
push @{$self->{maps_counters}->{global}},
{ label => 'total-link-up', filter => 'add_global', set => {
key_values => [ { name => 'global_link_up' }, { name => 'total_port' } ],
output_template => 'LinkStatus Up : %s', output_error_template => 'LinkStatus Up : %s',
output_use => 'global_link_up_absolute', threshold_use => 'global_link_up_absolute',
perfdatas => [
{ label => 'total_link_up', value => 'global_link_up_absolute', template => '%s',
min => 0, max => 'total_port_absolute' },
],
}
},
{ label => 'total-link-down', filter => 'add_global', set => {
key_values => [ { name => 'global_link_down' }, { name => 'total_port' } ],
output_template => 'LinkStatus Down : %s', output_error_template => 'LinkStatus Down : %s',
output_use => 'global_link_down_absolute', threshold_use => 'global_link_down_absolute',
perfdatas => [
{ label => 'total_link_down', value => 'global_link_down_absolute', template => '%s',
min => 0, max => 'total_port_absolute' },
],
}
},
;
}
sub set_counters_errors {
my ($self, %options) = @_;
push @{$self->{maps_counters}->{int}},
{ label => 'in-crc', filter => 'add_errors', set => {
key_values => [ { name => 'incrc', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' },
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %s',
closure_custom_perfdata => $self->can('custom_errors_perfdata'),
closure_custom_threshold_check => $self->can('custom_errors_threshold'),
}
},
;
}
sub set_key_values_status {
@ -343,36 +346,36 @@ sub add_result_global {
sub add_result_status {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{linkstatus} = defined($self->{results}->{$self->{oid_linkstatus} . '.' . $options{instance}}) ? $self->{oid_linkstatus_mapping}->{$self->{results}->{$self->{oid_linkstatus} . '.' . $options{instance}}} : undef;
$self->{interface_selected}->{$options{instance}}->{opstatus} = defined($self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}) ? $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}} : undef;
$self->{interface_selected}->{$options{instance}}->{admstatus} = defined($self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}) ? $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}} : undef;
$self->{interface_selected}->{$options{instance}}->{duplexstatus} = defined($self->{results}->{$self->{oid_duplexstatus} . '.' . $options{instance}}) ? $self->{oid_duplexstatus_mapping}->{$self->{results}->{$self->{oid_duplexstatus} . '.' . $options{instance}}} : 'n/a';
$self->{int}->{$options{instance}}->{linkstatus} = defined($self->{results}->{$self->{oid_linkstatus} . '.' . $options{instance}}) ? $self->{oid_linkstatus_mapping}->{$self->{results}->{$self->{oid_linkstatus} . '.' . $options{instance}}} : undef;
$self->{int}->{$options{instance}}->{opstatus} = defined($self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}) ? $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $options{instance}}} : undef;
$self->{int}->{$options{instance}}->{admstatus} = defined($self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}) ? $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $options{instance}}} : undef;
$self->{int}->{$options{instance}}->{duplexstatus} = defined($self->{results}->{$self->{oid_duplexstatus} . '.' . $options{instance}}) ? $self->{oid_duplexstatus_mapping}->{$self->{results}->{$self->{oid_duplexstatus} . '.' . $options{instance}}} : 'n/a';
}
sub add_result_traffic {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{mode_traffic} = 64;
$self->{interface_selected}->{$options{instance}}->{in} = $self->{results}->{$self->{oid_in64} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{out} = $self->{results}->{$self->{oid_out64} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{in} *= 8 if (defined($self->{interface_selected}->{$options{instance}}->{in}));
$self->{interface_selected}->{$options{instance}}->{out} *= 8 if (defined($self->{interface_selected}->{$options{instance}}->{out}));
$self->{interface_selected}->{$options{instance}}->{speed_in} = 0;
$self->{interface_selected}->{$options{instance}}->{speed_out} = 0;
$self->{int}->{$options{instance}}->{mode_traffic} = 64;
$self->{int}->{$options{instance}}->{in} = $self->{results}->{$self->{oid_in64} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{out} = $self->{results}->{$self->{oid_out64} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{in} *= 8 if (defined($self->{int}->{$options{instance}}->{in}));
$self->{int}->{$options{instance}}->{out} *= 8 if (defined($self->{int}->{$options{instance}}->{out}));
$self->{int}->{$options{instance}}->{speed_in} = 0;
$self->{int}->{$options{instance}}->{speed_out} = 0;
if ($self->{get_speed} == 0) {
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
}
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
} else {
my $interface_speed = 0;
$interface_speed = $self->{results}->{$self->{oid_speed64} . "." . $options{instance}} * 1000000;
$self->{interface_selected}->{$options{instance}}->{speed_in} = $interface_speed;
$self->{interface_selected}->{$options{instance}}->{speed_out} = $interface_speed;
$self->{interface_selected}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{interface_selected}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
$self->{int}->{$options{instance}}->{speed_in} = $interface_speed;
$self->{int}->{$options{instance}}->{speed_out} = $interface_speed;
$self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
$self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
}
}
@ -381,27 +384,27 @@ sub add_result_cast {
my $iucast = $self->{results}->{$self->{oid_ifHCInUcastPkts} . '.' . $options{instance}};
if (defined($iucast) && $iucast =~ /[1-9]/) {
$self->{interface_selected}->{$options{instance}}->{iucast} = $iucast;
$self->{interface_selected}->{$options{instance}}->{imcast} = defined($self->{results}->{$self->{oid_ifHCInMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCInMulticastPkts} . '.' . $options{instance}} : 0;
$self->{interface_selected}->{$options{instance}}->{ibcast} = defined($self->{results}->{$self->{oid_ifHCInBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCInBroadcastPkts} . '.' . $options{instance}} : 0;
$self->{interface_selected}->{$options{instance}}->{oucast} = $self->{results}->{$self->{oid_ifHCOutUcastPkts} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{omcast} = defined($self->{results}->{$self->{oid_ifHCOutMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCOutMulticastPkts} . '.' . $options{instance}} : 0;
$self->{interface_selected}->{$options{instance}}->{obcast} = defined($self->{results}->{$self->{oid_ifHCOutBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCOutBroadcastPkts} . '.' . $options{instance}} : 0;
$self->{interface_selected}->{$options{instance}}->{mode_cast} = 64;
$self->{int}->{$options{instance}}->{iucast} = $iucast;
$self->{int}->{$options{instance}}->{imcast} = defined($self->{results}->{$self->{oid_ifHCInMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCInMulticastPkts} . '.' . $options{instance}} : 0;
$self->{int}->{$options{instance}}->{ibcast} = defined($self->{results}->{$self->{oid_ifHCInBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCInBroadcastPkts} . '.' . $options{instance}} : 0;
$self->{int}->{$options{instance}}->{oucast} = $self->{results}->{$self->{oid_ifHCOutUcastPkts} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{omcast} = defined($self->{results}->{$self->{oid_ifHCOutMulticastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCOutMulticastPkts} . '.' . $options{instance}} : 0;
$self->{int}->{$options{instance}}->{obcast} = defined($self->{results}->{$self->{oid_ifHCOutBroadcastPkts} . '.' . $options{instance}}) ? $self->{results}->{$self->{oid_ifHCOutBroadcastPkts} . '.' . $options{instance}} : 0;
$self->{int}->{$options{instance}}->{mode_cast} = 64;
}
foreach (('iucast', 'imcast', 'ibcast', 'oucast', 'omcast', 'obcast')) {
$self->{interface_selected}->{$options{instance}}->{$_} = 0 if (!defined($self->{interface_selected}->{$options{instance}}->{$_}));
$self->{int}->{$options{instance}}->{$_} = 0 if (!defined($self->{int}->{$options{instance}}->{$_}));
}
$self->{interface_selected}->{$options{instance}}->{total_in_packets} = $self->{interface_selected}->{$options{instance}}->{iucast} + $self->{interface_selected}->{$options{instance}}->{imcast} + $self->{interface_selected}->{$options{instance}}->{ibcast};
$self->{interface_selected}->{$options{instance}}->{total_out_packets} = $self->{interface_selected}->{$options{instance}}->{oucast} + $self->{interface_selected}->{$options{instance}}->{omcast} + $self->{interface_selected}->{$options{instance}}->{obcast};
$self->{int}->{$options{instance}}->{total_in_packets} = $self->{int}->{$options{instance}}->{iucast} + $self->{int}->{$options{instance}}->{imcast} + $self->{int}->{$options{instance}}->{ibcast};
$self->{int}->{$options{instance}}->{total_out_packets} = $self->{int}->{$options{instance}}->{oucast} + $self->{int}->{$options{instance}}->{omcast} + $self->{int}->{$options{instance}}->{obcast};
}
sub add_result_errors {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{incrc} = $self->{results}->{$self->{oid_ifInCrc} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{incrc} = $self->{results}->{$self->{oid_ifInCrc} . '.' . $options{instance}};
}
sub add_result_speed {
@ -410,14 +413,14 @@ sub add_result_speed {
my $interface_speed = 0;
$interface_speed = $self->{results}->{$self->{oid_speed64} . "." . $options{instance}} * 1000000;
$self->{interface_selected}->{$options{instance}}->{speed} = $interface_speed;
$self->{int}->{$options{instance}}->{speed} = $interface_speed;
}
sub add_result_volume {
my ($self, %options) = @_;
$self->{interface_selected}->{$options{instance}}->{in_volume} = $self->{results}->{$self->{oid_in64} . '.' . $options{instance}};
$self->{interface_selected}->{$options{instance}}->{out_volume} = $self->{results}->{$self->{oid_out64} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{in_volume} = $self->{results}->{$self->{oid_in64} . '.' . $options{instance}};
$self->{int}->{$options{instance}}->{out_volume} = $self->{results}->{$self->{oid_out64} . '.' . $options{instance}};
}
1;

File diff suppressed because it is too large Load Diff