monitoring-plugins / monitoring-plugins

Monitoring Plugins
https://www.monitoring-plugins.org
GNU General Public License v3.0
487 stars 284 forks source link

check_curl: Parameterized -S does not work without -I #2013

Open oxzi opened 3 months ago

oxzi commented 3 months ago

Hopefully this output explains it better than I could do with words:

$ ./check_curl -V
check_curl v2.4.0 (monitoring-plugins 2.4.0)
libcurl/8.9.1 LibreSSL/3.9.0 zlib/1.3.1.1-motley nghttp2/1.61.0 ngtcp2/1.6.0 nghttp3/1.4.0

$ ./check_curl -H monitoring-plugins.org -S
HTTP OK: HTTP/1.1 301 Moved Permanently - 388 bytes in 0.112 second response time |time=0.111791s;;;0.000000;10.000000 size=388B;;;0;
$ ./check_curl -H monitoring-plugins.org -S 1.2+
HTTP CRITICAL - Unable to lookup IP address for '1.2+': getaddrinfo returned -4 - non-recoverable failure in name resolution
$ ./check_curl -H monitoring-plugins.org --ssl=1.2+
HTTP OK: HTTP/1.1 301 Moved Permanently - 388 bytes in 0.118 second response time |time=0.117554s;;;0.000000;10.000000 size=388B;;;0;
$ ./check_curl -H monitoring-plugins.org -I 130.133.8.40 -S 1.2+
HTTP OK: HTTP/1.1 301 Moved Permanently - 388 bytes in 0.115 second response time |time=0.115050s;;;0.000000;10.000000 size=388B;;;0;
RincewindsHat commented 3 months ago

hm, works with --ssl=1.2+, so parser error I guess

oxzi commented 3 months ago

Just got back to this. The error lies in getopt's different behavior of arguments (one colon) and optional arguments (two colons). The latter is used here and, just for the record, a non-POSIX extension initially added as a GNU extension, later ported to other libcs.

The difference is well explained in OpenBSD's getopt(3):

It does not matter to getopt() if a following argument has leading whitespace; except in the case where the argument is optional, denoted with two colons, no leading whitespace is permitted.

This is identical to the glibc behavior, but, unless I missed it in their man page, does not explicitly states this.

Thus, getting back to the initially reported error, the following version works:

./check_curl -H monitoring-plugins.org -S1.2+ HTTP OK: HTTP/1.1 301 Moved Permanently - 388 bytes in 0.104 second response time |time=0.104171s;;;0.000000;10.000000 size=388B;;;0;

One might close this, as it works as intended.

However, this results in an atypical usage, at least in my opinion. This can be seen in the Icinga 2 ITL issue0.

Btw, the merged version does not work as expected. The "(-S w/ value)" case sets a value which will get lost.

./check_curl -vv -H monitoring-plugins.org -I 130.133.8.40 -S 1.2+

  • Set SSL/TLS version to 0

After the 'S' getopt_long case, the next iteration results in 'c == -1'.

Thus, I would suggest either documenting this or changing the parsing logic.