(core) add alert_triggered() method for option --filter-perfdata-adv (#3935)
This commit is contained in:
parent
13f1938b3d
commit
b421d0888f
|
@ -465,6 +465,25 @@ sub expand_exponential {
|
|||
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) = @_;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue