enhance typo + use unit in thresholds (Ref #1187)
This commit is contained in:
parent
37c165e2d8
commit
0ca0d1047b
|
@ -66,7 +66,7 @@ sub windows_execute {
|
|||
}
|
||||
close TO_PARENT;
|
||||
|
||||
my $ein = "";
|
||||
my $ein = '';
|
||||
vec($ein, fileno(FROM_CHILD), 1) = 1;
|
||||
$job->watch(
|
||||
sub {
|
||||
|
@ -96,7 +96,7 @@ sub windows_execute {
|
|||
close FROM_CHILD;
|
||||
|
||||
if ($ended == 0) {
|
||||
$options{output}->add_option_msg(short_msg => "Command too long to execute (timeout)...");
|
||||
$options{output}->add_option_msg(short_msg => 'Command too long to execute (timeout)...');
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
chomp $stdout;
|
||||
|
@ -152,7 +152,7 @@ sub unix_execute {
|
|||
$sub_cmd .= $options{command_options} if (defined($options{command_options}));
|
||||
# On some equipment. Cannot get a pseudo terminal
|
||||
if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) {
|
||||
$cmd = "echo '" . $sub_cmd . "' | " . $cmd . ' ' . join(" ", @$args);
|
||||
$cmd = "echo '" . $sub_cmd . "' | " . $cmd . ' ' . join(' ', @$args);
|
||||
($lerror, $stdout, $exit_code) = backtick(
|
||||
command => $cmd,
|
||||
timeout => $options{options}->{timeout},
|
||||
|
@ -210,7 +210,7 @@ sub unix_execute {
|
|||
sub mymodule_load {
|
||||
my (%options) = @_;
|
||||
my $file;
|
||||
($file = ($options{module} =~ /\.pm$/ ? $options{module} : $options{module} . ".pm")) =~ s{::}{/}g;
|
||||
($file = ($options{module} =~ /\.pm$/ ? $options{module} : $options{module} . '.pm')) =~ s{::}{/}g;
|
||||
|
||||
eval {
|
||||
local $SIG{__DIE__} = 'IGNORE';
|
||||
|
@ -274,7 +274,7 @@ sub backtick {
|
|||
}
|
||||
|
||||
alarm(0);
|
||||
return (-1000, "Command too long to execute (timeout)...", -1);
|
||||
return (-1000, 'Command too long to execute (timeout)...', -1);
|
||||
} else {
|
||||
if ($arg{wait_exit} == 1) {
|
||||
# We're waiting the exit code
|
||||
|
@ -291,7 +291,7 @@ sub backtick {
|
|||
setpgrp( 0, 0 );
|
||||
|
||||
if ($arg{redirect_stderr} == 1) {
|
||||
open STDERR, ">&STDOUT";
|
||||
open STDERR, '>&STDOUT';
|
||||
}
|
||||
if (scalar(@{$arg{arguments}}) <= 0) {
|
||||
exec($arg{command});
|
||||
|
@ -320,7 +320,7 @@ sub powershell_encoded {
|
|||
|
||||
require Encode;
|
||||
require MIME::Base64;
|
||||
my $bytes = Encode::encode("utf16LE", $value);
|
||||
my $bytes = Encode::encode('utf16LE', $value);
|
||||
my $script = MIME::Base64::encode_base64($bytes, "\n");
|
||||
$script =~ s/\n//g;
|
||||
return $script;
|
||||
|
@ -374,13 +374,13 @@ sub change_seconds {
|
|||
my %options = @_;
|
||||
my ($str, $str_append) = ('', '');
|
||||
my $periods = [
|
||||
{ unit => 'y', value => 31556926 },
|
||||
{ unit => 'M', value => 2629743 },
|
||||
{ unit => 'w', value => 604800 },
|
||||
{ unit => 'd', value => 86400 },
|
||||
{ unit => 'h', value => 3600 },
|
||||
{ unit => 'm', value => 60 },
|
||||
{ unit => 's', value => 1 },
|
||||
{ unit => 'y', value => 31556926 },
|
||||
{ unit => 'M', value => 2629743 },
|
||||
{ unit => 'w', value => 604800 },
|
||||
{ unit => 'd', value => 86400 },
|
||||
{ unit => 'h', value => 3600 },
|
||||
{ unit => 'm', value => 60 },
|
||||
{ unit => 's', value => 1 },
|
||||
];
|
||||
my %values = ('y' => 1, 'M' => 2, 'w' => 3, 'd' => 4, 'h' => 5, 'm' => 6, 's' => 7);
|
||||
|
||||
|
@ -462,12 +462,26 @@ sub parse_threshold {
|
|||
my $perf_result = { arobase => 0, infinite_neg => 0, infinite_pos => 0, start => '', end => '' };
|
||||
|
||||
my $global_status = 1;
|
||||
if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?)?$/) {
|
||||
if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?(?:[KMGTPE][bB])?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?(?:[KMGTPE][bB])?)?$/) {
|
||||
$perf_result->{start} = $2 if (defined($2));
|
||||
$perf_result->{end} = $3 if (defined($3));
|
||||
$perf_result->{arobase} = 1 if (defined($1) && $1 eq '@');
|
||||
$perf_result->{start} =~ s/[\+:]//g;
|
||||
$perf_result->{end} =~ s/\+//;
|
||||
if ($perf_result->{start} =~ s/([KMGTPE])([bB])//) {
|
||||
$perf_result->{start} = scale_bytesbit(
|
||||
value => $perf_result->{start},
|
||||
src_unit => $2, dst_unit => $2,
|
||||
src_quantity => $1, dst_quantity => '',
|
||||
);
|
||||
}
|
||||
if ($perf_result->{end} =~ s/([KMGTPE])([bB])//) {
|
||||
$perf_result->{end} = scale_bytesbit(
|
||||
value => $perf_result->{end},
|
||||
src_unit => $2, dst_unit => $2,
|
||||
src_quantity => $1, dst_quantity => '',
|
||||
);
|
||||
}
|
||||
if ($perf_result->{end} eq '') {
|
||||
$perf_result->{end} = 1e500;
|
||||
$perf_result->{infinite_pos} = 1;
|
||||
|
@ -490,10 +504,10 @@ sub parse_threshold {
|
|||
sub get_threshold_litteral {
|
||||
my (%options) = @_;
|
||||
|
||||
my $perf_output = ($options{arobase} == 1 ? "@" : "") .
|
||||
(($options{infinite_neg} == 0) ? $options{start} : "~") .
|
||||
":" .
|
||||
(($options{infinite_pos} == 0) ? $options{end} : "");
|
||||
my $perf_output = ($options{arobase} == 1 ? '@' : '') .
|
||||
(($options{infinite_neg} == 0) ? $options{start} : '~') .
|
||||
':' .
|
||||
(($options{infinite_pos} == 0) ? $options{end} : '');
|
||||
return $perf_output;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,10 +66,10 @@ sub get_perfdata_for_output {
|
|||
$perf_value{start} = int($perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int}) && $options{cast_int} == 1);
|
||||
$perf_value{end} = int($perf_value{end}) if ($perf_value{infinite_pos} == 0 && defined($options{cast_int}) && $options{cast_int} == 1);
|
||||
|
||||
my $perf_output = ($perf_value{arobase} == 1 ? "@" : "") .
|
||||
(($perf_value{infinite_neg} == 0) ? $perf_value{start} : "~") .
|
||||
":" .
|
||||
(($perf_value{infinite_pos} == 0) ? $perf_value{end} : "");
|
||||
my $perf_output = ($perf_value{arobase} == 1 ? '@' : '') .
|
||||
(($perf_value{infinite_neg} == 0) ? $perf_value{start} : '~') .
|
||||
':' .
|
||||
(($perf_value{infinite_pos} == 0) ? $perf_value{end} : '');
|
||||
|
||||
return $perf_output;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ sub change_bytes {
|
|||
$value = $value / $divide;
|
||||
}
|
||||
|
||||
return (sprintf("%.2f", $sign . $value), $unit . (defined($options{network}) ? 'b' : 'B'));
|
||||
return (sprintf('%.2f', $sign . $value), $unit . (defined($options{network}) ? 'b' : 'B'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -146,13 +146,13 @@ sub display_local_help {
|
|||
open STDOUT, '>', \$stdout;
|
||||
|
||||
if ($alternative_fatpacker == 0) {
|
||||
pod2usage(-exitval => "NOEXIT", -input => pod_where({-inc => 1}, __PACKAGE__));
|
||||
pod2usage(-exitval => 'NOEXIT', -input => pod_where({-inc => 1}, __PACKAGE__));
|
||||
} else {
|
||||
my $pp = __PACKAGE__ . ".pm";
|
||||
my $pp = __PACKAGE__ . '.pm';
|
||||
$pp =~ s{::}{/}g;
|
||||
my $content_class = $INC{$pp}->{$pp};
|
||||
open my $str_fh, '<', \$content_class;
|
||||
pod2usage(-exitval => "NOEXIT", -input => $str_fh);
|
||||
pod2usage(-exitval => 'NOEXIT', -input => $str_fh);
|
||||
close $str_fh;
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ sub check_directory {
|
|||
|
||||
opendir(my $dh, $directory) || return ;
|
||||
while (my $filename = readdir $dh) {
|
||||
$self->check_directory($directory . "/" . $filename) if ($filename !~ /^\./ && -d $directory . "/" . $filename);
|
||||
$self->check_directory($directory . '/' . $filename) if ($filename !~ /^\./ && -d $directory . '/' . $filename);
|
||||
if ($filename eq 'plugin.pm') {
|
||||
my $stdout = '';
|
||||
|
||||
|
@ -202,7 +202,7 @@ sub check_plugin_option {
|
|||
my ($self) = @_;
|
||||
|
||||
if (defined($self->{version})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Global Version: " . $global_version);
|
||||
$self->{output}->add_option_msg(short_msg => 'Global Version: ' . $global_version);
|
||||
$self->{output}->option_exit(nolabel => 1);
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ sub display_list_plugin {
|
|||
foreach my $key (@$integrated_plugins) {
|
||||
# Need to load it to get the description
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $key,
|
||||
error_msg => "Cannot load module --plugin.");
|
||||
error_msg => 'Cannot load module --plugin.');
|
||||
|
||||
my $name = $key;
|
||||
$name =~ s/\.pm//g;
|
||||
|
@ -244,7 +244,7 @@ sub display_list_plugin {
|
|||
open STDOUT, '>', \$stdout;
|
||||
my $content_class = $INC{$key}->{$key};
|
||||
open my $str_fh, '<', \$content_class;
|
||||
pod2usage(-exitval => "NOEXIT", -input => $str_fh, -verbose => 99, -sections => "PLUGIN DESCRIPTION");
|
||||
pod2usage(-exitval => 'NOEXIT', -input => $str_fh, -verbose => 99, -sections => 'PLUGIN DESCRIPTION');
|
||||
close $str_fh;
|
||||
$self->{output}->add_option_msg(long_msg => $stdout);
|
||||
}
|
||||
|
@ -302,15 +302,16 @@ sub check_relaunch {
|
|||
|
||||
if ($need_restart == 1) {
|
||||
if (scalar(@args) <= 0) {
|
||||
unshift @args, @ARGV, "--plugin=" . $self->{plugin}
|
||||
unshift @args, @ARGV, '--plugin=' . $self->{plugin}
|
||||
}
|
||||
|
||||
my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
|
||||
command => $cmd,
|
||||
arguments => [@args],
|
||||
timeout => 30,
|
||||
wait_exit => 1
|
||||
);
|
||||
command => $cmd,
|
||||
arguments => [@args],
|
||||
timeout => 30,
|
||||
wait_exit => 1
|
||||
);
|
||||
|
||||
if ($exit_code <= -1000) {
|
||||
if ($exit_code == -1000) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
|
@ -351,7 +352,7 @@ sub run {
|
|||
|
||||
(undef, $self->{plugin}) =
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin},
|
||||
error_msg => "Cannot load module --plugin.");
|
||||
error_msg => 'Cannot load module --plugin.');
|
||||
my $plugin = $self->{plugin}->new(options => $self->{options}, output => $self->{output});
|
||||
$plugin->init(help => $self->{help},
|
||||
version => $self->{version});
|
||||
|
|
Loading…
Reference in New Issue