NagiosEnterprises / ncpa

Nagios Cross-Platform Agent
Other
177 stars 95 forks source link

Plugin arguments doesnt work with check_http_json.py #937

Open ccztux opened 1 year ago

ccztux commented 1 year ago

I have issues with the plugin arguments used by check_http_json.py.

Neither this call:

[root@tux01 ~]# ./check_ncpa.py -H 10.0.0.10 -t mytoken -M plugins/check_http_json.py -a '-H inside01 -P 443 -p interface-rest/incident/count?incidentType=failedTask -s -w count,@1: -c count,@1: -e count' -v
Connecting to: https://10.0.0.10:5693/api/plugins/check_http_json.py/-H/inside01/-P/443/-p/interface-rest%2Fincident%2Fcount%3FincidentType%3DfailedTask/-s/-w/count%2C%401%3A/-c/count%2C%401%3A/-e/count?token=mytoken&check=1
File returned contained:
{
    "returncode": 2,
    "stdout": "usage: check_http_json.py [-h] [-d] [-s] -H HOST [-k] [-V] [--cacert CACERT]\n                          [--cert CERT] [--key KEY] [-P PORT] [-p PATH]\n                          [-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]\n                          [-f SEPARATOR] [-F VALUE_SEPARATOR]\n                          [-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]\n                          [-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]\n                          [-e [KEY_LIST [KEY_LIST ...]]]\n                          [-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]\n                          [-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]\n                          [-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]\n                          [-u [KEY_VALUE_LIST_UNKNOWN [KEY_VALUE_LIST_UNKNOWN ...]]]\n                          [-y [KEY_VALUE_LIST_NOT [KEY_VALUE_LIST_NOT ...]]]\n                          [-Y [KEY_VALUE_LIST_NOT_CRITICAL [KEY_VALUE_LIST_NOT_CRITICAL ...]]]\n                          [-m [METRIC_LIST [METRIC_LIST ...]]]\ncheck_http_json.py: error: unrecognized arguments: incident count?incidentType=failedTask"
}
usage: check_http_json.py [-h] [-d] [-s] -H HOST [-k] [-V] [--cacert CACERT]
                          [--cert CERT] [--key KEY] [-P PORT] [-p PATH]
                          [-t TIMEOUT] [-B AUTH] [-D DATA] [-A HEADERS]
                          [-f SEPARATOR] [-F VALUE_SEPARATOR]
                          [-w [KEY_THRESHOLD_WARNING [KEY_THRESHOLD_WARNING ...]]]
                          [-c [KEY_THRESHOLD_CRITICAL [KEY_THRESHOLD_CRITICAL ...]]]
                          [-e [KEY_LIST [KEY_LIST ...]]]
                          [-E [KEY_LIST_CRITICAL [KEY_LIST_CRITICAL ...]]]
                          [-q [KEY_VALUE_LIST [KEY_VALUE_LIST ...]]]
                          [-Q [KEY_VALUE_LIST_CRITICAL [KEY_VALUE_LIST_CRITICAL ...]]]
                          [-u [KEY_VALUE_LIST_UNKNOWN [KEY_VALUE_LIST_UNKNOWN ...]]]
                          [-y [KEY_VALUE_LIST_NOT [KEY_VALUE_LIST_NOT ...]]]
                          [-Y [KEY_VALUE_LIST_NOT_CRITICAL [KEY_VALUE_LIST_NOT_CRITICAL ...]]]
                          [-m [METRIC_LIST [METRIC_LIST ...]]]
check_http_json.py: error: unrecognized arguments: incident count?incidentType=failedTask

nor that:

[root@tux01 ~]# ./check_ncpa.py -H 10.0.0.10 -t mytoken -M plugins/check_http_json.py -q args='-H inside01 -P 443 -p interface-rest/incident/count?incidentType=failedTask -s -w count,@1: -c count,@1: -e count' -v
An error occurred:
need more than 1 value to unpack

works.

I have fixed this for me and will provide the fix via a pull request. The fix adds the following new argument to check_ncpa.py:

  -r RAW_PLUGIN_ARGS, --raw-plugin-args=RAW_PLUGIN_ARGS
                        Raw plugin arguments for the plugin to be run. This is
                        an alternative to -a and should be used if the
                        arguments are more complex, like URL parameters.
                        Example: -r '-H inside01 -P 443 -p interface-
                        rest/incident/count?incidentType=failedTask -s -w
                        count,@1: -c count,@1: -e count'
JamieSimon2 commented 1 year ago

Please merge @ccztux 's commit, it fixes my problem with check_ncpa.py for the check_http (and similar) plugins.

EDIT: I observe this version breaks usability of the '-a' argument.

ccztux commented 1 year ago

@JamieSimon2 Do you have any issues using the -a argument? There was an issue using it, but this should be fixed.

JamieSimon2 commented 1 year ago

Yes, the current release at https://github.com/NagiosEnterprises/ncpa/blob/master/client/check_ncpa.py has the exact problem described above. Arguments with slashes aren't interpreted/parsed correctly -- example below is for HTTP calls -- and result in bad NCPA responses.

Example:

[centos@lab-eu-1a-0504-h17 ~]$ /usr/lib64/nagios/plugins/check_ncpa.py -H 172.19.6.0 -P 5693 --token "REDACTED" -M 'plugins/check_http' -a '--IP-address=172.19.6.0 -p 3000 -u /login' -v
Connecting to: https://172.19.6.0:5693/api/plugins/check_http/--IP-address%3D172.19.6.0/-p/3000/-u/%2Flogin?token=REDACTED&check=1
File returned contained:
{
    "returncode": 1,
    "stdout": "HTTP WARNING: HTTP/1.1 400 Bad Request - 103 bytes in 0.000 second response time |time=0.000416s;;;0.000000 size=103B;;;0"
}
HTTP WARNING: HTTP/1.1 400 Bad Request - 103 bytes in 0.000 second response time |time=0.000416s;;;0.000000 size=103B;;;0
ccztux commented 1 year ago

The changes were merged into the maint branch. Try the version from the maint branch.

JamieSimon2 commented 1 year ago

I regret to report my testing of https://github.com/NagiosEnterprises/ncpa/blob/maint/client/check_ncpa.py indicates "-a" still does not work correctly with the "/" character, but the "-r" argument does.

$ /usr/bin/python3 /usr/lib64/nagios/plugins/check_ncpa.py -H 172.19.6.0 -P 5693 -t "MYTOKEN" -M "plugins/check_http" -r "-I 172.19.6.0 -p 3000 -u /login --onredirect=follow"
HTTP OK: HTTP/1.0 200 OK - 32253 bytes in 0.006 second response time |time=0.005890s;;;0.000000 size=32253B;;;0
$ /usr/bin/python3 /usr/lib64/nagios/plugins/check_ncpa.py -H 172.19.6.0 -P 5693 -t "MYTOKEN" -M "plugins/check_http" -a "-I 172.19.6.0 -p 3000 -u /login --onredirect=follow"
HTTP WARNING: HTTP/1.1 400 Bad Request - 103 bytes in 0.000 second response time |time=0.000440s;;;0.000000 size=103B;;;0