enh(core): unknown custom threshold expression error (#2967)

This commit is contained in:
qgarnier 2021-07-16 09:17:29 +02:00 committed by GitHub
parent 4f98036bb9
commit 13fbbdbd53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 43 deletions

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
@ -40,6 +40,12 @@ sub custom_status_output {
);
}
sub prefix_service_output {
my ($self, %options) = @_;
return "Problem '" . $options{instance_value}->{displayName} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
@ -55,33 +61,27 @@ sub set_counters {
key_values => [ { name => 'problems_open' } ],
output_template => 'number of open problems : %s',
perfdatas => [
{ value => 'problems_open', template => '%s', value => 'problems_open', min => 0 },
],
{ template => '%s', value => 'problems_open', min => 0 }
]
}
},
}
];
$self->{maps_counters}->{problem} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'impactLevel' }, { name => 'severityLevel' },
{ label => 'status', type => 2, critical_default => '%{status} eq "OPEN"', set => {
key_values => [
{ name => 'status' }, { name => 'impactLevel' }, { name => 'severityLevel' },
{ name => 'entityName' }, { name => 'eventType' }, { name => 'entityId' }, { name => 'displayName' },
{ name => 'startTime' }, { name => 'endTime' }, { name => 'commentCount' }
{ name => 'startTime' }, { name => 'endTime' }, { name => 'commentCount' }, { name => 'time' }
],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
}
];
}
sub prefix_service_output {
my ($self, %options) = @_;
return "Problem '" . $options{instance_value}->{displayName} ."' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
@ -89,24 +89,12 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'relative-time:s' => { name => 'relative_time', default => 'min' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} eq "OPEN"' },
'relative-time:s' => { name => 'relative_time', default => 'min' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => [
'warning_status', 'critical_status', 'unknown_status',
]);
}
sub manage_selection {
my ($self, %options) = @_;
@ -116,7 +104,7 @@ sub manage_selection {
$self->{problem} = {};
$self->{problems}->{global} = { problem => {} };
my $i = 1;
my ($i, $time) = (1, time());
foreach my $item (@{$problem}) {
$self->{problems}->{global}->{problem}->{$i} = {
displayName => $item->{displayName},
@ -129,6 +117,7 @@ sub manage_selection {
startTime => $item->{startTime} / 1000,
endTime => $item->{endTime} > -1 ? $item->{endTime} / 1000 : -1,
commentCount => $item->{commentCount},
time => $time
};
if ($item->{status} eq 'OPEN') {
$self->{global}->{problems_open}++;
@ -156,17 +145,17 @@ Can use: min, 5mins, 10mins, 15mins, 30mins, hour, 2hours, 6hours, day, 3days, w
=item B<--unknown-status>
Set unknown threshold for status.
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}, %{time}
=item B<--warning-status>
Set warning threshold for status.
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}, %{time}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} eq "OPEN"').
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}, %{time}
=item B<--warning-*> B<--critical-*>

View File

@ -761,6 +761,7 @@ sub change_macros {
foreach (@{$options{macros}}) {
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$values->{$1}/g;
$self->{output}->test_eval(test => $self->{option_results}->{$_});
}
}
}

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_perfdata {
my ($self, %options) = @_;
@ -60,6 +60,7 @@ sub custom_status_calc {
foreach my $key (@{$self->{instance_mode}->{custom_keys}}) {
$self->{result_values}->{$key} = $options{new_datas}->{$self->{instance} . '_' . $key};
}
$self->{result_values}->{time} = time();
return 0;
}
@ -69,18 +70,18 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'queries_results', type => 1,
message_multiple => 'All queries results are ok', skipped_code => { -11 => 1 } },
message_multiple => 'All queries results are ok', skipped_code => { -11 => 1 } }
];
$self->{maps_counters}->{queries_results} = [
{ label => 'status', set => {
{ label => 'status', type => 2, set => {
key_values => [ { name => 'instance' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => $self->can('custom_status_perfdata'),
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
}
];
}
@ -94,9 +95,7 @@ sub new {
'instance:s' => { name => 'instance' },
'aggregation:s' => { name => 'aggregation', default => 'average' },
'output:s' => { name => 'output' },
'multiple-output:s' => { name => 'multiple_output' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
'multiple-output:s' => { name => 'multiple_output' }
});
return $self;
@ -131,8 +130,6 @@ sub check_options {
}
$self->{maps_counters_type}[0]->{message_multiple} = $self->{option_results}->{multiple_output} if (defined($self->{option_results}->{multiple_output}));
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {