use bigint for qos usage

This commit is contained in:
garnier-quentin 2020-03-31 10:38:37 +02:00
parent 90cb098967
commit e325247da4
1 changed files with 70 additions and 63 deletions

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub set_counters {
my ($self, %options) = @_;
@ -32,7 +33,7 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'total', type => 0 },
{ name => 'interface_classmap', type => 1, cb_prefix_output => 'prefix_intcmap_output', message_multiple => 'All interface classmaps are ok' },
{ name => 'classmap', type => 1, cb_prefix_output => 'prefix_cmap_output', message_multiple => 'All classmaps are ok' },
{ name => 'classmap', type => 1, cb_prefix_output => 'prefix_cmap_output', message_multiple => 'All classmaps are ok' }
];
$self->{maps_counters}->{interface_classmap} = [
@ -42,7 +43,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_traffic_calc'),
closure_custom_output => $self->can('custom_traffic_output'),
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold')
}
},
{ label => 'int-cmap-drop', set => {
@ -51,10 +52,10 @@ sub set_counters {
output_template => 'Drop : %s %s/s',
perfdatas => [
{ label => 'icmap_drop', value => 'drop_usage_per_second', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
}
];
$self->{maps_counters}->{classmap} = [
{ label => 'cmap-traffic', set => {
@ -63,8 +64,8 @@ sub set_counters {
output_template => 'Traffic : %s %s/s',
perfdatas => [
{ label => 'cmap_traffic', value => 'traffic_usage_per_second', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'cmap-drop', set => {
@ -73,11 +74,12 @@ sub set_counters {
output_template => 'Drop : %s %s/s',
perfdatas => [
{ label => 'cmap_drop', value => 'drop_usage_per_second', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
}
];
$self->{maps_counters}->{total} = [
{ label => 'total-traffic', set => {
key_values => [ { name => 'traffic_usage', diff => 1 } ],
@ -85,8 +87,8 @@ sub set_counters {
output_template => 'Total Traffic : %s %s/s',
perfdatas => [
{ label => 'total_traffic', value => 'traffic_usage_per_second', template => '%d',
unit => 'b/s', min => 0 },
],
unit => 'b/s', min => 0 }
]
}
},
{ label => 'total-drop', set => {
@ -95,16 +97,16 @@ sub set_counters {
output_template => 'Total Drop : %s %s/s',
perfdatas => [
{ label => 'total_drop', value => 'drop_usage_per_second', template => '%d',
unit => 'b/s', min => 0 },
],
unit => 'b/s', min => 0 }
]
}
},
}
];
}
sub custom_traffic_perfdata {
my ($self, %options) = @_;
my ($warning, $critical);
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' &&
(defined($self->{result_values}->{total}) && $self->{result_values}->{total} =~ /[0-9]/)) {
@ -114,7 +116,7 @@ sub custom_traffic_perfdata {
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel});
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel});
}
$self->{output}->perfdata_add(
label => 'icmap_traffic', unit => 'b/s',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
@ -127,7 +129,7 @@ sub custom_traffic_perfdata {
sub custom_traffic_threshold {
my ($self, %options) = @_;
my $exit = 'ok';
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' &&
(defined($self->{result_values}->{total}) && $self->{result_values}->{total} =~ /[0-9]/)) {
@ -142,10 +144,11 @@ sub custom_traffic_output {
my ($self, %options) = @_;
my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1);
my $msg = sprintf("Traffic : %s/s (%s)",
$traffic_value . $traffic_unit,
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-');
return $msg;
return sprintf(
'Traffic : %s/s (%s)',
$traffic_value . $traffic_unit,
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'
);
}
sub custom_traffic_calc {
@ -154,7 +157,7 @@ sub custom_traffic_calc {
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{traffic_usage} = $options{new_datas}->{$self->{instance} . '_traffic_usage'};
my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_traffic_usage'} - $options{old_datas}->{$self->{instance} . '_traffic_usage'});
$self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time};
if ($options{new_datas}->{$self->{instance} . '_total'} =~ /[1-9]/) {
@ -182,10 +185,10 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-source:s" => { name => 'filter_source' },
"oid-filter:s" => { name => 'oid_filter', default => 'ifname' },
"oid-display:s" => { name => 'oid_display', default => 'ifname' },
"units-traffic:s" => { name => 'units_traffic', default => '%' },
'filter-source:s' => { name => 'filter_source' },
'oid-filter:s' => { name => 'oid_filter', default => 'ifname' },
'oid-display:s' => { name => 'oid_display', default => 'ifname' },
'units-traffic:s' => { name => 'units_traffic', default => '%' }
});
return $self;
@ -205,7 +208,7 @@ sub check_options {
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}->{$_}})) {
@ -218,23 +221,20 @@ sub check_oids_label {
}
my $mapping = {
cbQosCMPrePolicyByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.4' },
cbQosCMPrePolicyByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.5' },
cbQosCMPrePolicyByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.6' },
cbQosCMPostPolicyByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.8' },
cbQosCMPostPolicyByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.9' },
cbQosCMPostPolicyByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.10' },
cbQosCMDropByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.15' },
cbQosCMDropByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.16' },
cbQosCMDropByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.17' },
cbQosCMDropByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.17' }
};
my $mapping2 = {
cbQosTSCfgRate => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.1' }, # bps
cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' }, # bps
cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' } # bps
};
my $mapping3 = {
cbQosQueueingCfgBandwidth => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.1' },
cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' },
cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' }
};
my $oid_cbQosIfIndex = '.1.3.6.1.4.1.9.9.166.1.1.1.1.4';
@ -252,17 +252,17 @@ my $oid_cbQosQueueingCfgEntry = '.1.3.6.1.4.1.9.9.166.1.9.1.1';
sub build_qos_information {
my ($self, %options) = @_;
my $qos_data = { complete_name => $options{class_name} };
# Need to try and find the queueing (it's a child)
$qos_data->{queueing} = $options{link_queueing}->{$options{policy_index} . '.' . $options{object_index}}
if (defined($options{link_queueing}->{$options{policy_index} . '.' . $options{object_index}}));
$qos_data->{shaping} = $options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}
if (!defined($qos_data->{shaping}) && defined($options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}));
while (($options{object_index} = $self->{results}->{$oid_cbQosParentObjectsIndex}->{$oid_cbQosParentObjectsIndex . '.' . $options{policy_index} . '.' . $options{object_index}}) != 0) {
my $config_index = $self->{results}->{$oid_cbQosConfigIndex}->{$oid_cbQosConfigIndex . '.' . $options{policy_index} . '.' . $options{object_index}};
my $tmp_name = '';
# try to find policy_map or class_map
if (defined($self->{results}->{$oid_cbQosCMName}->{$oid_cbQosCMName . '.' . $config_index})) {
@ -270,23 +270,23 @@ sub build_qos_information {
} elsif (defined($self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index})) {
$tmp_name = $self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index};
}
$qos_data->{shaping} = $options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}
if (!defined($qos_data->{shaping}) && defined($options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}));
$qos_data->{complete_name} = $tmp_name . ':' . $qos_data->{complete_name};
}
return $qos_data;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{interface_classmap} = {};
$self->{classmap} = {};
$self->{total} = { drop_usage => 0, total_usage => 0 };
my $request_oids = [
{ oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}} },
{ oid => $oid_cbQosPolicyMapName },
@ -294,9 +294,9 @@ sub manage_selection {
{ oid => $oid_cbQosConfigIndex },
{ oid => $oid_cbQosCMName },
{ oid => $oid_cbQosQueueingCfgEntry, end => $mapping3->{cbQosQueueingCfgBandwidthUnits}->{oid} },
{ oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPrePolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} },
{ oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPostPolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} },
{ oid => $oid_cbQosParentObjectsIndex },
{ oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} },
{ oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} }
];
push @$request_oids, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} }
if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display});
@ -321,8 +321,8 @@ sub manage_selection {
}
foreach (keys %{$self->{results}->{$oid_cbQosCMStatsEntry}}) {
next if (!/$mapping->{cbQosCMPrePolicyByte}->{oid}\.(\d+)\.(\d+)/);
next if (!/$mapping->{cbQosCMPostPolicyByteOverflow}->{oid}\.(\d+)\.(\d+)/);
my ($policy_index, $qos_object_index) = ($1, $2);
my $class_name = $classmap_name{$policy_index . '.' . $qos_object_index};
@ -338,24 +338,29 @@ sub manage_selection {
next;
}
my $qos_data = $self->build_qos_information(class_name => $class_name, policy_index => $policy_index, object_index => $qos_object_index,
link_queueing => $link_queueing, link_shaping => $link_shaping);
my $qos_data = $self->build_qos_information(
class_name => $class_name,
policy_index => $policy_index,
object_index => $qos_object_index,
link_queueing => $link_queueing,
link_shaping => $link_shaping
);
my $interface_filter = $self->{results}->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}->{$self->{oids_label}->{$self->{option_results}->{oid_filter}} . '.' . $if_index};
my $name = $interface_filter . ':' . $qos_data->{complete_name};
if (defined($self->{option_results}->{filter_source}) && $self->{option_results}->{filter_source} ne '' &&
$name !~ /$self->{option_results}->{filter_source}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter source.", debug => 1);
next;
}
# Same hash key but only for disco context
if (defined($options{disco})) {
$self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = $name;
next;
}
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cbQosCMStatsEntry}, instance => $policy_index . '.' . $qos_object_index);
my $traffic_usage = (defined($result->{cbQosCMPostPolicyByte64}) && $result->{cbQosCMPostPolicyByte64} =~ /[1-9]/) ?
$result->{cbQosCMPostPolicyByte64} : (($result->{cbQosCMPostPolicyByteOverflow} << 32) + $result->{cbQosCMPostPolicyByte});
@ -366,40 +371,42 @@ sub manage_selection {
my $result_shaping = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_cbQosTSCfgEntry}, instance => $qos_data->{shaping});
$total = defined($result_shaping->{cbQosTSCfgRate64}) ? $result_shaping->{cbQosTSCfgRate64} : $result_shaping->{cbQosTSCfgRate};
}
$self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = {
display => $name,
traffic_usage => $traffic_usage * 8, drop_usage => $drop_usage * 8, total => $total
traffic_usage => $traffic_usage * 8,
drop_usage => $drop_usage * 8,
total => $total
};
my @tabname = split /:/, $name;
if (defined($tabname[3])){
$class_name = $tabname[3].'-'.$class_name;
$class_name = $tabname[3] . '-' . $class_name;
}
$self->{classmap}->{$name} = { display => $class_name, drop_usage => 0, traffic_usage => 0} if (!defined($self->{classmap}->{$name}));
$self->{classmap}->{$name}->{traffic_usage} += $traffic_usage * 8;
$self->{classmap}->{$name}->{drop_usage} += $drop_usage * 8;
if (!defined($tabname[3])){
$self->{total}->{traffic_usage} += $traffic_usage * 8;
$self->{total}->{drop_usage} += $drop_usage * 8;
}
}
$self->{cache_name} = "cisco_qos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
$self->{cache_name} = 'cisco_qos_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_source}) ? md5_hex($self->{option_results}->{filter_source}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
if (scalar(keys %{$self->{interface_classmap}}) <= 0 && !defined($options{disco})) {
$self->{output}->add_option_msg(short_msg => "Cannot found classmap.");
$self->{output}->add_option_msg(short_msg => 'Cannot found classmap.');
$self->{output}->option_exit();
}
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}