fix(protocol/http): expected-content mode - fix legacy expected-string option (#3134)

This commit is contained in:
qgarnier 2021-09-23 15:18:17 +02:00 committed by GitHub
parent 9855e466d9
commit 79863cca17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -42,6 +42,7 @@ sub custom_content_output {
if (!$self->{output}->is_status(value => $self->{instance_mode}->{content_status}, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $self->{instance_mode}->{content_status}, compare => 'ok', litteral => 1)) {
my $filter = $self->{instance_mode}->{option_results}->{lc($self->{instance_mode}->{content_status}) . '-content'}; my $filter = $self->{instance_mode}->{option_results}->{lc($self->{instance_mode}->{content_status}) . '-content'};
$filter =~ s/\$values->/%/g; $filter =~ s/\$values->/%/g;
$filter =~ s/%\{expected_string\}/$self->{result_values}->{expected_string}/g;
$msg = sprintf("Content test [filter: '%s']", $filter); $msg = sprintf("Content test [filter: '%s']", $filter);
} }
@ -57,7 +58,10 @@ sub set_counters {
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'content', type => 2, set => { { label => 'content', type => 2, set => {
key_values => [ { name => 'content' }, { name => 'code' }, { name => 'first_header' }, { name => 'header' } ], key_values => [
{ name => 'content' }, { name => 'code' }, { name => 'first_header' }, { name => 'header' },
{ name => 'expected_string' }
],
closure_custom_output => $self->can('custom_content_output'), closure_custom_output => $self->can('custom_content_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_content_threshold') closure_custom_threshold_check => $self->can('custom_content_threshold')
@ -160,7 +164,7 @@ sub check_options {
# Legacy compat # Legacy compat
if (defined($options{option_results}->{expected_string}) && $options{option_results}->{expected_string} ne '') { if (defined($options{option_results}->{expected_string}) && $options{option_results}->{expected_string} ne '') {
$options{option_results}->{'critical-content'} = "%{content} !~ /$options{option_results}->{expected_string}/mi"; $options{option_results}->{'critical-content'} = "%{content} !~ /%{expected_string}/mi";
} }
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$self->load_request(); $self->load_request();
@ -181,6 +185,7 @@ sub manage_selection {
code => $self->{http}->get_code(), code => $self->{http}->get_code(),
header => $self->{http}->get_header(), header => $self->{http}->get_header(),
first_header => $self->{http}->get_first_header(), first_header => $self->{http}->get_first_header(),
expected_string => defined($self->{option_results}->{expected_string}) ? $self->{option_results}->{expected_string} : ''
}; };
if (defined($self->{option_results}->{extracted_pattern}) && $self->{option_results}->{extracted_pattern} ne '' && if (defined($self->{option_results}->{extracted_pattern}) && $self->{option_results}->{extracted_pattern} ne '' &&