(core) add alert_triggered() method for option --filter-perfdata-adv (#3935)
This commit is contained in:
parent
13f1938b3d
commit
b421d0888f
|
@ -458,13 +458,32 @@ sub convert_fahrenheit {
|
|||
|
||||
sub expand_exponential {
|
||||
my (%options) = @_;
|
||||
|
||||
|
||||
return $options{value} unless ($options{value} =~ /^(.*)e([-+]?)(.*)$/);
|
||||
my ($num, $sign, $exp) = ($1, $2, $3);
|
||||
my $sig = $sign eq '-' ? "." . ($exp - 1 + length $num) : '';
|
||||
return sprintf("%${sig}f", $options{value});
|
||||
}
|
||||
|
||||
sub alert_triggered {
|
||||
my (%options) = @_;
|
||||
|
||||
my ($rv_warn, $warning) = parse_threshold(threshold => $options{warning});
|
||||
my ($rv_crit, $critical) = parse_threshold(threshold => $options{critical});
|
||||
|
||||
foreach ([$rv_warn, $warning], [$rv_crit, $critical]) {
|
||||
next if ($_->[0] == 0);
|
||||
|
||||
if ($_->[1]->{arobase} == 0 && ($options{value} < $_->[1]->{start} || $options{value} > $_->[1]->{end})) {
|
||||
return 1;
|
||||
} elsif ($_->[1]->{arobase} == 1 && ($options{value} >= $_->[1]->{start} && $options{value} <= $_->[1]->{end})) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub parse_threshold {
|
||||
my (%options) = @_;
|
||||
|
||||
|
@ -513,19 +532,19 @@ 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} : '');
|
||||
(($options{infinite_neg} == 0) ? $options{start} : '~') .
|
||||
':' .
|
||||
(($options{infinite_pos} == 0) ? $options{end} : '');
|
||||
return $perf_output;
|
||||
}
|
||||
|
||||
sub set_timezone {
|
||||
my (%options) = @_;
|
||||
|
||||
|
||||
return {} if (!defined($options{name}) || $options{name} eq '');
|
||||
|
||||
|
||||
centreon::plugins::misc::mymodule_load(
|
||||
output => $options{output}, module => 'DateTime::TimeZone',
|
||||
error_msg => "Cannot load module 'DateTime::TimeZone'."
|
||||
|
@ -533,7 +552,7 @@ sub set_timezone {
|
|||
if (DateTime::TimeZone->is_valid_name($options{name})) {
|
||||
return { time_zone => DateTime::TimeZone->new(name => $options{name}) };
|
||||
}
|
||||
|
||||
|
||||
# try to manage syntax (:Pacific/Noumea for example)
|
||||
if ($options{name} =~ /^:(.*)$/ && DateTime::TimeZone->is_valid_name($1)) {
|
||||
return { time_zone => DateTime::TimeZone->new(name => $1) };
|
||||
|
|
|
@ -154,6 +154,7 @@ sub check_options {
|
|||
if (defined($self->{option_results}->{filter_perfdata_adv}) && $self->{option_results}->{filter_perfdata_adv} ne '') {
|
||||
$self->{option_results}->{filter_perfdata_adv} =~ s/%\{(.*?)\}/\$values->{$1}/g;
|
||||
$self->{option_results}->{filter_perfdata_adv} =~ s/%\((.*?)\)/\$values->{$1}/g;
|
||||
$self->{option_results}->{filter_perfdata_adv} =~ s/alert_triggered\(\)/alert_triggered\(%\$values\)/g;
|
||||
}
|
||||
|
||||
$self->load_perfdata_extend_args();
|
||||
|
@ -956,6 +957,7 @@ sub load_eval {
|
|||
$self->{safe} = Safe->new();
|
||||
$self->{safe}->share('$values');
|
||||
$self->{safe}->share('$assign_var');
|
||||
$self->{safe}->share_from('centreon::plugins::misc', ['alert_triggered']);
|
||||
}
|
||||
|
||||
$self->{safe_test} = 1;
|
||||
|
|
|
@ -110,7 +110,7 @@ sub threshold_check {
|
|||
if ($options{value} =~ /[.,]/) {
|
||||
$options{value} = sprintf("%.$self->{output}->{option_results}->{float_precision}f", $options{value});
|
||||
}
|
||||
|
||||
|
||||
foreach (@{$options{threshold}}) {
|
||||
next if (!defined($self->{threshold_label}->{$_->{label}}));
|
||||
next if (!defined($self->{threshold_label}->{$_->{label}}->{value}) || $self->{threshold_label}->{$_->{label}}->{value} eq '');
|
||||
|
|
Loading…
Reference in New Issue