diff --git a/apps/antivirus/kaspersky/snmp/mode/deployment.pm b/apps/antivirus/kaspersky/snmp/mode/deployment.pm index a9569f8b6..26eab3b40 100644 --- a/apps/antivirus/kaspersky/snmp/mode/deployment.pm +++ b/apps/antivirus/kaspersky/snmp/mode/deployment.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Deployment status is '%s'", $self->{result_values}->{status}); - return $msg; + return sprintf("Deployment status is '%s'", $self->{result_values}->{status}); } sub custom_status_calc { @@ -62,9 +61,12 @@ sub custom_progress_threshold { sub custom_progress_output { my ($self, %options) = @_; - my $msg = sprintf("Deployment progress: %d/%d (%.2f%%)", - $self->{result_values}->{installed}, $self->{result_values}->{total}, $self->{result_values}->{prct_installed}); - return $msg; + return sprintf( + "Deployment progress: %d/%d (%.2f%%)", + $self->{result_values}->{installed}, + $self->{result_values}->{total}, + $self->{result_values}->{prct_installed} + ); } sub custom_progress_calc { @@ -158,15 +160,20 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', set => { + { + label => 'status', + type => 2, + warning_default => '%{status} =~ /Warning/i', + critical_default => '%{status} =~ /Critical/i', + set => { key_values => [ { name => 'deploymentStatus' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, - { label => 'progress', set => { + { label => 'progress', nlabel => 'hosts.antivirus.installed.count', set => { key_values => [ { name => 'hostsInGroups' }, { name => 'hostsWithAntivirus' } ], closure_custom_calc => $self->can('custom_progress_calc'), closure_custom_output => $self->can('custom_progress_output'), @@ -174,15 +181,15 @@ sub set_counters { closure_custom_perfdata => $self->can('custom_progress_perfdata'), } }, - { label => 'failed', set => { + { label => 'failed', nlabel => 'hosts.antivirus.install.failed.count', set => { key_values => [ { name => 'hostsRemoteInstallFailed' } ], output_template => '%d failed remote installation(s)', perfdatas => [ - { label => 'failed', value => 'hostsRemoteInstallFailed', template => '%d', min => 0 }, - ], + { label => 'failed', template => '%d', min => 0 }, + ] } }, - { label => 'expiring', set => { + { label => 'expiring', nlabel => 'hosts.expiring.licence.count', set => { key_values => [ { name => 'licenceExpiringSerial' }, { name => 'licenceExpiringDays' }, { name => 'hostsLicenceExpiring' } ], closure_custom_calc => $self->can('custom_expiring_calc'), closure_custom_output => $self->can('custom_expiring_output'), @@ -190,14 +197,14 @@ sub set_counters { closure_custom_perfdata => $self->can('custom_expiring_perfdata'), } }, - { label => 'expired', set => { + { label => 'expired', nlabel => 'hosts.expired.licence.count', set => { key_values => [ { name => 'licenceExpiredSerial' }, { name => 'hostsLicenceExpired' } ], closure_custom_calc => $self->can('custom_expired_calc'), closure_custom_output => $self->can('custom_expired_output'), closure_custom_threshold_check => $self->can('custom_expired_threshold'), closure_custom_perfdata => $self->can('custom_expired_perfdata'), } - }, + } ]; } @@ -206,22 +213,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - "percent" => { name => 'percent' }, - }); + $options{options}->add_options(arguments => { + 'percent' => { name => 'percent' } + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - my %map_status = ( 0 => 'OK', 1 => 'Info', diff --git a/apps/antivirus/kaspersky/snmp/mode/events.pm b/apps/antivirus/kaspersky/snmp/mode/events.pm index ed45e8c49..7bc3809b3 100644 --- a/apps/antivirus/kaspersky/snmp/mode/events.pm +++ b/apps/antivirus/kaspersky/snmp/mode/events.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Events status is '%s'", $self->{result_values}->{status}); - return $msg; + return sprintf("Events status is '%s'", $self->{result_values}->{status}); } sub custom_status_calc { @@ -48,22 +47,26 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', set => { + { + label => 'status', + type => 2, warning_default => '%{status} =~ /Warning/i', + critical_default => '%{status} =~ /Critical/i', + set => { key_values => [ { name => 'eventsStatus' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, - { label => 'events', set => { + { label => 'events', nlabel => 'events.critical.count', set => { key_values => [ { name => 'criticalEventsCount' } ], output_template => '%d critical event(s)', perfdatas => [ - { label => 'events', value => 'criticalEventsCount', template => '%d', min => 0 }, - ], + { label => 'events', template => '%d', min => 0 } + ] } - }, + } ]; } @@ -72,11 +75,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - }); + $options{options}->add_options(arguments => { + }); + return $self; } diff --git a/apps/antivirus/kaspersky/snmp/mode/fullscan.pm b/apps/antivirus/kaspersky/snmp/mode/fullscan.pm index 82e2e8ed4..bf104fa4a 100644 --- a/apps/antivirus/kaspersky/snmp/mode/fullscan.pm +++ b/apps/antivirus/kaspersky/snmp/mode/fullscan.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Full scan status is '%s'", $self->{result_values}->{status}); - return $msg; + return sprintf("Full scan status is '%s'", $self->{result_values}->{status}); } sub custom_status_calc { @@ -48,7 +47,11 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', set => { + { + label => 'status', + type => 2, warning_default => '%{status} =~ /Warning/i', + critical_default => '%{status} =~ /Critical/i', + set => { key_values => [ { name => 'fullscanStatus' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), @@ -56,14 +59,14 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold, } }, - { label => 'not-scanned', set => { + { label => 'not-scanned', nlabel => 'hosts.unscanned.count', set => { key_values => [ { name => 'hostsNotScannedLately' } ], output_template => '%d hosts(s) has not been scanned lately', perfdatas => [ - { label => 'not_scanned', value => 'hostsNotScannedLately', template => '%d', min => 0 }, - ], + { label => 'not_scanned', template => '%d', min => 0 } + ] } - }, + } ]; } @@ -72,21 +75,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - }); + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - my %map_status = ( 0 => 'OK', 1 => 'Info', diff --git a/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm b/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm index f15834ba5..59c60d761 100644 --- a/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm +++ b/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Logical network status is '%s'", $self->{result_values}->{status}); - return $msg; + return sprintf("Logical network status is '%s'", $self->{result_values}->{status}); } sub custom_status_calc { @@ -48,46 +47,51 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', set => { + { + label => 'status', + type => 2, + warning_default => '%{status} =~ /Warning/i', + critical_default => '%{status} =~ /Critical/i', + set => { key_values => [ { name => 'logicalNetworkStatus' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, - { label => 'new-hosts', set => { + { label => 'new-hosts', nlabel => 'hosts.new.count', set => { key_values => [ { name => 'hostsFound' } ], output_template => '%d new host(s) found', perfdatas => [ - { label => 'new_hosts', value => 'hostsFound', template => '%d', min => 0 }, - ], + { label => 'new_hosts', template => '%d', min => 0 } + ] } }, - { label => 'groups', set => { + { label => 'groups', nlabel => 'groups.total.count', set => { key_values => [ { name => 'groupsCount' } ], output_template => '%d group(s) on the server', perfdatas => [ - { label => 'groups', value => 'groupsCount', template => '%d', min => 0 }, - ], + { label => 'groups', template => '%d', min => 0 } + ] } }, - { label => 'not-connected-long-time', set => { + { label => 'not-connected-long-time', nlabel => 'hosts.notconnected.count', set => { key_values => [ { name => 'hostsNotConnectedLongTime' } ], output_template => '%d host(s) has not connected for a long time', perfdatas => [ - { label => 'not_connected_long_time', value => 'hostsNotConnectedLongTime', template => '%d', min => 0 }, - ], + { label => 'not_connected_long_time', template => '%d', min => 0 } + ] } }, - { label => 'not-controlled', set => { + { label => 'not-controlled', nlabel => 'hosts.uncontrolled.count', set => { key_values => [ { name => 'hostsControlLost' } ], output_template => '%d host(s) are not controlled', perfdatas => [ - { label => 'not_controlled', value => 'hostsControlLost', template => '%d', min => 0 }, - ], + { label => 'not_controlled', template => '%d', min => 0 } + ] } - }, + } ]; } @@ -96,11 +100,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - }); + $options{options}->add_options(arguments => { + }); + return $self; } @@ -166,12 +168,14 @@ Can use special variables like: %{status} =item B<--warning-*> Threshold warning. -Can be: 'new-hosts', 'groups', 'not-connected-long-time', 'not-controlled'. +Can be: 'new-hosts', 'groups', 'not-connected-long-time', +'not-controlled'. =item B<--critical-*> Threshold critical. -Can be: 'new-hosts', 'groups', 'not-connected-long-time', 'not-controlled'. +Can be: 'new-hosts', 'groups', 'not-connected-long-time', +'not-controlled'. =back diff --git a/apps/antivirus/kaspersky/snmp/mode/protection.pm b/apps/antivirus/kaspersky/snmp/mode/protection.pm index 85ca7ca95..ea1971428 100644 --- a/apps/antivirus/kaspersky/snmp/mode/protection.pm +++ b/apps/antivirus/kaspersky/snmp/mode/protection.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -48,39 +48,44 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', set => { + { + label => 'status', + type => 2, + warning_default => '%{status} =~ /Warning/i', + critical_default => '%{status} =~ /Critical/i', + set => { key_values => [ { name => 'protectionStatus' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, - { label => 'no-antivirus', set => { + { label => 'no-antivirus', nlabel => 'protection.hosts.antivirus.notrunning.count', set => { key_values => [ { name => 'hostsAntivirusNotRunning' } ], output_template => '%d host(s) without running antivirus', perfdatas => [ - { label => 'no_antivirus', value => 'hostsAntivirusNotRunning', template => '%d', min => 0 }, - ], + { label => 'no_antivirus', template => '%d', min => 0 } + ] } }, - { label => 'no-real-time', set => { + { label => 'no-real-time', nlabel => 'protection.hosts.realtime.notrunning.count', set => { key_values => [ { name => 'hostsRealtimeNotRunning' } ], output_template => '%d hosts(s) without running real time protection', perfdatas => [ - { label => 'no_real_time', value => 'hostsRealtimeNotRunning', template => '%d', min => 0 }, - ], + { label => 'no_real_time', template => '%d', min => 0 } + ] } }, - { label => 'not-acceptable-level', set => { + { label => 'not-acceptable-level', nlabel => 'protection.hosts.realtime.unacceptable.level.count', set => { key_values => [ { name => 'hostsRealtimeLevelChanged' } ], output_template => '%d host(s) with not acceptable level of real time protection', perfdatas => [ - { label => 'not_acceptable_level', value => 'hostsRealtimeLevelChanged', template => '%d', min => 0 }, - ], + { label => 'not_acceptable_level', value => 'hostsRealtimeLevelChanged', template => '%d', min => 0 } + ] } }, - { label => 'not-cured-objects', set => { + { label => 'not-cured-objects', nlabel => 'protection.hosts.uncured.objects.count', set => { key_values => [ { name => 'hostsNotCuredObject' } ], output_template => '%d host(s) with not cured objects', perfdatas => [ @@ -88,12 +93,12 @@ sub set_counters { ], } }, - { label => 'too-many-threats', set => { + { label => 'too-many-threats', nlabel => 'protection.hosts.2manythreats.count', set => { key_values => [ { name => 'hostsTooManyThreats' } ], output_template => '%d host(s) with too many threats', perfdatas => [ - { label => 'too_many_threats', value => 'hostsTooManyThreats', template => '%d', min => 0 }, - ], + { label => 'too_many_threats', template => '%d', min => 0 } + ] } }, ]; @@ -104,21 +109,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - }); + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - my %map_status = ( 0 => 'OK', 1 => 'Info', diff --git a/apps/antivirus/kaspersky/snmp/mode/updates.pm b/apps/antivirus/kaspersky/snmp/mode/updates.pm index 740cbba6b..5d0bcf7d2 100644 --- a/apps/antivirus/kaspersky/snmp/mode/updates.pm +++ b/apps/antivirus/kaspersky/snmp/mode/updates.pm @@ -26,7 +26,7 @@ use strict; use warnings; use centreon::plugins::misc; use DateTime; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -104,15 +104,20 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', set => { + { + label => 'status', + type => 2, + warning_default => '%{status} =~ /Warning/i', + critical_default => '%{status} =~ /Critical/i', + set => { key_values => [ { name => 'updatesStatus' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'last-server-update', set => { + { label => 'last-server-update', nlabel => 'update.server.freshness.seconds', set => { key_values => [ { name => 'lastServerUpdateTime' } ], closure_custom_calc => $self->can('custom_last_calc'), closure_custom_output => $self->can('custom_last_output'), @@ -120,39 +125,36 @@ sub set_counters { closure_custom_perfdata => $self->can('custom_last_perfdata') } }, - { label => 'not-updated', set => { + { label => 'not-updated', nlabel => 'update.hosts.outdated.count', set => { key_values => [ { name => 'hostsNotUpdated' } ], output_template => '%d host(s) not up to date', perfdatas => [ - { label => 'not_updated', value => 'hostsNotUpdated', template => '%d', min => 0 } + { label => 'not_updated', template => '%d', min => 0 } ] } } ]; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{tz} = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - 'timezone:s' => { name => 'timezone', default => 'GMT' } + 'timezone:s' => { name => 'timezone', default => 'GMT' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->{tz} = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - my $map_status = { 0 => 'OK', 1 => 'Info', diff --git a/apps/antivirus/kaspersky/snmp/plugin.pm b/apps/antivirus/kaspersky/snmp/plugin.pm index 370213a3d..38782846d 100644 --- a/apps/antivirus/kaspersky/snmp/plugin.pm +++ b/apps/antivirus/kaspersky/snmp/plugin.pm @@ -26,19 +26,18 @@ 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}} = ( + $self->{modes} = { 'deployment' => 'apps::antivirus::kaspersky::snmp::mode::deployment', 'events' => 'apps::antivirus::kaspersky::snmp::mode::events', 'full-scan' => 'apps::antivirus::kaspersky::snmp::mode::fullscan', 'logical-network' => 'apps::antivirus::kaspersky::snmp::mode::logicalnetwork', 'protection' => 'apps::antivirus::kaspersky::snmp::mode::protection', 'updates' => 'apps::antivirus::kaspersky::snmp::mode::updates', - ); + }; return $self; }