API : Create Service

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

API : Create Service

Post 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?
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: API : Create Service

Post 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 "\".
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: API : Create Service

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: API : Create Service

Post 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.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: API : Create Service

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: API : Create Service

Post 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 ...
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: API : Create Service

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: API : Create Service

Post by dh0125e »

I think we can close, we've run it against several services and stuff is migrating as expected.


Thanks,
David
Locked