This commit is contained in:
garnier-quentin 2019-12-24 10:41:49 +01:00
parent a596b34a07
commit 8025e07287
1 changed files with 27 additions and 25 deletions

View File

@ -29,12 +29,11 @@ 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;
} }
@ -55,40 +54,43 @@ 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();
if (!($options{sql}->is_version_minimum(version => '5'))) {
if (!($self->{sql}->is_version_minimum(version => '5'))) { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $options{sql}->{version} . "' is not supported (need version >= '5.x').");
$self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x').");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{sql}->query(query => q{SHOW VARIABLES LIKE 'open_files_limit'}); $options{sql}->query(query => q{SHOW VARIABLES LIKE 'open_files_limit'});
my ($dummy, $open_files_limit) = $self->{sql}->fetchrow_array(); my ($dummy, $open_files_limit) = $options{sql}->fetchrow_array();
if (!defined($open_files_limit)) { if (!defined($open_files_limit)) {
$self->{output}->add_option_msg(short_msg => "Cannot get open files limit."); $self->{output}->add_option_msg(short_msg => "Cannot get open files limit.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Open_files'}); $options{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Open_files'});
($dummy, my $open_files) = $self->{sql}->fetchrow_array(); ($dummy, my $open_files) = $options{sql}->fetchrow_array();
if (!defined($open_files)) { if (!defined($open_files)) {
$self->{output}->add_option_msg(short_msg => "Cannot get open files."); $self->{output}->add_option_msg(short_msg => "Cannot get open files.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my $prct_open = int(100 * $open_files / $open_files_limit); my $prct_open = 100 * $open_files / $open_files_limit;
my $exit_code = $self->{perfdata}->threshold_check(value => $prct_open, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit_code = $self->{perfdata}->threshold_check(value => $prct_open, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(
short_msg => sprintf("%.2f%% of the open files limit reached (%d of max. %d)", severity => $exit_code,
$prct_open, $open_files, $open_files_limit)); short_msg => sprintf(
$self->{output}->perfdata_add(label => 'open_files', "%.2f%% of the open files limit reached (%s of max. %s)",
value => $open_files, $prct_open, $open_files, $open_files_limit
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $open_files_limit, cast_int => 1), )
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $open_files_limit, cast_int => 1), );
min => 0); $self->{output}->perfdata_add(
label => 'open_files',
value => $open_files,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $open_files_limit, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $open_files_limit, cast_int => 1),
min => 0
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();