From 559576356bd18763567396e27b355427285fedcf Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 28 Nov 2016 14:08:25 +0100 Subject: [PATCH] + Add QoS Cisco mode --- .../cisco/standard/snmp/mode/qosusage.pm | 248 ++++++++++++++---- network/cisco/standard/snmp/plugin.pm | 1 + 2 files changed, 201 insertions(+), 48 deletions(-) diff --git a/centreon/common/cisco/standard/snmp/mode/qosusage.pm b/centreon/common/cisco/standard/snmp/mode/qosusage.pm index a32a90ed9..545c9a95d 100644 --- a/centreon/common/cisco/standard/snmp/mode/qosusage.pm +++ b/centreon/common/cisco/standard/snmp/mode/qosusage.pm @@ -26,48 +26,156 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); +my $instance_mode; + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'ps', type => 1, cb_prefix_output => 'prefix_ps_output', message_multiple => 'All power sources are ok' }, + { 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' }, ]; - $self->{maps_counters}->{ps} = [ - { label => 'power', set => { - key_values => [ { name => 'PwrTotal' }, { name => 'display' } ], - output_template => 'Total input power : %s W', output_error_template => "total input power : %s", + $self->{maps_counters}->{interface_classmap} = [ + { label => 'int-cmap-traffic', set => { + key_values => [ { name => 'display' }, { name => 'traffic_usage', diff => 1 }, { name => 'total' } ], + per_second => 1, + 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'), + } + }, + { label => 'int-cmap-drop', set => { + key_values => [ { name => 'drop_usage', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Drop : %s %s/s', perfdatas => [ - { label => 'power', value => 'PwrTotal_absolute', template => '%s', - unit => 'W', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + { label => 'icmap_drop', value => 'drop_usage_per_second', template => '%d', + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, - { label => 'energy', set => { - key_values => [ { name => 'EnergyAccum', diff => 1 }, { name => 'display' } ], - output_template => 'Total energy : %.3f kWh', output_error_template => "Total energy : %s", + ]; + $self->{maps_counters}->{classmap} = [ + { label => 'cmap-traffic', set => { + key_values => [ { name => 'traffic_usage', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic : %s %s/s', perfdatas => [ - { label => 'energy', value => 'EnergyAccum_absolute', template => '%.3f', - unit => 'kWh', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + { label => 'cmap_traffic', value => 'traffic_usage_per_second', template => '%d', + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, - { label => 'current-neutral', set => { - key_values => [ { name => 'EcNeutral' }, { name => 'display' } ], - output_template => 'Current neutral : %s Amp AC RMS', output_error_template => "Current neutral : %s", + { label => 'cmap-drop', set => { + key_values => [ { name => 'drop_usage', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Drop : %s %s/s', perfdatas => [ - { label => 'current_neutral', value => 'EcNeutral_absolute', template => '%s', - unit => 'AmpAcRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + { label => 'cmap_drop', value => 'drop_usage_per_second', template => '%d', + 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 } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Total Traffic : %s %s/s', + perfdatas => [ + { label => 'total_traffic', value => 'traffic_usage_per_second', template => '%d', + unit => 'b/s', min => 0 }, + ], + } + }, + { label => 'total-drop', set => { + key_values => [ { name => 'drop_usage', diff => 1 } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Total Drop : %s %s/s', + perfdatas => [ + { label => 'total_drop', value => 'drop_usage_per_second', template => '%d', + unit => 'b/s', min => 0 }, ], } }, ]; } -sub prefix_ps_output { +sub custom_usage_perfdata { my ($self, %options) = @_; - return "Power source '" . $options{instance_value}->{display} . "' "; + my $extra_label = ''; + if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { + $extra_label .= '_' . $self->{result_values}->{display}; + } + + my ($warning, $critical); + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{total})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + } + + $self->{output}->perfdata_add(label => 'icmap_traffic' . $extra_label, unit => 'b/s', + value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_traffic_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{total})) { + $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' } ]); + } elsif ($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' } ]); + } + return $exit; +} + +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; +} + +sub custom_traffic_calc { + my ($self, %options) = @_; + + $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]/) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_total'}; + } + + return 0; +} + +sub prefix_intcmap_output { + my ($self, %options) = @_; + + return "Interface classmap '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_cmap_output { + my ($self, %options) = @_; + + return "Classmap '" . $options{instance_value}->{display} . "' "; } sub new { @@ -81,6 +189,7 @@ sub new { "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; @@ -96,6 +205,7 @@ sub check_options { 'ifname' => '.1.3.6.1.2.1.31.1.1.1.1', }; $self->check_oids_label(); + $instance_mode = $self; } sub check_oids_label { @@ -113,15 +223,19 @@ 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' }, - cbQosCMDropPktOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.12' }, - cbQosCMDropPkt => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.13' }, - cbQosCMDropPkt64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.14' }, + 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' }, +}; +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 }; my $oid_cbQosIfIndex = '.1.3.6.1.4.1.9.9.166.1.1.1.1.4'; @@ -133,7 +247,7 @@ my $oid_cbQosCMStatsEntry = '.1.3.6.1.4.1.9.9.166.1.15.1.1'; # Can be linked to a classmap also my $oid_cbQosPolicyMapName = '.1.3.6.1.4.1.9.9.166.1.6.1.1.1'; # Shaping : Linked to a classmap -my $oid_cbQosTSCfgRate = '.1.3.6.1.4.1.9.9.166.1.13.1.1.1'; +my $oid_cbQosTSCfgEntry = '.1.3.6.1.4.1.9.9.166.1.13.1.1'; # Linked to a classmap my $oid_cbQosQueueingCfgBandwidth = '.1.3.6.1.4.1.9.9.166.1.9.1.1.1'; my $oid_cbQosQueueingCfgBandwidthUnits = '.1.3.6.1.4.1.9.9.166.1.9.1.1.2'; @@ -141,9 +255,12 @@ my $oid_cbQosQueueingCfgBandwidthUnits = '.1.3.6.1.4.1.9.9.166.1.9.1.1.2'; sub build_qos_information { my ($self, %options) = @_; - $self->{complete_name} = $options{class_name}; + my $qos_data = { complete_name => $options{class_name} }; # Need to try and find the queueing (it's a child) - # TODO + $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}}; @@ -156,17 +273,21 @@ sub build_qos_information { $tmp_name = $self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index}; } - # Need to find a shaping (first) - # TODO + $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}})); - $self->{complete_name} = $tmp_name . ':' . $self->{complete_name}; + $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}} }, @@ -178,6 +299,7 @@ sub manage_selection { { oid => $oid_cbQosQueueingCfgBandwidthUnits }, { oid => $oid_cbQosCMStatsEntry }, { oid => $oid_cbQosParentObjectsIndex }, + { oid => $oid_cbQosTSCfgEntry }, ]; push @$request_oids, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} } if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}); @@ -190,11 +312,16 @@ sub manage_selection { $classmap_name{$1} = $self->{results}->{$oid_cbQosCMName}->{$oid_cbQosCMName . '.' . $self->{results}->{$oid_cbQosConfigIndex}->{$_}}; } } - #$self->{parent_object} = {}; - #foreach (keys %{$self->{results}->{$oid_cbQosParentObjectsIndex}}) { - # /(\d+)\.(\d+)$/; - # $self->{parent_object}->{$1 . '.' . $self->{results}->{$oid_cbQosParentObjectsIndex}->{$_}} = $2; - #} + my ($link_queueing, $link_shaping) = ({}, {}); + foreach (keys %{$self->{results}->{$oid_cbQosParentObjectsIndex}}) { + /(\d+)\.(\d+)$/; + my $config_index = $self->{results}->{$oid_cbQosConfigIndex}->{$oid_cbQosConfigIndex . '.' . $1 . '.' . $2}; + if (defined($self->{results}->{$oid_cbQosQueueingCfgBandwidth}->{$oid_cbQosQueueingCfgBandwidth . '.' . $config_index})) { + $link_queueing->{$1 . '.' . $self->{results}->{$oid_cbQosParentObjectsIndex}->{$_}} = $config_index; + } elsif (defined($self->{results}->{$oid_cbQosTSCfgEntry}->{$mapping2->{cbQosTSCfgRate}->{oid} . '.' . $config_index})) { + $link_shaping->{$1 . '.' . $self->{results}->{$oid_cbQosParentObjectsIndex}->{$_}} = $config_index; + } + } foreach (keys %{$self->{results}->{$oid_cbQosCMStatsEntry}}) { next if (!/$mapping->{cbQosCMPrePolicyByte}->{oid}\.(\d+)\.(\d+)/); @@ -214,10 +341,11 @@ sub manage_selection { next; } - $self->build_qos_information(class_name => $class_name, policy_index => $policy_index, object_index => $qos_object_index); + 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 . ':' . $self->{complete_name}; + 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}/) { @@ -226,7 +354,26 @@ sub manage_selection { } my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cbQosCMStatsEntry}, instance => $policy_index . '.' . $qos_object_index); - print "======$name=======\n"; + my $traffic_usage = (defined($result->{cbQosCMPostPolicyByte64}) && $result->{cbQosCMPostPolicyByte64} =~ /[1-9]/) ? + $result->{cbQosCMPostPolicyByte64} : (($result->{cbQosCMPostPolicyByteOverflow} << 32) + $result->{cbQosCMPostPolicyByte}); + my $drop_usage = (defined($result->{cbQosCMDropByte64}) && $result->{cbQosCMDropByte64} =~ /[1-9]/) ? + $result->{cbQosCMDropByte64} : (($result->{cbQosCMDropByteOverflow} << 32) + $result->{cbQosCMDropByte}); + my $total = 'unknown'; + if (defined($qos_data->{shaping})) { + 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 + }; + $self->{classmap}->{$class_name} = { display => $class_name, drop_usage => 0, traffic_usage => 0} if (!defined($self->{classmap}->{$class_name})); + $self->{classmap}->{$class_name}->{traffic_usage} += $traffic_usage * 8; + $self->{classmap}->{$class_name}->{drop_usage} += $drop_usage * 8; + + $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} . '_' . @@ -252,24 +399,29 @@ Check QoS. =item B<--filter-source> Filter interface name and class-map (can be a regexp). -Example of a source (interfacename:classmap): FastEthernet1:Visioconference +Example of a source (interfacename:servicepolicy:classmap:...): FastEthernet1:Visioconference =item B<--filter-counters> Only display some counters (regexp can be used). -Example: --filter-counters='^(power|energy)$' +Example: --filter-counters='^(total-traffic)$' =item B<--warning-*> Threshold warning. -Can be: 'power', 'energy', 'current-neutral', -'line-load', 'line-current'. +Can be: 'int-cmap-traffic', 'int-cmap-drop', +'cmap-traffic', 'cmap-drop', 'total-traffic', 'total-drop'. =item B<--critical-*> Threshold critical. -Can be: 'power', 'energy', 'current-neutral', -'line-load', 'line-current'. +Can be: 'int-cmap-traffic', 'int-cmap-drop', +'cmap-traffic', 'cmap-drop', 'total-traffic', 'total-drop'. + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Only for --warning-int-traffic and --critical-int-traffic options. =item B<--oid-filter> diff --git a/network/cisco/standard/snmp/plugin.pm b/network/cisco/standard/snmp/plugin.pm index 558abceaa..a4d1950ae 100644 --- a/network/cisco/standard/snmp/plugin.pm +++ b/network/cisco/standard/snmp/plugin.pm @@ -39,6 +39,7 @@ sub new { 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', 'memory-flash' => 'centreon::common::cisco::standard::snmp::mode::memoryflash', + 'qos-usage' => 'centreon::common::cisco::standard::snmp::mode::qosusage', 'spanning-tree' => 'snmp_standard::mode::spanningtree', 'stack' => 'centreon::common::cisco::standard::snmp::mode::stack', );