From cf8564f1b529af64c0cdb057e7751e0fae7a3437 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 1 Jun 2020 11:40:08 +0200 Subject: [PATCH] enhance network versa --- network/versa/snmp/mode/devices.pm | 179 +++++++++++ network/versa/snmp/mode/qospolicy.pm | 369 ++++++++++++++++++++++ network/versa/snmp/mode/qospolicyusage.pm | 321 ------------------- network/versa/snmp/mode/system.pm | 161 ---------- network/versa/snmp/plugin.pm | 10 +- 5 files changed, 554 insertions(+), 486 deletions(-) create mode 100644 network/versa/snmp/mode/devices.pm create mode 100644 network/versa/snmp/mode/qospolicy.pm delete mode 100644 network/versa/snmp/mode/qospolicyusage.pm delete mode 100644 network/versa/snmp/mode/system.pm diff --git a/network/versa/snmp/mode/devices.pm b/network/versa/snmp/mode/devices.pm new file mode 100644 index 000000000..3e7fc25e5 --- /dev/null +++ b/network/versa/snmp/mode/devices.pm @@ -0,0 +1,179 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::versa::snmp::mode::devices; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_sessions_active_output { + my ($self, %options) = @_; + + return sprintf( + 'sessions active: %s (%s)', + $self->{result_values}->{sessions_active}, + $self->{result_values}->{sessions_max} + ); +} + +sub custom_sessions_failed_output { + my ($self, %options) = @_; + + return sprintf( + 'sessions failed: %s (%s)', + $self->{result_values}->{sessions_failed}, + $self->{result_values}->{sessions_max} + ); +} + +sub prefix_device_output { + my ($self, %options) = @_; + + return "Device '" . $options{instance_value}->{vsn_id} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'devices', type => 1, cb_prefix_output => 'prefix_device_output', message_multiple => 'All devices are ok' } + ]; + + $self->{maps_counters}->{devices} = [ + { label => 'cpu-utilization', nlabel => 'device.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_load' } ], + output_template => 'cpu load: %.2f %%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] + } + }, + { label => 'memory-usage', nlabel => 'device.memory.usage.percentage', set => { + key_values => [ { name => 'memory' } ], + output_template => 'memory used: %.2f%%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] + } + }, + { label => 'sessions-active', nlabel => 'device.sessions.active.count', set => { + key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' } ], + closure_custom_output => $self->can('custom_sessions_active_output'), + perfdatas => [ + { template => '%s', min => 0, max => 'sessions_max', label_extra_instance => 1 } + ] + } + }, + { label => 'sessions-active-prct', nlabel => 'device.sessions.active.percentage', display_ok => 0, set => { + key_values => [ { name => 'sessions_active_prct' } ], + output_template => 'sessions active: %.2f %%', + perfdatas => [ + { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => 'sessions-failed', nlabel => 'device.sessions.failed.count', set => { + key_values => [ { name => 'sessions_failed' }, { name => 'sessions_max' } ], + closure_custom_output => $self->can('custom_sessions_failed_output'), + perfdatas => [ + { template => '%s', min => 0, max => 'sessions_max', label_extra_instance => 1 } + ] + } + }, + { label => 'sessions-failed-prct', nlabel => 'device.sessions.active.percentage', display_ok => 0, set => { + key_values => [ { name => 'sessions_failed_prct' } ], + output_template => 'sessions failed: %.2f %%', + perfdatas => [ + { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_deviceTableEntry = '.1.3.6.1.4.1.42359.2.2.1.1.1.1'; + + my $mapping_device = { + vsn_id => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.1' }, # deviceVSNId + cpu_load => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.2' }, # deviceCPULoad + memory => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.3' }, # deviceMemoryLoad + sessions_active => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.5' }, # deviceActiveSessions + sessions_failed => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.6' }, # deviceFailedSessions + sessions_max => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.7' } # deviceMaxSessions + }; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_deviceTableEntry, + end => $mapping_device->{sessions_max}->{oid}, + nothing_quit => 1 + ); + + $self->{devices} = {}; + foreach (keys %$snmp_result) { + next if (! /^$mapping_device->{cpu_load}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance); + + $self->{devices}->{ $result->{vsn_id} } = $result; + $self->{devices}->{ $result->{vsn_id} }->{sessions_active_prct} = $result->{sessions_active} * 100/ $result->{sessions_max}; + $self->{devices}->{ $result->{vsn_id} }->{sessions_failed_prct} = $result->{sessions_failed} * 100/ $result->{sessions_max}; + } +} + +1; + +__END__ + +=head1 MODE + +Check device system statistics (cpu, memory, sessions). + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='cpu_load' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu', 'memory', 'active-sessions', 'failed-sessions', 'sessions-used-prct', 'sessions-free-prct'. + +=back + +=cut diff --git a/network/versa/snmp/mode/qospolicy.pm b/network/versa/snmp/mode/qospolicy.pm new file mode 100644 index 000000000..1b9619413 --- /dev/null +++ b/network/versa/snmp/mode/qospolicy.pm @@ -0,0 +1,369 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::versa::snmp::mode::qospolicy; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub custom_bytespersecond_perfdata { + my ($self) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'B/s', + instances => [ + $self->{result_values}->{org_name}, + $self->{result_values}->{policy_name}, + $self->{result_values}->{rule_name} + ], + value => sprintf('%.2f', $self->{result_values}->{ $self->{key_values}->[0]->{name} }), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); +} + +sub custom_count_perfdata { + my ($self) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + instances => [ + $self->{result_values}->{org_name}, + $self->{result_values}->{policy_name}, + $self->{result_values}->{rule_name} + ], + value => sprintf('%s', $self->{result_values}->{ $self->{key_values}->[0]->{name} }), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'qospolicy', type => 1, cb_prefix_output => 'prefix_qospolicy_output', message_multiple => 'All QoS policies are ok' }, + { name => 'appqospolicy', type => 1, cb_prefix_output => 'prefix_appqospolicy_output', message_multiple => 'All applications QoS policies are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{qospolicy} = [ + { label => 'qos-policy-hit', nlabel => 'qos.policy.hit.count', set => { + key_values => [ + { name => 'hit_count', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'hits: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'qos-policy-sessions-deny', nlabel => 'qos.policy.sessions.deny.count', set => { + key_values => [ + { name => 'sessions_deny', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'sessions deny: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'qos-policy-packets-dropped', nlabel => 'qos.policy.packets.dropped.count', set => { + key_values => [ + { name => 'drop_pkts', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'packets dropped: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'qos-policy-traffic-dropped', nlabel => 'appqos.policy.traffic.dropped.bytespersecond', set => { + key_values => [ + { name => 'drop_bytes', per_second => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'traffic dropped: %.2f %s/s', + output_change_bytes => 2, + closure_custom_perfdata => $self->can('custom_bytespersecond_perfdata') + } + }, + { label => 'qos-policy-packets-forwarded', nlabel => 'qos.policy.packets.forwarded.count', display => 0, set => { + key_values => [ + { name => 'forward_pkts', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'packets forwarded: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'qos-policy-traffic-forwarded', nlabel => 'qos.policy.traffic.forwarded.bytespersecond', set => { + key_values => [ + { name => 'forward_bytes', per_second => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'traffic forwarded: %.2f %s/s', + output_change_bytes => 2, + closure_custom_perfdata => $self->can('custom_bytespersecond_perfdata') + } + } + ]; + + $self->{maps_counters}->{appqospolicy} = [ + { label => 'appqos-policy-hit', nlabel => 'appqos.policy.hit.count', set => { + key_values => [ + { name => 'hit_count', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'hits: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'appqos-policy-packets-dropped', nlabel => 'appqos.policy.packets.dropped.count', display_ok => 0, set => { + key_values => [ + { name => 'drop_pkts', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'packets dropped: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'appqos-policy-traffic-dropped', nlabel => 'appqos.policy.traffic.dropped.bytespersecond', set => { + key_values => [ + { name => 'drop_bytes', per_second => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'traffic dropped: %.2f %s/s', + output_change_bytes => 2, + closure_custom_perfdata => $self->can('custom_bytespersecond_perfdata') + } + }, + { label => 'appqos-policy-packets-forwarded', nlabel => 'appqos.policy.packets.forwarded.count', display_ok => 0, set => { + key_values => [ + { name => 'forward_pkts', diff => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'packets forwarded: %s', + closure_custom_perfdata => $self->can('custom_count_perfdata') + } + }, + { label => 'appqos-policy-traffic-forwarded', nlabel => 'appqos.policy.traffic.forwarded.bytespersecond', set => { + key_values => [ + { name => 'forward_bytes', per_second => 1 }, { name => 'org_name' }, + { name => 'policy_name' }, { name => 'rule_name' } + ], + output_template => 'traffic forwarded: %.2f %s/s', + output_change_bytes => 2, + closure_custom_perfdata => $self->can('custom_bytespersecond_perfdata') + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-org:s' => { name => 'filter_org' }, + 'filter-rule:s' => { name => 'filter_rule' }, + 'filter-policy:s' => { name => 'filter_policy' } + }); + + return $self; +} + +sub prefix_qospolicy_output { + my ($self, %options) = @_; + + return sprintf( + "QoS policy '%s' [org: %s] [policy: %s] ", + $options{instance_value}->{rule_name}, + $options{instance_value}->{org_name}, + $options{instance_value}->{policy_name} + ); +} + +sub prefix_appqospolicy_output { + my ($self, %options) = @_; + + return sprintf( + "Application QoS policy '%s' [org: %s] [policy: %s] ", + $options{instance_value}->{rule_name}, + $options{instance_value}->{org_name}, + $options{instance_value}->{policy_name} + ); +} + +my $mapping_qos_policy = { + org_name => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.5' }, # qosPolicyOrgName + policy_name => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.6' }, # qosPolicyName + rule_name => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.7' }, # qosPolicyRuleName + hit_count => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.8' }, # qosPolicyHitCount + drop_pkts => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.9' }, # qosPolicyDropPktCount + drop_bytes => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.10' }, # qosPolicyDropByteCount + forward_pkts => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.11' }, # qosPolicyForwardPktCount + forward_bytes => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.12' }, # qosPolicyForwardByteCount + sessions_deny => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.13' } # qosPolicySessionDenyCount +}; + +my $mapping_app_qos_policy = { + org_name => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.5' }, # appQosPolicyOrgName + policy_name => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.6' }, # appQosPolicyName + rule_name => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.7' }, # appQosPolicyRuleName + hit_count => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.8' }, # appQosPolicyHitCount + drop_pkts => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.9' }, # appQosPolicyDropPktCount + drop_bytes => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.10' }, # appQosPolicyDropByteCount + forward_pkts => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.11' }, # appQosPolicyForwardPktCount + forward_bytes => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.12' } # appQosPolicyForwardByteCount +}; + +my $oid_qosPolicyEntry = '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1'; +my $oid_appQosPolicyEntry = '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { + oid => $oid_qosPolicyEntry, + start => $mapping_qos_policy->{org_name}->{oid}, + end => $mapping_qos_policy->{sessions_deny}->{oid} + }, + { + oid => $oid_appQosPolicyEntry, + start => $mapping_app_qos_policy->{org_name}->{oid}, + end => $mapping_app_qos_policy->{forward_bytes}->{oid} + } + ], + nothing_quit => 1 + ); + + $self->{qospolicy} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_qosPolicyEntry}}) { + next if ($oid !~ /^$mapping_qos_policy->{org_name}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping_qos_policy, results => $snmp_result->{$oid_qosPolicyEntry}, instance => $instance); + + if (defined($self->{option_results}->{filter_org}) && $self->{option_results}->{filter_org} ne '' && + $result->{org_name} !~ /$self->{option_results}->{filter_org}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{org_name} . "': no matching 'org' filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_policy}) && $self->{option_results}->{filter_policy} ne '' && + $result->{policy_name} !~ /$self->{option_results}->{filter_policy}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{policy_name} . "': no matching filter 'policy' .", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_rule}) && $self->{option_results}->{filter_rule} ne '' && + $result->{rule_name} !~ /$self->{option_results}->{filter_rule}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{rule_name} . "': no matching filter. 'rule' ", debug => 1); + next; + } + + $self->{qospolicy}->{$instance} = $result; + } + + $self->{appqospolicy} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_appQosPolicyEntry}}) { + next if ($oid !~ /^$mapping_app_qos_policy->{org_name}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping_app_qos_policy, results => $snmp_result->{$oid_appQosPolicyEntry}, instance => $instance); + + if (defined($self->{option_results}->{filter_org}) && $self->{option_results}->{filter_org} ne '' && + $result->{org_name} !~ /$self->{option_results}->{filter_org}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{org_name} . "': no matching 'org' filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_policy}) && $self->{option_results}->{filter_policy} ne '' && + $result->{policy_name} !~ /$self->{option_results}->{filter_policy}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{policy_name} . "': no matching filter 'policy' .", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_rule}) && $self->{option_results}->{filter_rule} ne '' && + $result->{rule_name} !~ /$self->{option_results}->{filter_rule}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{rule_name} . "': no matching filter. 'rule' ", debug => 1); + next; + } + + $self->{appqospolicy}->{$instance} = $result; + } + + if (scalar(keys %{$self->{appqospolicy}}) <= 0 && scalar(keys %{$self->{qospolicy}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No policy found. Check your filters'); + $self->{output}->option_exit(); + } + + $self->{cache_name} = 'versanetworks_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_org}) ? md5_hex($self->{option_results}->{filter_org}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_rule}) ? md5_hex($self->{option_results}->{filter_rule}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_policy}) ? md5_hex($self->{option_results}->{filter_policy}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check policy usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='qos-policy-hit' + +=item B<--filter-org> + +Filter monitoring on 'org' -organization name- (can be a regexp). +An org may have 1 to n associated policies and rules + +=item B<--filter-policy> + +Filter monitoring on 'policy' -policy name- (can be a regexp). +A policy may have 1 to n associated rules + +=item B<--filter-rule> + +Filter monitoring on 'rule' -rule name- (can be a regexp) +Rules are unique + +=item B<--warning-*> B<--critical-*> + +Thresholds for QoS policy: +Can be: 'qos-policy-hit', 'qos-policy-sessions-deny', 'qos-policy-packets-dropped', 'qos-policy-traffic-dropped', +'qos-policy-packets-forwarded', 'qos-policy-traffic-forwarded'. + +Thresholds for applications QoS policy: +Can be: 'appqos-policy-hit', 'appqos-policy-packets-dropped', 'appqos-policy-traffic-dropped', +'appqos-policy-packets-forwarded', 'appqos-policy-traffic-forwarded'. + +=back + +=cut diff --git a/network/versa/snmp/mode/qospolicyusage.pm b/network/versa/snmp/mode/qospolicyusage.pm deleted file mode 100644 index 23f5b2e8f..000000000 --- a/network/versa/snmp/mode/qospolicyusage.pm +++ /dev/null @@ -1,321 +0,0 @@ -# -# Copyright 2020 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::versa::snmp::mode::policyusage; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use Digest::MD5 qw(md5_hex); - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'qospolicy', type => 1, cb_prefix_output => 'prefix_qospolicy_output', message_multiple => 'All QOS policies are ok' }, - { name => 'appqospolicy', type => 1, cb_prefix_output => 'prefix_appqospolicy_output', message_multiple => 'All Applications QOS policies are ok', skipped_code => { -10 => 1 } } - ]; - - $self->{maps_counters}->{qospolicy} = [ - { label => 'qos-policy-hit-count', nlabel => 'qos.policy.hit.count', set => { - key_values => [ { name => 'qosPolicyHitCount', diff => 1 }, { name => 'display' } ], - output_template => 'hits: %.2f', - perfdatas => [ - { label => 'qos_hit_count', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'qos-policy-session-deny-count', nlabel => 'qos.policy.sessions.deny.count', set => { - key_values => [ { name => 'qosPolicySessionDenyCount', diff => 1 }, { name => 'display' } ], - output_template => 'session deny: %.2f', - perfdatas => [ - { label => 'qos_sessions_deny_count', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'qos-policy-dropped-packets', nlabel => 'qos.policy.packets.dropped.count', set => { - key_values => [ { name => 'qosPolicyDropPktCount', diff => 1 }, { name => 'display' } ], - output_template => 'dropped packets: %.2f', - perfdatas => [ - { label => 'qos_dropped_packets', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'qos-policy-dropped-bytes', nlabel => 'appqos.policy.dropped.bytes', set => { - key_values => [ { name => 'qosPolicyDropByteCount', diff => 1 }, { name => 'display' } ], - output_template => 'dropped packets (volume): %.2f %s/s', - output_change_bytes => 2, - perfdatas => [ - { label => 'qos_dropped_packets_bytes', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'qos-policy-forwarded-packets', nlabel => 'qos.policy.packets.forwarded.count', set => { - key_values => [ { name => 'qosPolicyForwardPktCount', diff => 1 }, { name => 'display' } ], - output_template => 'forwarded packets: %.2f', - perfdatas => [ - { label => 'qos_forwarded_packets', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'qos-policy-forwarded-bytes', nlabel => 'qos.policy.forwarded.bytes', set => { - key_values => [ { name => 'qosPolicyForwardByteCount', diff => 1 }, { name => 'display' } ], - output_template => 'forwarded packets (volume): %.2f %s/s', - output_change_bytes => 2, - perfdatas => [ - { label => 'qos_forwarded_packets_bytes', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - } - ]; - - $self->{maps_counters}->{appqospolicy} = [ - { label => 'appqos-policy-hit-count', nlabel => 'appqos.policy.hit.count', set => { - key_values => [ { name => 'appQosPolicyHitCount', diff => 1 }, { name => 'display' } ], - output_template => 'hits: %.2f', - perfdatas => [ - { label => 'appqos_hit_count', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'appqos-policy-dropped-packets', nlabel => 'appqos.policy.packets.dropped.count', set => { - key_values => [ { name => 'appQosPolicyDropPktCount', diff => 1 }, { name => 'display' } ], - output_template => 'dropped packets: %.2f', - perfdatas => [ - { label => 'appqos_dropped_packets', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'appqos-policy-dropped-bytes', nlabel => 'appqos.policy.dropped.bytes', set => { - key_values => [ { name => 'appQosPolicyDropByteCount', diff => 1 }, { name => 'display' } ], - output_template => 'dropped packets (volume): %.2f %s/s', - output_change_bytes => 2, - perfdatas => [ - { label => 'appqos_dropped_packets_bytes', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'appqos-policy-forwarded-packets', nlabel => 'appqos.policy.packets.forwarded.count', set => { - key_values => [ { name => 'appQosPolicyForwardPktCount', diff => 1 }, { name => 'display' } ], - output_template => 'forwarded packets: %s', - perfdatas => [ - { label => 'appqos_forwarded_packets', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'appqos-policy-forwarded-bytes', nlabel => 'appqos.policy.forwarded.bytes', set => { - key_values => [ { name => 'appQosPolicyForwardByteCount', diff => 1 }, { name => 'display' } ], - output_template => 'forwarded packets (volume): %.2f %s/s', - output_change_bytes => 2, - perfdatas => [ - { label => 'appqos_forwarded_packets_bytes', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - } - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); - bless $self, $class; - - $options{options}->add_options(arguments => { - 'filter-org:s' => { name => 'filter_org' }, - 'filter-rule:s' => { name => 'filter_rule' }, - 'filter-policy:s' => { name => 'filter_policy' }, - }); - - return $self; -} - -sub prefix_qospolicy_output { - my ($self, %options) = @_; - - return "QOS Policy '" . $options{instance_value}->{display} . "' "; -} - -sub prefix_appqospolicy_output { - my ($self, %options) = @_; - - return "App QOS Policy '" . $options{instance_value}->{display} . "' "; -} - -my $mapping_qos_policy = { - qosPolicyOrgName => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.5' }, - qosPolicyName => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.6' }, - qosPolicyRuleName => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.7' }, - qosPolicyHitCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.8' }, - qosPolicyDropPktCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.9' }, - qosPolicyDropByteCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.10' }, - qosPolicyForwardPktCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.11' }, - qosPolicyForwardByteCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.12' }, - qosPolicySessionDenyCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1.13' }, -}; - -my $mapping_app_qos_policy = { - appQosPolicyOrgName => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.5' }, - appQosPolicyName => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.6' }, - appQosPolicyRuleName => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.7' }, - appQosPolicyHitCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.8' }, - appQosPolicyDropPktCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.9' }, - appQosPolicyDropByteCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.10' }, - appQosPolicyForwardPktCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.11' }, - appQosPolicyForwardByteCount => { oid => '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1.12' }, -}; - -my $oid_qosPolicyEntry = '.1.3.6.1.4.1.42359.2.2.1.2.1.5.1.1'; -my $oid_appQosPolicyEntry = '.1.3.6.1.4.1.42359.2.2.1.2.1.5.2.1'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{policy} = {}; - - $self->{results} = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_qosPolicyEntry, - start => $mapping_qos_policy->{qosPolicyOrgName}->{oid}, - end => $mapping_qos_policy->{qosPolicySessionDenyCount}->{oid} }, - { oid => $oid_appQosPolicyEntry, - start => $mapping_app_qos_policy->{appQosPolicyOrgName}->{oid}, - end => $mapping_app_qos_policy->{appQosPolicyForwardByteCount}->{oid} } - ], - nothing_quit => 1); - - foreach my $oid (keys %{$self->{results}->{$oid_qosPolicyEntry}}) { - next if ($oid !~ /^$mapping_qos_policy->{qosPolicyOrgName}->{oid}\.(.*)$/); - my $instance = $1; - - my $result = $options{snmp}->map_instance(mapping => $mapping_qos_policy, results => $self->{results}->{$oid_qosPolicyEntry}, instance => $instance); - - if (defined($self->{option_results}->{filter_org}) && $self->{option_results}->{filter_org} ne '' && - $result->{wgPolicyName} !~ /$self->{option_results}->{filter_org}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{qosPolicyOrgName} . "': no matching 'org' filter.", debug => 1); - next; - } - if (defined($self->{option_results}->{filter_policy}) && $self->{option_results}->{filter_policy} ne '' && - $result->{wgPolicyName} !~ /$self->{option_results}->{filter_policy}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{qosPolicyName} . "': no matching filter 'policy' .", debug => 1); - next; - } - if (defined($self->{option_results}->{filter_rule}) && $self->{option_results}->{filter_rule} ne '' && - $result->{wgPolicyName} !~ /$self->{option_results}->{filter_rule}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{qosPolicyRuleName} . "': no matching filter. 'rule' ", debug => 1); - next; - } - - $self->{qospolicy}->{$instance} = { display => $result->{appQosPolicyRuleName}, - %$result - }; - - } - - foreach my $oid (keys %{$self->{results}->{$oid_appQosPolicyEntry}}) { - next if ($oid !~ /^$mapping_app_qos_policy->{appQosPolicyOrgName}->{oid}\.(.*)$/); - my $instance = $1; - - my $result = $options{snmp}->map_instance(mapping => $mapping_app_qos_policy, results => $self->{results}->{$oid_appQosPolicyEntry}, instance => $instance); - - if (defined($self->{option_results}->{filter_org}) && $self->{option_results}->{filter_org} ne '' && - $result->{wgPolicyName} !~ /$self->{option_results}->{filter_org}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{appQosPolicyOrgName} . "': no matching 'org' filter.", debug => 1); - next; - } - if (defined($self->{option_results}->{filter_policy}) && $self->{option_results}->{filter_policy} ne '' && - $result->{wgPolicyName} !~ /$self->{option_results}->{filter_policy}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{appQosPolicyName} . "': no matching filter 'policy' .", debug => 1); - next; - } - if (defined($self->{option_results}->{filter_rule}) && $self->{option_results}->{filter_rule} ne '' && - $result->{wgPolicyName} !~ /$self->{option_results}->{filter_rule}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{appQosPolicyRuleName} . "': no matching filter. 'rule' ", debug => 1); - next; - } - - $self->{appqospolicy}->{$instance} = { display => $result->{appQosPolicyRuleName}, - %$result - }; - - } - - if (scalar(keys %{$self->{appqospolicy}}) <= 0 && scalar(keys %{$self->{qospolicy}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No policy found. Check your filters"); - $self->{output}->option_exit(); - } - - $self->{cache_name} = "versanetworks_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); -} - -1; - -__END__ - -=head1 MODE - -Check policy usage. - -=over 8 - -=item B<--filter-counters> - -Only display some counters (regexp can be used). -Example: --filter-counters='^total-connections$' - -=item B<--filter-org> - -Filter monitoring on 'org' -organization name- (can be a regexp). -An org may have 1 to n associated policies and rules - -=item B<--filter-policy> - -Filter monitoring on 'policy' -policy name- (can be a regexp). -A policy may have 1 to n associated rules - -=item B<--filter-rule> - -Filter monitoring on 'rule' -rule name- (can be a regexp) -Rules are unique - -=item B<--warning-*> - -Threshold WARNING for QOS Policy: -Can be: 'qos-policy-hit-count', 'qos-policy-dropped-packets', 'qos-policy-dropped-bytes', -'qos-policy-forwarded-packets', 'qos-policy-forwarded-bytes' - -Threshold WARNING for Applications QOS Policy: -Can be: 'appqos-policy-hit-count', 'appqos-policy-dropped-packets', -'appqos-policy-dropped-bytes', 'appqos-policy-forwarded-packets', 'appqos-policy-forwarded-bytes' - -=item B<--critical-*> - -Threshold CRITICAL for QOS Policy: -Can be: 'qos-policy-hit-count', 'qos-policy-dropped-packets', 'qos-policy-dropped-bytes', -'qos-policy-forwarded-packets', 'qos-policy-forwarded-bytes' - -Threshold CRITICAL for Applications QOS Policy: -Can be: 'appqos-policy-hit-count', 'appqos-policy-dropped-packets', -'appqos-policy-dropped-bytes', 'appqos-policy-forwarded-packets', 'appqos-policy-forwarded-bytes' - -=back - -=cut diff --git a/network/versa/snmp/mode/system.pm b/network/versa/snmp/mode/system.pm deleted file mode 100644 index b65f79148..000000000 --- a/network/versa/snmp/mode/system.pm +++ /dev/null @@ -1,161 +0,0 @@ -# -# Copyright 2020 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::versa::snmp::mode::system; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0, message_separator => ' - ' } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'cpu', nlabel => 'appliance.cpu.load.percentage', set => { - key_values => [ { name => 'cpu' } ], - output_template => 'CPU Load: %s%%', - perfdatas => [ - { label => 'cpu_load', template => '%s', min => 0, max => 100, unit => '%' }, - ], - } - }, - { label => 'memory', nlabel => 'appliance.memory.load.percentage', set => { - key_values => [ { name => 'memory' } ], - output_template => 'Memory Load: %s%%', - perfdatas => [ - { label => 'memory_load', template => '%s', min => 0, max => 100, unit => '%' }, - ], - } - }, - { label => 'active-sessions', nlabel => 'appliance.sessions.active.count', set => { - key_values => [ { name => 'sessions_active' } ], - output_template => 'Active sessions: %s', - perfdatas => [ - { label => 'active_sessions', template => '%s', min => 0 }, - ], - } - }, - { label => 'failed-sessions', nlabel => 'appliance.sessions.failed.count', set => { - key_values => [ { name => 'sessions_failed' } ], - output_template => 'Failed sessions : %s', - perfdatas => [ - { label => 'failed_sessions', template => '%s', min => 0 }, - ], - } - }, - { label => 'sessions-used-prct', nlabel => 'appliance.sessions.usage.percentage', set => { - key_values => [ { name => 'sessions_prct_used' } ], - output_template => 'Sessions used (prct): %s%%', - perfdatas => [ - { label => 'active_sessions', template => '%s', min => 0, unit => '%' }, - ], - } - }, - { label => 'sessions-free-prct', nlabel => 'appliance.sessions.free.percentage', set => { - key_values => [ { name => 'sessions_prct_free' } ], - output_template => 'Sessions free (prct): %s%%', - perfdatas => [ - { label => 'free_sessions', template => '%s', min => 0, unit => '%' }, - ], - } - } - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); - bless $self, $class; - - $options{options}->add_options(arguments => { - }); - - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $oid_deviceTableEntry = '.1.3.6.1.4.1.42359.2.2.1.1.1.1'; - - my $mapping_device = { - deviceCPULoad => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.2' }, - deviceMemoryLoad => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.3' }, - deviceBuffer => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.4' }, # deprecated, ignoring - deviceActiveSessions => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.5' }, - deviceFailedSessions => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.6' }, - deviceMaxSessions => { oid => '.1.3.6.1.4.1.42359.2.2.1.1.1.1.7' } - }; - - my $snmp_result = $options{snmp}->get_table( - oid => $oid_deviceTableEntry, - start => $mapping_device->{deviceCPULoad}->{oid}, - end => $mapping_device->{deviceMaxSessions}->{oid}, - nothing_quit => 1 - ); - - foreach my $oid (keys %$snmp_result) { - next if ($oid !~ /^$mapping_device->{deviceCPULoad}->{oid}\.(.*)/); - my $instance = $1; - $self->{global} = { cpu => $snmp_result->{$mapping_device->{deviceCPULoad}->{oid} . "." . $instance}, - memory => $snmp_result->{$mapping_device->{deviceMemoryLoad}->{oid} . "." . $instance}, - sessions_active => $snmp_result->{$mapping_device->{deviceActiveSessions}->{oid} . "." . $instance}, - sessions_failed => $snmp_result->{$mapping_device->{deviceFailedSessions}->{oid} . "." . $instance}, - }; - $self->{global}->{sessions_prct_used} = ($self->{global}->{sessions_active} + $self->{global}->{sessions_failed}) * 100 / - $snmp_result->{$mapping_device->{deviceMaxSessions}->{oid} . "." . $instance}; - $self->{global}->{sessions_prct_free} = 100 - $self->{global}->{sessions_prct_used}; - } - -} - -1; - -__END__ - -=head1 MODE - -Check system statistics (cpu, memory, sessions) - -=over 8 - -=item B<--filter-counters> - -Only display some counters (regexp can be used). -Example: --filter-counters='^(cpu)$' - -=item B<--warning-*> - -Threshold warning. -Can be: 'cpu', 'memory', 'active-sessions', 'failed-sessions', 'sessions-used-prct', 'sessions-free-prct'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'cpu', 'memory', 'active-sessions', 'failed-sessions', 'sessions-used-prct', 'sessions-free-prct'. - -=back - -=cut diff --git a/network/versa/snmp/plugin.pm b/network/versa/snmp/plugin.pm index e42e2f84e..c2ca877cd 100644 --- a/network/versa/snmp/plugin.pm +++ b/network/versa/snmp/plugin.pm @@ -30,10 +30,12 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'policy-usage' => 'network::versa::snmp::mode::qospolicyusage', - 'system' => 'network::versa::snmp::mode::system', - ); + $self->{modes} = { + 'devices' => 'network::versa::snmp::mode::devices', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'qos-policy' => 'network::versa::snmp::mode::qospolicy' + }; return $self; }