Page 1 of 1
API : Create Service
Posted: Tue Mar 23, 2021 11:01 am
by dh0125e
When using the create service API we are seeing that "\" is being removed from the check_command. It doesn't matter if it's \ or \\. I can see that it's getting swapped to the %5C in the URL that's being sent to the system.
Is there any work around for being able to include \ as part of a check_command?
Re: API : Create Service
Posted: Wed Mar 24, 2021 9:45 am
by dh0125e
Impact of this is we are unable to synchronize nagios services between XI hosts using the API as the filepath for Windows systems are being broken via the removal of "\".
Re: API : Create Service
Posted: Wed Mar 24, 2021 10:13 am
by benjaminsmith
Hi
@dh0125e,
Can you post the full API command (redact any sensitive info) to the thread and I will try to replicate this on my system.
Also, what version of Nagios XI are you using?
Thanks,
Benjamin
Re: API : Create Service
Posted: Wed Mar 24, 2021 1:21 pm
by dh0125e
The source service JSON from the REST API
{
"config_name": "DAVID-TEST",
"service_description": "DAVID-TEST: Log file GenericHost.log_copy_1",
"use": [
"service-template-name-goes-here"
],
"hostgroup_name": [
"DAVID_TEST"
],
"check_command": "command_name_here!-P $_HOSTPORT$ -t $_HOSTNCPATOKEN$ -M 'plugins\/customplugin.exe' -q 'args=-p some info is here,args=-l \"G:\\DIR1\\DIR2\\file.log\",args=-c 1,args=-a'!!!!!!!",
"notes": "something-here",
"register": "1"
}
]
What we get on the other side in the check_command
-P $_HOSTPORT$ -t $_HOSTNCPATOKEN$ -M 'plugins/customplugin.exe' -q 'args=-p some info is here,args=-l "G:DIR1DIR2file.log",args=-c 1,args=-a'
---
The script in use removes the register:1 value, and adds a force:1 to the json payload, otherwise it's left the same and not altered.
Re: API : Create Service
Posted: Thu Mar 25, 2021 11:51 am
by benjaminsmith
Hi
@dh0125e,
After digging into this some more, there are several functions for stripslashes in the API. Try using
\\\\ instead of
\\and test the command again. That should take care of the issue.
If that still doesn't work, please post the exact API call for us to review.
Regards,
Benjamin
Re: API : Create Service
Posted: Thu Mar 25, 2021 12:49 pm
by dh0125e
Some more testing based upon your feedback, tripling the number of slashes appears to make it work in limited testing, I had only doubled the slashes previously ...
Re: API : Create Service
Posted: Fri Mar 26, 2021 10:10 am
by benjaminsmith
Hi,
Some more testing based upon your feedback, tripling the number of slashes appears to make it work in limited testing, I had only doubled the slashes previously
That's good to hear. We can keep this open while you are testing if you have further questions.
Regards,
Benjamin
Re: API : Create Service
Posted: Fri Mar 26, 2021 11:32 am
by dh0125e
I think we can close, we've run it against several services and stuff is migrating as expected.
Thanks,
David