From d5019bff5fdf47b7d38eb68712f2851ad15117dc Mon Sep 17 00:00:00 2001 From: itoussies <65223458+itoussies@users.noreply.github.com> Date: Fri, 8 Jan 2021 08:52:57 +0100 Subject: [PATCH] enh(plugin)apps-antivirus-mcafee-webgateway-snmp metricsv2 (#2476) --- .../mcafee/webgateway/snmp/mode/clients.pm | 31 ++++++--------- .../webgateway/snmp/mode/connections.pm | 34 ++++++++-------- .../mcafee/webgateway/snmp/mode/detections.pm | 6 +-- .../webgateway/snmp/mode/ftpstatistics.pm | 28 ++++++------- .../webgateway/snmp/mode/httpsstatistics.pm | 36 ++++++++--------- .../webgateway/snmp/mode/httpstatistics.pm | 12 +++--- .../mcafee/webgateway/snmp/mode/versions.pm | 39 ++++++++++--------- .../mcafee/webgateway/snmp/plugin.pm | 4 +- 8 files changed, 92 insertions(+), 98 deletions(-) diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm index e85e53471..f553437a9 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/clients.pm @@ -30,28 +30,28 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0 }, + { name => 'global', type => 0 } ]; $self->{maps_counters}->{global} = [ - { label => 'clients', set => { + { label => 'clients', nlabel => 'clients.connected.count', set => { key_values => [ { name => 'stClientCount' } ], output_template => 'Connected clients: %d', perfdatas => [ - { label => 'connected_clients', value => 'stClientCount', template => '%d', - min => 0, unit => 'clients' }, - ], + { label => 'connected_clients', template => '%d', + min => 0, unit => 'clients' } + ] } }, - { label => 'sockets', set => { + { label => 'sockets', nlabel => 'sockets.connected.count', set => { key_values => [ { name => 'stConnectedSockets' } ], output_template => 'Open network sockets: %d', perfdatas => [ - { label => 'open_sockets', value => 'stConnectedSockets', template => '%d', - min => 0, unit => 'sockets' }, - ], + { label => 'open_sockets', template => '%d', + min => 0, unit => 'sockets' } + ] } - }, + } ]; } @@ -60,18 +60,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-counters:s" => { name => 'filter_counters', default => '' }, - }); + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - my $oid_stClientCount = '.1.3.6.1.4.1.1230.2.7.2.5.2.0'; my $oid_stConnectedSockets = '.1.3.6.1.4.1.1230.2.7.2.5.3.0'; diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm index b41160c3a..c7dafe826 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/connections.pm @@ -30,50 +30,50 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_connection_output' }, + { name => 'global', type => 0, cb_prefix_output => 'prefix_connection_output' } ]; $self->{maps_counters}->{global} = [ - { label => 'legitimate', set => { + { label => 'legitimate', nlabel => 'connections.legitimate.persecond', set => { key_values => [ { name => 'stConnectionsLegitimate', per_second => 1 } ], output_template => 'Legitimate: %d', perfdatas => [ - { label => 'legitimate_connections', template => '%d', min => 0, unit => 'connections/s' }, - ], + { label => 'legitimate_connections', template => '%d', min => 0, unit => 'connections/s' } + ] } }, - { label => 'blocked', set => { + { label => 'blocked', nlabel => 'connections.blocked.persecond', set => { key_values => [ { name => 'stConnectionsBlocked', per_second => 1 } ], output_template => 'Blocked: %d', perfdatas => [ - { label => 'blocked_connections', template => '%d', min => 0, unit => 'connections/s' }, - ], + { label => 'blocked_connections', template => '%d', min => 0, unit => 'connections/s' } + ] } }, - { label => 'blocked-by-am', set => { + { label => 'blocked-by-am', nlabel => 'connections.antimalware.blocked.persecond', set => { key_values => [ { name => 'stBlockedByAntiMalware', per_second => 1 } ], output_template => 'Blocked by Anti Malware: %d', perfdatas => [ - { label => 'blocked_by_am', template => '%d', min => 0, unit => 'connections/s' }, - ], + { label => 'blocked_by_am', template => '%d', min => 0, unit => 'connections/s' } + ] } }, - { label => 'blocked-by-mf', set => { + { label => 'blocked-by-mf', nlabel => 'connections.mediafilter.blocked.persecond', set => { key_values => [ { name => 'stBlockedByMediaFilter', per_second => 1 } ], output_template => 'Blocked by Media Filter: %d', perfdatas => [ - { label => 'blocked_by_mf', template => '%d', min => 0, unit => 'connections/s' }, - ], + { label => 'blocked_by_mf', template => '%d', min => 0, unit => 'connections/s' } + ] } }, - { label => 'blocked-by-uf', set => { + { label => 'blocked-by-uf', nlabel => 'connections.urlfilter.blocked.persecond', set => { key_values => [ { name => 'stBlockedByURLFilter', per_second => 1 } ], output_template => 'Blocked by URL Filter: %d', perfdatas => [ - { label => 'blocked_by_uf', template => '%d', min => 0, unit => 'connections/s' }, - ], + { label => 'blocked_by_uf', template => '%d', min => 0, unit => 'connections/s' } + ] } - }, + } ]; } diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm index c0ee3d4fc..2d40035c0 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/detections.pm @@ -32,11 +32,11 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0 }, { name => 'categories', type => 1, cb_prefix_output => 'prefix_categories_output', - message_multiple => 'All categories are ok' }, + message_multiple => 'All categories are ok' } ]; $self->{maps_counters}->{global} = [ - { label => 'malware-detected', set => { + { label => 'malware-detected', nlabel => 'malwares.detected.persecond', set => { key_values => [ { name => 'stMalwareDetected', per_second => 1 } ], output_template => 'Malware detected (per sec): %d', perfdatas => [ @@ -46,7 +46,7 @@ sub set_counters { } ]; $self->{maps_counters}->{categories} = [ - { label => 'category', set => { + { label => 'category', nlabel => 'category.malwares.detected.persecond', set => { key_values => [ { name => 'stCategoryCount', per_second => 1 }, { name => 'stCategoryName' } ], output_template => 'detections (per sec): %d', perfdatas => [ diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm index 472846878..755da0a03 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/ftpstatistics.pm @@ -30,46 +30,46 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' }, + { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' } ]; $self->{maps_counters}->{traffics} = [ - { label => 'client-to-proxy', set => { + { label => 'client-to-proxy', nlabel => 'ftp.traffic.client2proxy.bitspersecond', set => { key_values => [ { name => 'stFtpBytesFromClient', per_second => 1 } ], output_template => 'from client to proxy: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'ftp_traffic_client_to_proxy', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'ftp_traffic_client_to_proxy', template => '%d', min => 0, unit => 'b/s' } + ] } }, - { label => 'server-to-proxy', set => { + { label => 'server-to-proxy', nlabel => 'ftp.traffic.server2proxy.bitspersecond', set => { key_values => [ { name => 'stFtpBytesFromServer', per_second => 1 } ], output_template => 'from server to proxy: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'ftp_traffic_server_to_proxy', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'ftp_traffic_server_to_proxy', template => '%d', min => 0, unit => 'b/s' } + ] } }, - { label => 'proxy-to-client', set => { + { label => 'proxy-to-client', nlabel => 'ftp.traffic.proxy2client.bitspersecond', set => { key_values => [ { name => 'stFtpBytesToClient', per_second => 1 } ], output_template => 'from proxy to client: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'ftp_traffic_proxy_to_client', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'ftp_traffic_proxy_to_client', template => '%d', min => 0, unit => 'b/s' } + ] } }, - { label => 'proxy-to-server', set => { + { label => 'proxy-to-server', nlabel => 'ftp.traffic.proxy2server.bitspersecond', set => { key_values => [ { name => 'stFtpBytesToServer', per_second => 1 } ], output_template => 'from proxy to server: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'ftp_traffic_proxy_to_server', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'ftp_traffic_proxy_to_server', template => '%d', min => 0, unit => 'b/s' } + ] } - }, + } ]; } diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm index c1faf9c57..0d33db030 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/httpsstatistics.pm @@ -31,56 +31,56 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0 }, - { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' }, + { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' } ]; $self->{maps_counters}->{global} = [ - { label => 'requests', set => { + { label => 'requests', nlabel => 'https.requests.persecond', set => { key_values => [ { name => 'stHttpsRequests', per_second => 1 } ], output_template => 'HTTPS Requests (per sec): %d', perfdatas => [ - { label => 'https_requests', template => '%d', min => 0, unit => 'requests/s' }, - ], + { label => 'https_requests', template => '%d', min => 0, unit => 'requests/s' } + ] } - }, + } ]; $self->{maps_counters}->{traffics} = [ - { label => 'client-to-proxy', set => { + { label => 'client-to-proxy', nlabel => 'https.traffic.client2proxy.bitspersecond', set => { key_values => [ { name => 'stHttpsBytesFromClient', per_second => 1 } ], output_template => 'from client to proxy: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'https_traffic_client_to_proxy', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'https_traffic_client_to_proxy', template => '%d', min => 0, unit => 'b/s' } + ] } }, - { label => 'server-to-proxy', set => { + { label => 'server-to-proxy', nlabel => 'https.traffic.server2proxy.bitspersecond', set => { key_values => [ { name => 'stHttpsBytesFromServer', per_second => 1 } ], output_template => 'from server to proxy: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'https_traffic_server_to_proxy', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'https_traffic_server_to_proxy', template => '%d', min => 0, unit => 'b/s' } + ] } }, - { label => 'proxy-to-client', set => { + { label => 'proxy-to-client', nlabel => 'https.traffic.proxy2client.bitspersecond', set => { key_values => [ { name => 'stHttpsBytesToClient', per_second => 1 } ], output_template => 'from proxy to client: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'https_traffic_proxy_to_client', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'https_traffic_proxy_to_client', template => '%d', min => 0, unit => 'b/s' } + ] } }, - { label => 'proxy-to-server', set => { + { label => 'proxy-to-server', nlabel => 'https.traffic.proxy2server.bitspersecond', set => { key_values => [ { name => 'stHttpsBytesToServer', per_second => 1 } ], output_template => 'from proxy to server: %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'https_traffic_proxy_to_server', template => '%d', min => 0, unit => 'b/s' }, - ], + { label => 'https_traffic_proxy_to_server', template => '%d', min => 0, unit => 'b/s' } + ] } - }, + } ]; } diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm index 9804c6a1c..145382cc1 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.pm @@ -31,11 +31,11 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0 }, - { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' }, + { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' } ]; $self->{maps_counters}->{global} = [ - { label => 'requests', set => { + { label => 'requests', nlabel => 'http.requests.persecond', set => { key_values => [ { name => 'stHttpRequests', per_second => 1 } ], output_template => 'HTTP Requests (per sec): %d', perfdatas => [ @@ -46,7 +46,7 @@ sub set_counters { ]; $self->{maps_counters}->{traffics} = [ - { label => 'client-to-proxy', set => { + { label => 'client-to-proxy', nlabel => 'http.traffic.client2proxy.bitspersecond', set => { key_values => [ { name => 'stHttpBytesFromClient', per_second => 1 } ], output_template => 'from client to proxy: %s %s/s', output_change_bytes => 2, @@ -55,7 +55,7 @@ sub set_counters { ] } }, - { label => 'server-to-proxy', set => { + { label => 'server-to-proxy', nlabel => 'http.traffic.server2proxy.bitspersecond', set => { key_values => [ { name => 'stHttpBytesFromServer', per_second => 1 } ], output_template => 'from server to proxy: %s %s/s', output_change_bytes => 2, @@ -64,7 +64,7 @@ sub set_counters { ] } }, - { label => 'proxy-to-client', set => { + { label => 'proxy-to-client', nlabel => 'http.traffic.proxy2client.bitspersecond', set => { key_values => [ { name => 'stHttpBytesToClient', per_second => 1 } ], output_template => 'from proxy to client: %s %s/s', output_change_bytes => 2, @@ -73,7 +73,7 @@ sub set_counters { ] } }, - { label => 'proxy-to-server', set => { + { label => 'proxy-to-server', nlabel => 'http.traffic.proxy2server.bitspersecond', set => { key_values => [ { name => 'stHttpBytesToServer', per_second => 1 } ], output_template => 'from proxy to server: %s %s/s', output_change_bytes => 2, diff --git a/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm b/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm index c889105d5..5294be966 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm @@ -50,16 +50,19 @@ sub custom_version_threshold { sub custom_version_output { my ($self, %options) = @_; - my $human_since = centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since}); - my $msg = sprintf("%s: %s [Last update: %s]", $self->{result_values}->{output}, $self->{result_values}->{version}, $human_since); - return $msg; + return sprintf( + "%s: %s [Last update: %s]", + $self->{result_values}->{output}, + $self->{result_values}->{version}, + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since}) + ); } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ @@ -89,24 +92,10 @@ sub set_counters { closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => $self->can('custom_version_threshold'), } - }, + } ]; } -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-counters:s" => { name => 'filter_counters', default => '' }, - }); - - $self->{cache} = centreon::plugins::statefile->new(%options); - return $self; -} - sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); @@ -114,6 +103,18 @@ sub check_options { $self->{cache}->check_options(%options); } +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + $self->{cache} = centreon::plugins::statefile->new(%options); + return $self; +} + 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'; diff --git a/apps/antivirus/mcafee/webgateway/snmp/plugin.pm b/apps/antivirus/mcafee/webgateway/snmp/plugin.pm index 78f44ccd1..dc29ca8b5 100644 --- a/apps/antivirus/mcafee/webgateway/snmp/plugin.pm +++ b/apps/antivirus/mcafee/webgateway/snmp/plugin.pm @@ -31,7 +31,7 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( + $self->{modes} = { 'clients' => 'apps::antivirus::mcafee::webgateway::snmp::mode::clients', 'connections' => 'apps::antivirus::mcafee::webgateway::snmp::mode::connections', 'detections' => 'apps::antivirus::mcafee::webgateway::snmp::mode::detections', @@ -39,7 +39,7 @@ sub new { 'http-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpstatistics', 'https-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpsstatistics', 'versions' => 'apps::antivirus::mcafee::webgateway::snmp::mode::versions', - ); + }; return $self; }