Fix #1781
This commit is contained in:
parent
a596b34a07
commit
8025e07287
|
@ -29,12 +29,11 @@ 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;
|
||||
}
|
||||
|
@ -55,40 +54,43 @@ sub check_options {
|
|||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '5'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x').");
|
||||
$options{sql}->connect();
|
||||
if (!($options{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}->option_exit();
|
||||
}
|
||||
|
||||
$self->{sql}->query(query => q{SHOW VARIABLES LIKE 'open_files_limit'});
|
||||
my ($dummy, $open_files_limit) = $self->{sql}->fetchrow_array();
|
||||
$options{sql}->query(query => q{SHOW VARIABLES LIKE 'open_files_limit'});
|
||||
my ($dummy, $open_files_limit) = $options{sql}->fetchrow_array();
|
||||
if (!defined($open_files_limit)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get open files limit.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Open_files'});
|
||||
($dummy, my $open_files) = $self->{sql}->fetchrow_array();
|
||||
$options{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Open_files'});
|
||||
($dummy, my $open_files) = $options{sql}->fetchrow_array();
|
||||
if (!defined($open_files)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get open files.");
|
||||
$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' } ]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("%.2f%% of the open files limit reached (%d of max. %d)",
|
||||
$prct_open, $open_files, $open_files_limit));
|
||||
$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}->output_add(
|
||||
severity => $exit_code,
|
||||
short_msg => sprintf(
|
||||
"%.2f%% of the open files limit reached (%s of max. %s)",
|
||||
$prct_open, $open_files, $open_files_limit
|
||||
)
|
||||
);
|
||||
$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}->exit();
|
||||
|
|
Loading…
Reference in New Issue