check_multi
check_multi copied to clipboard
Double escaping of html entities in xml format causes problems when used in a pipeline
Using check_multi in a pipeline to do multiple checks in a single call to a slow remote system
ssh remote "check_multi -f my.cmd -r 256" | check_multi -f - -r 8192+8+1
OK - 4 plugins checked, 4 ok [global_result_rating: parsing error (Evaluation error in 'COUNT(WARNING) > 0': syntax error at (eval 15) line 1, near ">" ),global_result_rating: parsing error (Evaluation error in 'COUNT(CRITICAL) > 0': syntax error at (eval 16) line 1, near ">" )]
The response causing problems is from the remote 'check_proc' command which returns the name of the process in single quotes.
Plaintext response
[ 1] proc_couchdb PROCS OK: 1 process with command name 'beam'
XML response
<output>PROCS OK: 1 process with command name &#039;beam&#039; </output>
This is my first post to github, so I am not sure of the etiquette, but I fixed the problem locally which is caused when the "&" character returned in the xml is sometimes double escaped due to the variable sorting of keys in the perl hash which is used to transform the response.
OLD
#---
#--- helper routine which encodes several XML specific characters
#---
sub xml_encode {
my $input=shift;
my %transtab=(
'\'' => ''',
'&' => '&',
'<' => '<',
'>' => '>',
'\|' => '|',
);
for (keys(%transtab)) {
$input=~s/$_/$transtab{$_}/g;
}
$input;
}
NEW working solution
#---
#--- helper routine which encodes several XML specific characters
#---
sub xml_encode {
my $input=shift;
my %transtab=(
'\'' => ''',
'<' => '<',
'>' => '>',
'\|' => '|',
);
# must encode '&' first, otherwise double encoding can happen
# hash keys() doesn't guarantee order.
$input=~s/&/&/g;
for (keys(%transtab)) {
$input=~s/$_/$transtab{$_}/g;
}
$input;
}