fix(openldap): system-usage mode - illegal division by zero (#3036)

This commit is contained in:
qgarnier 2021-08-11 11:20:22 +02:00 committed by GitHub
parent e88a1f52ef
commit d861ebe669
1 changed files with 19 additions and 19 deletions

View File

@ -27,6 +27,12 @@ use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use centreon::common::protocols::ldap::lib::ldap; use centreon::common::protocols::ldap::lib::ldap;
sub prefix_operation_output {
my ($self, %options) = @_;
return 'Operation completed ';
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -42,36 +48,35 @@ sub set_counters {
key_values => [ { name => 'operations_completed_' . $_, diff => 1 } ], key_values => [ { name => 'operations_completed_' . $_, diff => 1 } ],
output_template => $_ . ' %s', output_template => $_ . ' %s',
perfdatas => [ perfdatas => [
{ label => 'operations_' . $_, template => '%.2f', min => 0 } { template => '%.2f', min => 0 }
] ]
} }
}; };
} }
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'con-current', nlabel => 'system.connections.current.count', set => { { label => 'con-current', nlabel => 'system.connections.current.count', set => {
key_values => [ { name => 'connections_current' } ], key_values => [ { name => 'connections_current' } ],
output_template => 'Current connections %s', output_template => 'Current connections %s',
perfdatas => [ perfdatas => [
{ label => 'connections_current', template => '%s', min => 0 }, { template => '%s', min => 0 }
], ]
} }
}, },
{ label => 'con-total', nlabel => 'system.connections.total.count', set => { { label => 'con-total', nlabel => 'system.connections.total.count', set => {
key_values => [ { name => 'connections_total', diff => 1 } ], key_values => [ { name => 'connections_total', diff => 1 } ],
output_template => 'Total connections %s', output_template => 'Total connections %s',
perfdatas => [ perfdatas => [
{ label => 'connections_total', template => '%s', min => 0 }, { template => '%s', min => 0 }
], ]
} }
}, },
{ label => 'threads-active', nlabel => 'system.threads.active.percentage', set => { { label => 'threads-active', nlabel => 'system.threads.active.percentage', set => {
key_values => [ { name => 'threads_active_prct' } ], key_values => [ { name => 'threads_active_prct' } ],
output_template => 'Current active threads %.2f %%', output_template => 'Current active threads %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'threads_active', template => '%.2f', min => 0, max => 100, unit => '%' }, { template => '%.2f', min => 0, max => 100, unit => '%' }
], ]
} }
}, },
{ label => 'traffic', nlabel => 'system.traffic.bytespersecond', set => { { label => 'traffic', nlabel => 'system.traffic.bytespersecond', set => {
@ -79,19 +84,13 @@ sub set_counters {
output_template => 'traffic %s %s/s', output_template => 'traffic %s %s/s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ label => 'traffic', template => '%s', min => 0, unit => 'B/s', cast_int => 1 }, { template => '%s', min => 0, unit => 'B/s', cast_int => 1 }
] ]
} }
} }
]; ];
} }
sub prefix_operation_output {
my ($self, %options) = @_;
return 'Operation completed ';
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
@ -106,7 +105,7 @@ sub new {
'tls' => { name => 'use_tls' }, 'tls' => { name => 'use_tls' },
'username:s' => { name => 'username' }, 'username:s' => { name => 'username' },
'password:s' => { name => 'password' }, 'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout', default => '30' }, 'timeout:s' => { name => 'timeout', default => '30' }
}); });
return $self; return $self;
@ -185,7 +184,8 @@ sub manage_selection {
} }
} }
$self->{global}->{threads_active_prct} = $self->{global}->{threads_active} * 100 / $self->{global}->{threads_max}; $self->{global}->{threads_active_prct} = $self->{global}->{threads_active} * 100 / $self->{global}->{threads_max}
if (defined($self->{global}->{threads_max}) && $self->{global}->{threads_max} > 0);
$self->{cache_name} = "openldap_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' . $self->{cache_name} = "openldap_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));