fix(errors): from check_plugins.pl script (#3336)

This commit is contained in:
qgarnier 2021-12-22 11:59:18 +01:00 committed by GitHub
parent e2d40f4c0f
commit 30a51a32b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 25 deletions

View File

@ -118,7 +118,7 @@ sub set_counters {
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'total', nlabel = 'jobs.total.count', set => { { label => 'total', nlabel => 'jobs.total.count', set => {
key_values => [ { name => 'total' } ], key_values => [ { name => 'total' } ],
output_template => 'total jobs : %s', output_template => 'total jobs : %s',
perfdatas => [ perfdatas => [

View File

@ -59,7 +59,7 @@ sub new {
$self->{output} = $options{output}; $self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options); $self->{http} = centreon::plugins::http->new(%options);
$self->{cache} = centreon::plugins::statefile->new(%options); $self->{cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
} }
@ -231,7 +231,7 @@ sub get_host_statistics {
sub cache_hosts { sub cache_hosts {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{cache_hosts} = centreon::plugins::statefile->new(%options); $self->{cache_hosts} = centreon::plugins::statefile->new(output => $self->{output});
$self->{cache_hosts}->check_options(option_results => $self->{option_results}); $self->{cache_hosts}->check_options(option_results => $self->{option_results});
my $has_cache_file = $self->{cache_hosts}->read(statefile => 'cache_ovirt_hosts_' . md5_hex($self->{hostname}) . '_' . md5_hex($self->{api_username})); my $has_cache_file = $self->{cache_hosts}->read(statefile => 'cache_ovirt_hosts_' . md5_hex($self->{hostname}) . '_' . md5_hex($self->{api_username}));
my $timestamp_cache = $self->{cache_hosts}->get(name => 'last_timestamp'); my $timestamp_cache = $self->{cache_hosts}->get(name => 'last_timestamp');

View File

@ -82,7 +82,7 @@ sub check {
$checked++; $checked++;
my $status = 'ok' my $status = 'ok';
if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' && if (defined($self->{option_results}->{critical}) && $self->{option_results}->{critical} ne '' &&
$self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) { $self->{output}->test_eval(test => $self->{option_results}->{critical}, values => $self->{data})) {
$status = 'critical'; $status = 'critical';

View File

@ -112,7 +112,7 @@ sub manage_selection {
my $read_io = {}; my $read_io = {};
my $write_io = {}; my $write_io = {};
if (keys $first_stat->{diskio}) { if (defined($first_stat->{diskio})) {
$self->{containers}->{$container_id} = { $self->{containers}->{$container_id} = {
node_name => $result->{$container_id}->{NodeName}, node_name => $result->{$container_id}->{NodeName},
display => defined($self->{option_results}->{use_name}) ? $name : $container_id, display => defined($self->{option_results}->{use_name}) ? $name : $container_id,

View File

@ -24,18 +24,16 @@ use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use DBD::Firebird;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' }
"critical:s" => { name => 'critical', }, });
});
return $self; return $self;
} }
@ -56,13 +54,10 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql};
$self->{sql}->connect(); $options{sql}->connect();
$options{sql}->query(query => q{SELECT COUNT(MON$USER) FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID <> CURRENT_CONNECTION});
$self->{sql}->query(query => q{SELECT COUNT(MON$USER) FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID <> CURRENT_CONNECTION}); my $result = $options{sql}->fetchrow_array();
my $result = $self->{sql}->fetchrow_array();
if (!defined($result)) { if (!defined($result)) {
$self->{output}->add_option_msg(short_msg => "Cannot get users."); $self->{output}->add_option_msg(short_msg => "Cannot get users.");
@ -72,13 +67,17 @@ sub run {
my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $msg = sprintf("%d user(s) connect to database", $result); my $msg = sprintf("%d user(s) connect to database", $result);
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(
short_msg => $msg); severity => $exit_code,
$self->{output}->perfdata_add(label => 'users', value => $result, short_msg => $msg
nlabel => 'users.count', );
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), $self->{output}->perfdata_add(
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), label => 'users', value => $result,
min => 0); nlabel => 'users.count',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();

View File

@ -75,7 +75,7 @@ sub set_defaults {}
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;