centreon / centreon-plugins

Collection of standard plugins to discover and gather cloud-to-edge metrics and status across your whole IT infrastructure.
https://www.centreon.com
Apache License 2.0
310 stars 274 forks source link

apps-nmap-cli mode discovery fails decoding xml when nmap returns warning in output #4305

Closed rmorandell-pgum closed 1 year ago

rmorandell-pgum commented 1 year ago

Command:

perl apps-nmap-cli.pl --plugin=apps::nmap::cli::plugin --mode=discovery --subnet='x.x.x.x/24' --timeout=900 --prettify

Error:

UNKNOWN: Cannot decode xml response: not well-formed (invalid token) at line 151, column 115, byte 5368 at /usr/lib64/perl5/vendor_perl/XML/Parser.pm line 187. XML::Simple called at apps-nmap-cli.pl line 105.

I changed the plugin writing out the output of the nmap cmd to file before the plugin parses the output. The problem is that in the nmap output i find this lines in "non xml format"

<hosthint><status state="up" reason="unknown-response" reason_ttl="0"/>
<address addr="xx.xx.xx.227" addrtype="ipv4"/>
<hostnames>
</hostnames>
</hosthint>
sendto in send_ip_packet_sd: sendto(4, packet, 60, 0, xx.xx.xx.58, 16) => Operation not permitted
Offending packet: TCP 192.168.0.94:34810 > xx.xx.xx.58:22  ttl=43 id=32614 iplen=60  seq=322734765 win=128 <wscale 10,nop,mss 265,timestamp 4294967295 0,sackOK>
sendto in send_ip_packet_sd: sendto(4, packet, 60, 0, xx.xx.xx.59, 16) => Operation not permitted
Offending packet: TCP 192.168.0.94:34810 > xx.xx.xx.59:22  ttl=59 id=17536 iplen=60  seq=322734765 win=128 <wscale 10,nop,mss 265,timestamp 4294967295 0,sackOK>
...
<host starttime="1679665010" endtime="1679665012"><status state="up" reason="echo-reply" reason_ttl="63"/>
<address addr="xx.xx.xx.50" addrtype="ipv4"/>
<hostnames>
</hostnames>

I have changed the plugin in the run functions adding "2 > /dev/null" to ignore errors and warnings as workaround.

my ($stdout) = $options{custom}->execute_command( command => 'nmap', command_options => $self->{option_results}->{nmap_options}, command_options_suffix => "$self->{option_results}->{subnet} 2> /dev/null", timeout => 120 );

garnier-quentin commented 1 year ago

The issue is about the stderr ? I don't understand how it can be an issue because the nmap doesnt redirect stderr to stdout.

rmorandell-pgum commented 1 year ago

it seem so but if on this error i write the nmap response to file i find this lines above in the output file .. and this seems definitely error or warnings from nmap ..

image

redirecting with "2> /dev/null" the lines doesn't appear and the plugin is working well

garnier-quentin commented 1 year ago

You're right. by default i redirect stderr...

garnier-quentin commented 1 year ago

https://github.com/centreon/centreon-plugins/pull/4324