From f110fec4c343bb7e033c8ed8f5d627266955ec11 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 13 Jun 2019 10:12:57 +0200 Subject: [PATCH] Fix #755 --- .../cisco/ironport/snmp/mode/proxyusage.pm | 239 ++++++++++++++++++ network/cisco/ironport/snmp/plugin.pm | 1 + 2 files changed, 240 insertions(+) create mode 100644 centreon/common/cisco/ironport/snmp/mode/proxyusage.pm diff --git a/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm b/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm new file mode 100644 index 000000000..4ed2080b9 --- /dev/null +++ b/centreon/common/cisco/ironport/snmp/mode/proxyusage.pm @@ -0,0 +1,239 @@ +# +# Copyright 2019 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 centreon::common::cisco::ironport::snmp::mode::proxyusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub custom_data_calc { + my ($self, %options) = @_; + + my $delta_value = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{hit_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{hit_ref}}; + my $delta_total = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref}}; + + $self->{result_values}->{hits_prct} = 100; + if ($delta_total > 0) { + $self->{result_values}->{hits_prct} = $delta_value * 100 / $delta_total; + } + return 0; +} + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'global_http', type => 0, cb_prefix_output => 'prefix_http_output', skipped_code => { -10 => 1 } }, + { name => 'global_icp', type => 0, cb_prefix_output => 'prefix_icp_output', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global_http} = [ + { label => 'client-http-hits-rate', nlabel => 'client.http.hits.percentage', set => { + key_values => [ { name => 'cacheClientRequests', diff => 1 }, { name => 'cacheClientHits', diff => 1 } ], + closure_custom_calc => $self->can('custom_data_calc'), + closure_custom_calc_extra_options => { hit_ref => 'cacheClientHits', total_ref => 'cacheClientRequests' }, + output_template => 'client hits rate : %.2f %%', output_use => 'hits_prct', threshold_use => 'hits_prct', + perfdatas => [ + { label => 'client_http_hits_rate', value => 'hits_prct', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'client-http-errors', display_ok => 0, nlabel => 'client.http.errors.count', set => { + key_values => [ { name => 'cacheClientErrors', diff => 1 } ], + output_template => 'client errors : %s', + perfdatas => [ + { label => 'client_http_errors', value => 'cacheClientErrors_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'client-http-traffic-in', display_ok => 0, nlabel => 'client.http.traffic.in.bitspersecond', set => { + key_values => [ { name => 'cacheClientInKb', diff => 1 } ], + output_template => 'client traffic in : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'client_http_traffic_in', value => 'cacheClientInKb_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + { label => 'client-http-traffic-out', display_ok => 0, nlabel => 'client.http.traffic.out.bitspersecond', set => { + key_values => [ { name => 'cacheClientOutKb', diff => 1 } ], + output_template => 'client traffic Out : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'client_http_traffic_out', value => 'cacheClientOutKb_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + { label => 'total-con-clients', nlabel => 'client.http.total.connections.count', set => { + key_values => [ { name => 'cacheClientTotalConns' } ], + output_template => 'total number of clients : %s', + perfdatas => [ + { label => 'total_con_clients', value => 'cacheClientTotalConns_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{global_icp} = [ + { label => 'client-icp-hits-rate', nlabel => 'client.icp.hits.percentage', set => { + key_values => [ { name => 'cacheClientICPRequests', diff => 1 }, { name => 'cacheClientICPHits', diff => 1 } ], + closure_custom_calc_extra_options => { hit_ref => 'cacheClientICPHits', total_ref => 'cacheClientICPRequests' }, + closure_custom_calc => $self->can('custom_data_calc'), + output_template => 'client hits rate : %.2f %%', output_use => 'hits_prct', threshold_use => 'hits_prct', + perfdatas => [ + { label => 'client_icp_hits_rate', value => 'hits_prct', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'http-mean-time', nlabel => 'http.response.mean.time.milliseconds', set => { + key_values => [ { name => 'cacheMeanRespTime' } ], + output_template => 'http mean response time : %s ms', + perfdatas => [ + { label => 'http_mean_time', value => 'cacheMeanRespTime_absolute', template => '%s', + min => 0, unit => 'ms' }, + ], + } + }, + { label => 'server-traffic-in', display_ok => 0, nlabel => 'server.traffic.in.bitspersecond', set => { + key_values => [ { name => 'cacheServerInKb', diff => 1 } ], + output_template => 'server traffic in : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'server_traffic_in', value => 'cacheServerInKb_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + { label => 'server-traffic-out', display_ok => 0, nlabel => 'server.traffic.out.bitspersecond', set => { + key_values => [ { name => 'cacheServerOutKb', diff => 1 } ], + output_template => 'server traffic Out : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'server_traffic_out', value => 'cacheServerOutKb_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + ]; +} + +sub prefix_http_output { + my ($self, %options) = @_; + + return "http "; +} + +sub prefix_icp_output { + my ($self, %options) = @_; + + return "icp "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my %oids = ( + cacheClientRequests => '.1.3.6.1.4.1.15497.1.2.3.2.2.0', + cacheClientHits => '.1.3.6.1.4.1.15497.1.2.3.2.3.0', + cacheClientErrors => '.1.3.6.1.4.1.15497.1.2.3.2.4.0', + cacheClientInKb => '.1.3.6.1.4.1.15497.1.2.3.2.5.0', + cacheClientOutKb => '.1.3.6.1.4.1.15497.1.2.3.2.6.0', + cacheClientICPRequests => '.1.3.6.1.4.1.15497.1.2.3.2.11.0', + cacheClientICPHits => '.1.3.6.1.4.1.15497.1.2.3.2.12.0', + cacheServerInKb => '.1.3.6.1.4.1.15497.1.2.3.3.5.0', + cacheServerOutKb => '.1.3.6.1.4.1.15497.1.2.3.3.6.0', + cacheClientTotalConns => '.1.3.6.1.4.1.15497.1.2.3.2.8.0', + cacheMeanRespTime => '.1.3.6.1.4.1.15497.1.2.3.6.2.0', + ); + my $snmp_result = $options{snmp}->get_leef(oids => [ + values %oids + ], nothing_quit => 1); + + $self->{global_http} = { + cacheClientRequests => $snmp_result->{$oids{cacheClientRequests}}, + cacheClientHits => $snmp_result->{$oids{cacheClientHits}}, + cacheClientErrors => $snmp_result->{$oids{cacheClientErrors}}, + cacheClientInKb => $snmp_result->{$oids{cacheClientInKb}} * 1024 * 8, + cacheClientOutKb => $snmp_result->{$oids{cacheClientOutKb}} * 1024 * 8, + cacheClientTotalConns => $snmp_result->{$oids{cacheClientTotalConns}}, + }; + $self->{global_icp} = { + cacheClientICPRequests => $snmp_result->{$oids{cacheClientICPRequests}}, + cacheClientICPHits => $snmp_result->{$oids{cacheClientICPHits}}, + }; + $self->{global} = { + cacheMeanRespTime => $snmp_result->{$oids{cacheMeanRespTime}}, + cacheServerInKb => $snmp_result->{$oids{cacheServerInKb}} * 1024 * 8, + cacheServerOutKb => $snmp_result->{$oids{cacheServerOutKb}} * 1024 * 8, + }; + + $self->{cache_name} = "cisco_ironport_" . $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')); +} + +1; + +__END__ + +=head1 MODE + +Check proxy usage (websecurity appliance). + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='http' + +=item B<--warning-*> B<--critical-*> + +Threshold warning. +Can be: 'client-http-hits-rate', 'client-http-errors', 'client-http-traffic-in', +'client-http-traffic-out', 'total-con-clients', 'client-icp-hits-rate', +'server-traffic-in', 'server-traffic-out', 'http-mean-time'. + +=back + +=cut diff --git a/network/cisco/ironport/snmp/plugin.pm b/network/cisco/ironport/snmp/plugin.pm index c11a67445..2cc0ae8da 100644 --- a/network/cisco/ironport/snmp/plugin.pm +++ b/network/cisco/ironport/snmp/plugin.pm @@ -37,6 +37,7 @@ sub new { 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::ironport::snmp::mode::memory', + 'proxy-usage' => 'centreon::common::cisco::ironport::snmp::mode::proxyusage', ); return $self;