Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_nscp_api: support spaces in query arguments #5537

Closed
cite opened this issue Aug 30, 2017 · 5 comments · Fixed by #5539
Closed

check_nscp_api: support spaces in query arguments #5537

cite opened this issue Aug 30, 2017 · 5 comments · Fixed by #5539
Labels
area/windows Windows agent and plugins bug Something isn't working
Milestone

Comments

@cite
Copy link

cite commented Aug 30, 2017

Trying to use check_nscp_api to check a Windows service with a space in it's name, we get the error message the argument ('service=Haufe FabricHostService') for option '--arguments' is invalid. No amount of escaping the space will fix this, and actually substituting the space wit %20 seems to lead to double-escaping the string.

However, using curl, we can see this works:

# curl -sk -H "password: secret" https://10.2.3.4:8443/query/check_service?service=Haufe%20FabricHostService | jq .
{
  "header": {
    "source_id": ""
  },
  "payload": [
    {
      "command": "check_service",
      "lines": [
        {
          "message": "OK: All 1 service(s) are ok.",
          "perf": [
            {
              "alias": "Haufe FabricHostService",
              "int_value": {
                "critical": 0,
                "value": 4,
                "warning": 0
              }
            }
          ]
        }
      ],
      "result": "OK"
    }
  ]
}

Version is 1.0.0:

# /usr/libexec/icinga/plugin/check_nscp_api --version
Version: 1.0.0
@dnsmichi
Copy link
Contributor

@Crunsher ACQUERY_ENCODE does not include whitespaces when called with Utility::EscapeString(). This could be a possible reason.

@atj
Copy link
Contributor

atj commented Aug 30, 2017

This issue occurs for all arguments not just "--query", e.g.:

$ Bin/Release/check_nscp_api -H 127.0.0.1 -q 'test' --password 'pass word'
the argument ('pass word') for option '--password' is invalid
Options:
  -h [ --help ]             Print usage message and exit
  -V [ --version ]          Print version and exit
  -d [ --debug ]            Verbose/Debug output
  -H [ --host ] arg         REQUIRED: NSCP API Host
  -P [ --port ] arg (=8443) NSCP API Port (Default: 8443)
  --password arg            REQUIRED: NSCP API Password
  -q [ --query ] arg        REQUIRED: NSCP API Query endpoint
  -a [ --arguments ] arg    NSCP API Query arguments for the endpoint

This occurs because a lexical_cast from a std::string containing spaces to icinga::String throws a boost::bad_lexical_cast exception. I believe is due to the fact that lexical_cast uses the >> operator which splits on whitespace.

See my PR for a fix.

@cite
Copy link
Author

cite commented Sep 3, 2017

I can confirm that @atj fixed the problem in his PR.

@dnsmichi dnsmichi added bug Something isn't working Plugins labels Sep 4, 2017
@dnsmichi dnsmichi added this to the 2.7.1 milestone Sep 5, 2017
@dnsmichi
Copy link
Contributor

Confirmed, breaks here as well.

mbmif ~ # check_nscp_api -H 10.0.10.148 --password icinga --query check_service --arguments 'service=User Manager'
the argument ('service=User Manager') for option '--arguments' is invalid
Options:
  -h [ --help ]             Print usage message and exit
  -V [ --version ]          Print version and exit
  -d [ --debug ]            Verbose/Debug output
  -H [ --host ] arg         REQUIRED: NSCP API Host
  -P [ --port ] arg (=8443) NSCP API Port (Default: 8443)
  --password arg            REQUIRED: NSCP API Password
  -q [ --query ] arg        REQUIRED: NSCP API Query endpoint
  -a [ --arguments ] arg    NSCP API Query arguments for the endpoint

mbmif ~ # check_nscp_api -H 10.0.10.148 --password icinga --query check_service --arguments 'service=UserManager'
check_service OK: All 1 service(s) are ok. | 'UserManager'=4;0;0

Seems that Windows accepts the workaround without spaces too.

@dnsmichi
Copy link
Contributor

Better test case is in #5539.

@dnsmichi dnsmichi added the area/windows Windows agent and plugins label May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/windows Windows agent and plugins bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants