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 ba40a60990
commit 754a783c48
6 changed files with 24 additions and 25 deletions

View File

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

View File

@ -59,7 +59,7 @@ sub new {
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options);
$self->{cache} = centreon::plugins::statefile->new(%options);
return $self;
}
@ -231,7 +231,7 @@ sub get_host_statistics {
sub cache_hosts {
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});
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');

View File

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

View File

@ -112,7 +112,7 @@ sub manage_selection {
my $read_io = {};
my $write_io = {};
if (keys $first_stat->{diskio}) {
if (defined($first_stat->{diskio})) {
$self->{containers}->{$container_id} = {
node_name => $result->{$container_id}->{NodeName},
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 warnings;
use DBD::Firebird;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }
});
return $self;
}
@ -56,13 +54,10 @@ sub check_options {
sub run {
my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT COUNT(MON$USER) FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID <> CURRENT_CONNECTION});
my $result = $self->{sql}->fetchrow_array();
$options{sql}->connect();
$options{sql}->query(query => q{SELECT COUNT(MON$USER) FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID <> CURRENT_CONNECTION});
my $result = $options{sql}->fetchrow_array();
if (!defined($result)) {
$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 $msg = sprintf("%d user(s) connect to database", $result);
$self->{output}->output_add(severity => $exit_code,
short_msg => $msg);
$self->{output}->perfdata_add(label => 'users', value => $result,
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}->output_add(
severity => $exit_code,
short_msg => $msg
);
$self->{output}->perfdata_add(
label => 'users', value => $result,
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}->exit();

View File

@ -75,7 +75,7 @@ sub set_defaults {}
sub check_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->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;