From d3ac05e6e66abb3a7820b7ff7c438551488f35cd Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 19 Feb 2021 11:24:25 +0100 Subject: [PATCH] Fix #2006 (#2600) --- .../mcafee/webgateway/snmp/mode/clients.pm | 9 +- .../webgateway/snmp/mode/connections.pm | 18 +-- .../mcafee/webgateway/snmp/mode/detections.pm | 11 +- .../webgateway/snmp/mode/ftpstatistics.pm | 14 ++- .../webgateway/snmp/mode/httpsstatistics.pm | 21 ++-- .../webgateway/snmp/mode/httpstatistics.pm | 21 ++-- .../mcafee/webgateway/snmp/mode/system.pm | 104 ++++++++++++++++++ .../mcafee/webgateway/snmp/mode/versions.pm | 44 ++++---- .../mcafee/webgateway/snmp/plugin.pm | 1 + 9 files changed, 176 insertions(+), 67 deletions(-) create mode 100644 apps/antivirus/mcafee/webgateway/snmp/mode/system.pm diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm index 316f20ee9..39aa418d1 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use Digest::MD5 qw(md5_hex); sub set_counters { my ($self, %options) = @_; @@ -71,10 +70,10 @@ my $oid_stConnectedSockets = '.1.3.6.1.4.1.1230.2.7.2.5.3.0'; sub manage_selection { my ($self, %options) = @_; - my $results = $options{snmp}->get_leef(oids => [ $oid_stClientCount, $oid_stConnectedSockets ], - nothing_quit => 1); - - $self->{global} = {}; + my $results = $options{snmp}->get_leef( + oids => [ $oid_stClientCount, $oid_stConnectedSockets ], + nothing_quit => 1 + ); $self->{global} = { stClientCount => $results->{$oid_stClientCount}, diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm index 8e4e966c0..bba2c9208 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm @@ -80,7 +80,7 @@ sub set_counters { sub prefix_connection_output { my ($self, %options) = @_; - return "Connections (per sec) "; + return 'Connections (per sec) '; } sub new { @@ -103,16 +103,18 @@ my $oid_stBlockedByURLFilter = '.1.3.6.1.4.1.1230.2.7.2.1.7.0'; sub manage_selection { my ($self, %options) = @_; - $self->{cache_name} = "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - my $results = $options{snmp}->get_leef(oids => [ $oid_stConnectionsLegitimate, $oid_stBlockedByAntiMalware, - $oid_stConnectionsBlocked, $oid_stBlockedByMediaFilter, - $oid_stBlockedByURLFilter ], - nothing_quit => 1); - - $self->{global} = {}; + my $results = $options{snmp}->get_leef( + oids => [ + $oid_stConnectionsLegitimate, $oid_stBlockedByAntiMalware, + $oid_stConnectionsBlocked, $oid_stBlockedByMediaFilter, + $oid_stBlockedByURLFilter + ], + nothing_quit => 1 + ); $self->{global} = { stConnectionsLegitimate => $results->{$oid_stConnectionsLegitimate}, diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm index a2081a5c8..34d71cc2f 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm @@ -88,21 +88,18 @@ my $oid_stCategoriesEntry = '.1.3.6.1.4.1.1230.2.7.2.1.10.1'; sub manage_selection { my ($self, %options) = @_; - $self->{cache_name} = "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); my $results = $options{snmp}->get_leef(oids => [ $oid_stMalwareDetected ], nothing_quit => 1); - my $results2 = $options{snmp}->get_table(oid => $oid_stCategoriesEntry, nothing_quit => 1); - - $self->{global} = {}; - $self->{categories} = {}; $self->{global} = { stMalwareDetected => $results->{$oid_stMalwareDetected}, }; + $self->{categories} = {}; foreach my $oid (keys %{$results2}) { next if ($oid !~ /^$mapping->{stCategoryName}->{oid}\.(\d+)/); my $instance = $1; @@ -114,9 +111,9 @@ sub manage_selection { next; } - $self->{categories}->{$result->{stCategoryName}} = { + $self->{categories}->{ $result->{stCategoryName} } = { stCategoryName => $result->{stCategoryName}, - stCategoryCount => $result->{stCategoryCount}, + stCategoryCount => $result->{stCategoryCount} } } diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm index 924d3b53d..f8f1a8f62 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm @@ -98,15 +98,17 @@ my $oid_stFtpBytesToServer = '.1.3.6.1.4.1.1230.2.7.2.4.5.0'; sub manage_selection { my ($self, %options) = @_; - $self->{cache_name} = "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - my $results = $options{snmp}->get_leef(oids => [ $oid_stFtpBytesFromClient, $oid_stFtpBytesFromServer, - $oid_stFtpBytesToClient, $oid_stFtpBytesToServer ], - nothing_quit => 1); - - $self->{traffics} = {}; + my $results = $options{snmp}->get_leef( + oids => [ + $oid_stFtpBytesFromClient, $oid_stFtpBytesFromServer, + $oid_stFtpBytesToClient, $oid_stFtpBytesToServer + ], + nothing_quit => 1 + ); $self->{traffics} = { stFtpBytesFromClient => $results->{$oid_stFtpBytesFromClient} * 8, diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm index 356f73c58..ae0d0f164 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm @@ -110,26 +110,27 @@ my $oid_stHttpsBytesToServer = '.1.3.6.1.4.1.1230.2.7.2.3.6.0'; sub manage_selection { my ($self, %options) = @_; - $self->{cache_name} = "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - my $results = $options{snmp}->get_leef(oids => [ $oid_stHttpsRequests, $oid_stHttpsBytesFromClient, - $oid_stHttpsBytesFromServer, $oid_stHttpsBytesToClient, - $oid_stHttpsBytesToServer ], - nothing_quit => 1); - - $self->{global} = {}; - $self->{traffics} = {}; + my $results = $options{snmp}->get_leef( + oids => [ + $oid_stHttpsRequests, $oid_stHttpsBytesFromClient, + $oid_stHttpsBytesFromServer, $oid_stHttpsBytesToClient, + $oid_stHttpsBytesToServer + ], + nothing_quit => 1 + ); $self->{global} = { - stHttpsRequests => $results->{$oid_stHttpsRequests}, + stHttpsRequests => $results->{$oid_stHttpsRequests} }; $self->{traffics} = { stHttpsBytesFromClient => $results->{$oid_stHttpsBytesFromClient} * 8, stHttpsBytesFromServer => $results->{$oid_stHttpsBytesFromServer} * 8, stHttpsBytesToClient => $results->{$oid_stHttpsBytesToClient} * 8, - stHttpsBytesToServer => $results->{$oid_stHttpsBytesToServer} * 8, + stHttpsBytesToServer => $results->{$oid_stHttpsBytesToServer} * 8 }; } diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm index 018c921e1..78921d45f 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm @@ -111,26 +111,27 @@ my $oid_stHttpBytesToServer = '.1.3.6.1.4.1.1230.2.7.2.2.6.0'; sub manage_selection { my ($self, %options) = @_; - $self->{cache_name} = "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - my $results = $options{snmp}->get_leef(oids => [ $oid_stHttpRequests, $oid_stHttpBytesFromClient, - $oid_stHttpBytesFromServer, $oid_stHttpBytesToClient, - $oid_stHttpBytesToServer ], - nothing_quit => 1); - - $self->{global} = {}; - $self->{traffics} = {}; + my $results = $options{snmp}->get_leef( + oids => [ + $oid_stHttpRequests, $oid_stHttpBytesFromClient, + $oid_stHttpBytesFromServer, $oid_stHttpBytesToClient, + $oid_stHttpBytesToServer + ], + nothing_quit => 1 + ); $self->{global} = { - stHttpRequests => $results->{$oid_stHttpRequests}, + stHttpRequests => $results->{$oid_stHttpRequests} }; $self->{traffics} = { stHttpBytesFromClient => $results->{$oid_stHttpBytesFromClient} * 8, stHttpBytesFromServer => $results->{$oid_stHttpBytesFromServer} * 8, stHttpBytesToClient => $results->{$oid_stHttpBytesToClient} * 8, - stHttpBytesToServer => $results->{$oid_stHttpBytesToServer} * 8, + stHttpBytesToServer => $results->{$oid_stHttpBytesToServer} * 8 }; } diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/system.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/system.pm new file mode 100644 index 000000000..e5a2a55a5 --- /dev/null +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/system.pm @@ -0,0 +1,104 @@ +# +# Copyright 2021 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 apps::antivirus::mcafee::webgateway::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 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'cpu-utilization', nlabel => 'system.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_util' } ], + output_template => 'cpu usage: %.2f%%', + perfdatas => [ + { template => '%.2f', unit => '%', min => 0, max => 100 } + ] + } + }, + { label => 'dns-resolve-time', nlabel => 'system.dns.resolve.time.milliseconds', set => { + key_values => [ { name => 'dns_time' } ], + output_template => 'time to resolve dns: %sms', + perfdatas => [ + { template => '%s', unit => 'ms', min => 0 } + ] + } + } + ]; +} + +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; +} + +my $oid_stCPULoad = '.1.3.6.1.4.1.1230.2.7.2.5.1.0'; +my $oid_stResolveHostViaDNS = '.1.3.6.1.4.1.1230.2.7.2.5.6.0'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_leef( + oids => [ $oid_stCPULoad, $oid_stResolveHostViaDNS ], + nothing_quit => 1 + ); + + $self->{global} = { + cpu_util => $results->{$oid_stCPULoad}, + dns_time => $results->{$oid_stResolveHostViaDNS} + }; +} + +1; + +__END__ + +=head1 MODE + +Check system. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +(Example: --filter-counters='cpu') + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu-utilization', 'dns-resolve-time'. + +=back + +=cut diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm index 4681d4bd9..abf301868 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm @@ -41,10 +41,13 @@ sub custom_version_calc { sub custom_version_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{since}, - threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - return $exit; + return $self->{perfdata}->threshold_check( + value => $self->{result_values}->{since}, + threshold => [ + { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } + ] + ); } sub custom_version_output { @@ -72,7 +75,7 @@ sub set_counters { closure_custom_calc_extra_options => { label_ref => 'pMFEDATVersion', output_ref => 'DAT Version' }, closure_custom_output => $self->can('custom_version_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_version_threshold'), + closure_custom_threshold_check => $self->can('custom_version_threshold') } }, { label => 'tsdb-version', set => { @@ -81,7 +84,7 @@ sub set_counters { closure_custom_calc_extra_options => { label_ref => 'pTSDBVersion', output_ref => 'TrustedSource Database Version' }, closure_custom_output => $self->can('custom_version_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_version_threshold'), + closure_custom_threshold_check => $self->can('custom_version_threshold') } }, { label => 'proactive-version', set => { @@ -90,19 +93,12 @@ sub set_counters { closure_custom_calc_extra_options => { label_ref => 'pAMProactiveVersion', output_ref => 'ProActive Database Version' }, closure_custom_output => $self->can('custom_version_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_version_threshold'), + closure_custom_threshold_check => $self->can('custom_version_threshold') } } ]; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->{cache}->check_options(%options); -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -115,6 +111,13 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{cache}->check_options(%options); +} + my $oid_pMFEDATVersion = '.1.3.6.1.4.1.1230.2.7.1.20.4.0'; my $oid_pAMProactiveVersion = '.1.3.6.1.4.1.1230.2.7.1.20.5.0'; my $oid_pTSDBVersion = '.1.3.6.1.4.1.1230.2.7.1.20.6.0'; @@ -122,19 +125,18 @@ my $oid_pTSDBVersion = '.1.3.6.1.4.1.1230.2.7.1.20.6.0'; sub manage_selection { my ($self, %options) = @_; - $self->{new_datas} = {}; - $self->{cache}->read(statefile => "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + $self->{cache}->read(statefile => 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'))); - my $results = $options{snmp}->get_leef(oids => [ $oid_pMFEDATVersion, $oid_pAMProactiveVersion, $oid_pTSDBVersion ], - nothing_quit => 1); - - $self->{global} = {}; + my $results = $options{snmp}->get_leef( + oids => [ $oid_pMFEDATVersion, $oid_pAMProactiveVersion, $oid_pTSDBVersion ], + nothing_quit => 1 + ); $self->{new_datas} = { pMFEDATVersion => $results->{$oid_pMFEDATVersion}, pAMProactiveVersion => $results->{$oid_pAMProactiveVersion}, - pTSDBVersion => $results->{$oid_pTSDBVersion}, + pTSDBVersion => $results->{$oid_pTSDBVersion} }; foreach my $version (('pMFEDATVersion', 'pAMProactiveVersion', 'pTSDBVersion')) { diff --git a/apps/antivirus/mcafee/webgateway/snmp/plugin.pm b/apps/antivirus/mcafee/webgateway/snmp/plugin.pm index cf9f6f009..4d69798e2 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/plugin.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/plugin.pm @@ -38,6 +38,7 @@ sub new { 'ftp-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::ftpstatistics', 'http-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpstatistics', 'https-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpsstatistics', + 'system' => 'apps::antivirus::mcafee::webgateway::snmp::mode::system', 'versions' => 'apps::antivirus::mcafee::webgateway::snmp::mode::versions', };