From 1b8bc822e2500bf3bd5e42a7b2c6e9baf4cc44ed Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 5 May 2017 14:29:43 +0200 Subject: [PATCH] add citrix application acceleration plugin --- .../citrix/appacceleration/snmp/mode/cpu.pm | 109 +++++++++ .../snmp/mode/listserviceclass.pm | 112 +++++++++ .../snmp/mode/serviceclassusage.pm | 220 ++++++++++++++++++ network/citrix/appacceleration/snmp/plugin.pm | 50 ++++ 4 files changed, 491 insertions(+) create mode 100644 network/citrix/appacceleration/snmp/mode/cpu.pm create mode 100644 network/citrix/appacceleration/snmp/mode/listserviceclass.pm create mode 100644 network/citrix/appacceleration/snmp/mode/serviceclassusage.pm create mode 100644 network/citrix/appacceleration/snmp/plugin.pm diff --git a/network/citrix/appacceleration/snmp/mode/cpu.pm b/network/citrix/appacceleration/snmp/mode/cpu.pm new file mode 100644 index 000000000..c359055bb --- /dev/null +++ b/network/citrix/appacceleration/snmp/mode/cpu.pm @@ -0,0 +1,109 @@ +# +# Copyright 2017 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::citrix::appacceleration::snmp::mode::cpu; + +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', set => { + key_values => [ { name => 'cpu' } ], + output_template => 'CPU Usage : %.2f%% (1min)', + perfdatas => [ + { label => 'cpu', value => 'cpu_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'load', set => { + key_values => [ { name => 'load' } ], + output_template => 'Load : %s', + perfdatas => [ + { label => 'load', value => 'load_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_wsCpuUsage = '.1.3.6.1.4.1.3845.30.4.1.1.1.24.0'; + my $oid_wsSystemLoad = '.1.3.6.1.4.1.3845.30.4.1.1.1.34.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_wsCpuUsage, $oid_wsSystemLoad], nothing_quit => 1); + + $self->{global} = { 'cpu' => $snmp_result->{$oid_wsCpuUsage}, 'load' => $snmp_result->{$oid_wsSystemLoad} }; +} + +1; + +__END__ + +=head1 MODE + +Check cpu usage. + +=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', 'load'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'cpu', 'load'. + +=back + +=cut + diff --git a/network/citrix/appacceleration/snmp/mode/listserviceclass.pm b/network/citrix/appacceleration/snmp/mode/listserviceclass.pm new file mode 100644 index 000000000..32398267d --- /dev/null +++ b/network/citrix/appacceleration/snmp/mode/listserviceclass.pm @@ -0,0 +1,112 @@ +# +# Copyright 2017 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::citrix::appacceleration::snmp::mode::listserviceclass; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_wsServiceClassName = '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.2'; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $self->{snmp}->get_table(oid => $oid_wsServiceClassName, nothing_quit => 1); + $self->{sc} = {}; + foreach my $oid (keys %{$snmp_result}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping service class '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{sc}->{$snmp_result->{$oid}} = { name => $snmp_result->{$oid} }; + } +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + foreach my $name (sort keys %{$self->{sc}}) { + $self->{output}->output_add(long_msg => "'" . $name . "'"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List Service Class:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name']); +} + +sub disco_show { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + foreach my $name (sort keys %{$self->{sc}}) { + $self->{output}->add_disco_entry(name => $name); + } +} + +1; + +__END__ + +=head1 MODE + +List Service Class. + +=over 8 + +=item B<--filter-name> + +Filter by service class name. + +=back + +=cut + diff --git a/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm b/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm new file mode 100644 index 000000000..a9d5aa97b --- /dev/null +++ b/network/citrix/appacceleration/snmp/mode/serviceclassusage.pm @@ -0,0 +1,220 @@ +# +# Copyright 2017 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::citrix::appacceleration::snmp::mode::serviceclassusage; + +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 => 'sc', type => 1, cb_prefix_output => 'prefix_sc_output', message_multiple => 'All Service Class are ok' } + ]; + + $self->{maps_counters}->{sc} = [ + { label => 'current-acc-con', set => { + key_values => [ { name => 'wsScsCurrentAcceleratedConnections' }, { name => 'display' } ], + output_template => 'Current Accelerated Connections : %s', + perfdatas => [ + { label => 'current_accelerated_connections', value => 'wsScsCurrentAcceleratedConnections_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-acc-con', set => { + key_values => [ { name => 'wsScsTotalAcceleratedConnections', diff => 1 }, { name => 'display' } ], + output_template => 'Total Accelerated Connections : %s', + perfdatas => [ + { label => 'total_accelerated_connections', value => 'wsScsTotalAcceleratedConnections_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-nonacc-con', set => { + key_values => [ { name => 'wsScsTotalNonAcceleratedConnections', diff => 1 }, { name => 'display' } ], + output_template => 'Total Non Accelerated Connections : %s', + perfdatas => [ + { label => 'total_nonaccelerated_connections', value => 'wsScsTotalNonAcceleratedConnections_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-in', set => { + key_values => [ { name => 'wsScsPreCompressReceivedOctets', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In : %s %s/s', + perfdatas => [ + { label => 'traffic_in', value => 'wsScsPreCompressReceivedOctets_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-in-compressed', set => { + key_values => [ { name => 'wsScsCompressReceivedOctets', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In Compressed : %s %s/s', + perfdatas => [ + { label => 'traffic_in_compressed', value => 'wsScsCompressReceivedOctets_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-out', set => { + key_values => [ { name => 'wsScsPreCompressSentOctets', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out : %s %s/s', + perfdatas => [ + { label => 'traffic_out', value => 'wsScsPreCompressSentOctets_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-out-compressed', set => { + key_values => [ { name => 'wsScsCompressSentOctets', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out Compressed : %s %s/s', + perfdatas => [ + { label => 'traffic_out_compressed', value => 'wsScsCompressSentOctets_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_sc_output { + my ($self, %options) = @_; + + return "Service Class '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +my $oid_wsServiceClassName = '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.2'; +my $mapping = { + wsScsCurrentAcceleratedConnections => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.3' }, + wsScsTotalAcceleratedConnections => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.4' }, + wsScsTotalNonAcceleratedConnections => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.6' }, + wsScsCompressSentOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.9' }, + wsScsCompressReceivedOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.10' }, + wsScsPreCompressSentOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.11' }, + wsScsPreCompressReceivedOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.12' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $snmp_result = $options{snmp}->get_table(oid => $oid_wsServiceClassName, nothing_quit => 1); + $self->{sc} = {}; + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping service class '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{sc}->{$instance} = { display => $snmp_result->{$oid} }; + } + + $options{snmp}->load(oids => [$mapping->{wsScsCurrentAcceleratedConnections}->{oid}, $mapping->{wsScsTotalAcceleratedConnections}->{oid}, + $mapping->{wsScsTotalNonAcceleratedConnections}->{oid}, $mapping->{wsScsCompressSentOctets}->{oid}, + $mapping->{wsScsCompressReceivedOctets}->{oid}, $mapping->{wsScsPreCompressSentOctets}->{oid}, + $mapping->{wsScsPreCompressReceivedOctets}->{oid} + ], + instances => [keys %{$self->{sc}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{sc}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + foreach my $name (('wsScsCompressSentOctets', 'wsScsCompressReceivedOctets', 'wsScsPreCompressSentOctets', 'wsScsPreCompressReceivedOctets')) { + $result->{$name} *= 8; + } + + foreach my $name (keys %$mapping) { + $self->{sc}->{$_}->{$name} = $result->{$name}; + } + } + + if (scalar(keys %{$self->{sc}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No service class found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "citrix_appacceleration_" . $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 service class usage. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'current-acc-con', 'total-acc-con', 'total-nonacc-con', +'traffic-in-compressed', 'traffic-out-compressed', +'traffic-in', 'traffic-out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'current-acc-con', 'total-acc-con', 'total-nonacc-con', +'traffic-in-compressed', 'traffic-out-compressed', +'traffic-in', 'traffic-out'. + +=item B<--filter-name> + +Filter by service class name (can be a regexp). + +=back + +=cut diff --git a/network/citrix/appacceleration/snmp/plugin.pm b/network/citrix/appacceleration/snmp/plugin.pm new file mode 100644 index 000000000..0dfacf9b1 --- /dev/null +++ b/network/citrix/appacceleration/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2017 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::citrix::appacceleration::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'cpu' => 'network::citrix::appacceleration::snmp::mode::cpu', + 'list-serviceclass' => 'network::citrix::appacceleration::snmp::mode::listserviceclass', + 'serviceclass-usage' => 'network::citrix::appacceleration::snmp::mode::serviceclassusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Citrix Application Acceleration Module in SNMP (CloudBridge, Orbital, Repeater). + +=cut