diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm index 52eac55d0..3e15758a8 100644 --- a/centreon/plugins/perfdata.pm +++ b/centreon/plugins/perfdata.pm @@ -71,12 +71,12 @@ sub get_perfdata_for_output { if (defined($options{total})) { $perf_value{start} = $perf_value{start} * $options{total} / 100 if ($perf_value{infinite_neg} == 0); $perf_value{end} = $perf_value{end} * $options{total} / 100 if ($perf_value{infinite_pos} == 0); - $perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && !defined($options{cast_int})); - $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && !defined($options{cast_int})); + $perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && (!defined($options{cast_int}) || $options{cast_int} != 1)); + $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && (!defined($options{cast_int}) || $options{cast_int} != 1)); } - $perf_value{start} = sprintf("%d", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int})); - $perf_value{end} = sprintf("%d", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && defined($options{cast_int})); + $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} : "~") . diff --git a/centreon/plugins/values.pm b/centreon/plugins/values.pm index ddba7274f..9b4d7bf3d 100644 --- a/centreon/plugins/values.pm +++ b/centreon/plugins/values.pm @@ -181,6 +181,7 @@ sub perfdata { my $warn = defined($self->{threshold_warn}) ? $self->{threshold_warn} : 'warning-' . $self->{label}; my $crit = defined($self->{threshold_crit}) ? $self->{threshold_crit} : 'critical-' . $self->{label}; + my $cast_int = defined($options{cast_int}) ? $options{cast_int} : 0; foreach my $perf (@{$self->{perfdatas}}) { my ($label, $extra_label, $min, $max, $th_total) = ($self->{label}, ''); @@ -209,9 +210,9 @@ sub perfdata { } $self->{output}->perfdata_add(label => $label . $extra_label, unit => $perf->{unit}, - value => sprintf($template, $self->{result_values}->{$perf->{value}}), - warning => $self->{perfdata}->get_perfdata_for_output(label => $warn, total => $th_total), - critical => $self->{perfdata}->get_perfdata_for_output(label => $crit, total => $th_total), + value => $cast_int == 1 ? int($self->{result_values}->{$perf->{value}}) : sprintf($template, $self->{result_values}->{$perf->{value}}), + warning => $self->{perfdata}->get_perfdata_for_output(label => $warn, total => $th_total, cast_int => $cast_int), + critical => $self->{perfdata}->get_perfdata_for_output(label => $crit, total => $th_total, cast_int => $cast_int), min => $min, max => $max); } } diff --git a/database/mssql/mode/databasessize.pm b/database/mssql/mode/databasessize.pm index b249cc830..4883ab55e 100644 --- a/database/mssql/mode/databasessize.pm +++ b/database/mssql/mode/databasessize.pm @@ -104,18 +104,18 @@ sub run { my ($use_value, $use_unit) = $self->{perfdata}->change_bytes(value => $use); $self->{output}->output_add(long_msg => sprintf("DB '%s' Size: %s Used: %.2f %s (%.2f%%) Free: %s (%.2f%%)", $database, $size_brut, $use_value, $use_unit, $percent_use, $free_brut, $percent_free)); if (defined($self->{option_results}->{free})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $percent_free, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $percent_free, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("DB '%s' Size: %s Free: %s (%.2f%%)", $database, $size_brut, $free_brut, $percent_use)); } $self->{output}->perfdata_add(label => sprintf("db_%s_free",$database), unit => 'B', - value => sprintf("%d",$free), + value => int($free), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), min => 0, - max => sprintf("%d",$size)); + max => int($size)); } else { my $exit_code = $self->{perfdata}->threshold_check(value => $percent_use, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { @@ -124,11 +124,11 @@ sub run { } $self->{output}->perfdata_add(label => sprintf("db_%s_used",$database), unit => 'B', - value => sprintf("%d",$use), + value => int($use), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), min => 0, - max => sprintf("%d",$size)); + max => int($size)); } } } diff --git a/database/mysql/mode/databasessize.pm b/database/mysql/mode/databasessize.pm index 50fad0583..a397f2922 100644 --- a/database/mysql/mode/databasessize.pm +++ b/database/mysql/mode/databasessize.pm @@ -92,13 +92,13 @@ sub run { next if (defined($self->{option_results}->{filter}) && $$row[0] !~ /$self->{option_results}->{filter}/); - my $exit_code = $self->{perfdata}->threshold_check(value => $$row[1], threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $$row[1], threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($value, $value_unit) = $self->{perfdata}->change_bytes(value => $$row[1]); - $self->{output}->output_add(long_msg => sprintf("DB '" . $$row[0] . "' size: %.3f%s", $value, $value_unit)); + $self->{output}->output_add(long_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit)); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("DB '" . $$row[0] . "' size: %.3f%s", $value, $value_unit)); + short_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit)); } $self->{output}->perfdata_add(label => $$row[0] . '_size', value => $$row[1], diff --git a/database/mysql/mode/queries.pm b/database/mysql/mode/queries.pm index a5a19a452..723e64f1a 100644 --- a/database/mysql/mode/queries.pm +++ b/database/mysql/mode/queries.pm @@ -114,9 +114,9 @@ sub run { next; } - my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Total requests = %d.", $value)); + short_msg => sprintf("Total requests = %s", $value)); $self->{output}->perfdata_add(label => 'total_requests', value => $value, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), diff --git a/database/postgres/mode/tablespace.pm b/database/postgres/mode/tablespace.pm index 636295aad..1c65cb797 100644 --- a/database/postgres/mode/tablespace.pm +++ b/database/postgres/mode/tablespace.pm @@ -89,7 +89,7 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($value, $value_unit) = $self->{perfdata}->change_bytes(value => $result); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf('Tablespace "%s" size is %d %s',$self->{option_results}->{tablespace}, $value, $value_unit)); + short_msg => sprintf('Tablespace "%s" size is %s %s',$self->{option_results}->{tablespace}, $value, $value_unit)); $self->{output}->perfdata_add(label => $self->{option_results}->{tablespace}, value => $result, diff --git a/database/postgres/mode/vacuum.pm b/database/postgres/mode/vacuum.pm index 754adc888..7e362d047 100644 --- a/database/postgres/mode/vacuum.pm +++ b/database/postgres/mode/vacuum.pm @@ -67,6 +67,10 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } + if (($self->{perfdata}->threshold_validate(label => 'dbname', value => $self->{option_results}->{dbname})) eq 'postgres') { + $self->{output}->add_option_msg(short_msg => "Invalid db."); + $self->{output}->option_exit(); + } } @@ -85,6 +89,9 @@ sub run { if ($1 eq 'postgres') { $self->{output}->add_option_msg(short_msg => "Cannot use system 'postgres' database ; you must use a real database."); $self->{output}->option_exit(); + } elsif ($1 eq '') { + $self->{output}->add_option_msg(short_msg => "Database must be specified."); + $self->{output}->option_exit(); } } else { $self->{output}->add_option_msg(short_msg => "Need to specify database argument."); diff --git a/network/citrix/netscaler/common/mode/memory.pm b/network/citrix/netscaler/common/mode/memory.pm index c5eb78a21..0e035c312 100644 --- a/network/citrix/netscaler/common/mode/memory.pm +++ b/network/citrix/netscaler/common/mode/memory.pm @@ -83,7 +83,7 @@ sub run { my $free = $total_size - $used; my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_resMemUsage}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used); @@ -96,7 +96,7 @@ sub run { $free_value . " " . $free_unit, (100 - $result->{$oid_resMemUsage}))); $self->{output}->perfdata_add(label => "used", unit => 'B', - value => sprintf("%d", $used), + value => int($used), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), min => 0, max => $total_size); diff --git a/network/citrix/netscaler/common/mode/storage.pm b/network/citrix/netscaler/common/mode/storage.pm index 2c96cec8e..f78339b86 100644 --- a/network/citrix/netscaler/common/mode/storage.pm +++ b/network/citrix/netscaler/common/mode/storage.pm @@ -91,7 +91,7 @@ sub run { my $prct_used = $total_used * 100 / $total_size; my $prct_free = 100 - $prct_used; - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $total_free); diff --git a/network/juniper/common/junos/mode/memoryforwarding.pm b/network/juniper/common/junos/mode/memoryforwarding.pm index 49c1837fc..d5a8d1038 100644 --- a/network/juniper/common/junos/mode/memoryforwarding.pm +++ b/network/juniper/common/junos/mode/memoryforwarding.pm @@ -89,7 +89,7 @@ sub run { my $mem_usage = $result2->{$oid_jnxJsSPUMonitoringMemoryUsage . '.' . $instance}; my $exit_code = $self->{perfdata}->threshold_check(value => $mem_usage, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("Memory '%d' usage is: %s%%", $instance, $mem_usage)); $self->{output}->perfdata_add(label => 'mem_' . $instance, unit => '%', diff --git a/os/aix/snmp/mode/swap.pm b/os/aix/snmp/mode/swap.pm index 3faa600c6..217c1f4b2 100644 --- a/os/aix/snmp/mode/swap.pm +++ b/os/aix/snmp/mode/swap.pm @@ -132,16 +132,16 @@ sub run { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $swap_total); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $swap_total - $total_used); - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%d%%)", $swap_name, + short_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $swap_name, $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $total_used * 100 / $swap_total, $total_free_value . " " . $total_free_unit, 100 - ($total_used * 100 / $results->{$aix_swap_pool}->{$aix_swap_total . "." . $_}))); } - $self->{output}->output_add(long_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%d%%)", $swap_name, + $self->{output}->output_add(long_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $swap_name, $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $total_used * 100 / $swap_total, $total_free_value . " " . $total_free_unit, 100 - ($total_used * 100 / $swap_total))); diff --git a/os/linux/local/mode/filessize.pm b/os/linux/local/mode/filessize.pm index 3e1dd3431..a31a78fdb 100644 --- a/os/linux/local/mode/filessize.pm +++ b/os/linux/local/mode/filessize.pm @@ -138,12 +138,12 @@ sub run { $total_size += $size; my $exit_code = $self->{perfdata}->threshold_check(value => $size, - threshold => [ { label => 'critical_one', 'exit_litteral' => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical_one', exit_litteral => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ]); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $size); $self->{output}->output_add(long_msg => sprintf("%s: %s", $name, $size_value . ' ' . $size_unit)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("'%d' size is %s", $name, $size_value . ' ' . $size_unit)); + short_msg => sprintf("'%s' size is %s", $name, $size_value . ' ' . $size_unit)); } $self->{output}->perfdata_add(label => $name, unit => 'B', value => $size, @@ -154,7 +154,7 @@ sub run { # Total Size my $exit_code = $self->{perfdata}->threshold_check(value => $total_size, - threshold => [ { label => 'critical_total', 'exit_litteral' => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical_total', exit_litteral => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $total_size); $self->{output}->output_add(long_msg => sprintf("Total: %s", $size_value . ' ' . $size_unit)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { diff --git a/snmp_standard/mode/storage.pm b/snmp_standard/mode/storage.pm index e34511d10..8f06c90cf 100644 --- a/snmp_standard/mode/storage.pm +++ b/snmp_standard/mode/storage.pm @@ -183,8 +183,8 @@ sub run { # in bytes hrStorageAllocationUnits my $total_size = $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}; if ($total_size <= 0) { - $self->{output}->add_option_msg(long_msg => sprintf("Skipping storage '%d': total size is <= 0 (%d)", - $name_storage, $total_size)); + $self->{output}->add_option_msg(long_msg => sprintf("Skipping storage '%d': total size is <= 0 (%s)", + $name_storage, int($total_size))); next; } @@ -247,7 +247,7 @@ sub run { value => $value_perf, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), - min => 0, max => sprintf("%d", $total_size - $reserved_value)); + min => 0, max => int($total_size - $reserved_value)); } if ($num_disk_check == 0) { diff --git a/storage/emc/DataDomain/mode/filesystem.pm b/storage/emc/DataDomain/mode/filesystem.pm index 91a35bbe4..b454d2068 100644 --- a/storage/emc/DataDomain/mode/filesystem.pm +++ b/storage/emc/DataDomain/mode/filesystem.pm @@ -57,7 +57,7 @@ my $maps_counters = { threshold_use => 'used_prct', output_error_template => '%s', perfdatas => [ - { value => 'used', label => 'used', template => '%d', + { value => 'used', label => 'used', cast_int => 1, unit => 'B', min => 0, max => 'total', threshold_total => 'total', label_extra_instance => 1, instance_use => 'display' }, ], diff --git a/storage/qnap/snmp/mode/memory.pm b/storage/qnap/snmp/mode/memory.pm index 01ebd4b2a..fbdbceed9 100644 --- a/storage/qnap/snmp/mode/memory.pm +++ b/storage/qnap/snmp/mode/memory.pm @@ -106,7 +106,7 @@ sub run { my $prct_used = $memory_used * 100 / $total_size; my $prct_free = 100 - $prct_used; - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used); my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); @@ -118,10 +118,10 @@ sub run { $free_value . " " . $free_unit, $prct_free)); $self->{output}->perfdata_add(label => "used", - value => sprintf("%d", $memory_used), + value => int($memory_used), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), - min => 0, max => sprintf("%d", $total_size)); + min => 0, max => int($total_size)); $self->{output}->display(); $self->{output}->exit();