Page 1 of 1

REST API Less than sign

Posted: Wed Feb 26, 2020 9:17 am
by andyb4u
Hi,

I'm fairly new to working with the API.

I'm trying to create a new service via the REST API, POST config/service


I originally tried this:

curl -XPOST "http://nagiosserver/nagiosxi/api/v1/con ... y&pretty=1" -d 'host_name=new_server&service_description=Disk Usage - C&use=xiwizard_itassistwindowsserver_nrpe_service&check_command=check_nrpe\!check_drivesize\!-a "warning=((free<10%) and (free<4G))" "critical=((free<5%) and (free<2G))" "top-syntax=%(status) %(problem_list)" "detail-syntax=%(drive) Total: %(size) - Used: %(used) (%(used_pct)%) - Free: %(free) (%(free_pct)%)" "drive=c"&check_interval=5&retry_interval=1&max_check_attempts=5&check_period=xi_timeperiod_24x7&contact_groups=Application Support Team - Monitoring,Server Hosting - Windows&notification_interval=1440&notification_period=xi_timeperiod_24x7&_xiwizard=nrpewindows&applyconfig=1'

But found that it didn't like the < symbol.

If I looked at the service in Core Config it only showed part of the string in $ARG2$ field : -a "warning=((free

I then tried to substitute the < symbol with it's hexadecimal code (%3C) :

curl -XPOST "http://nagiosserver/nagiosxi/api/v1/con ... y&pretty=1" -d 'host_name=new_server&service_description=Disk Usage - C&use=xiwizard_itassistwindowsserver_nrpe_service&check_command=check_nrpe\!check_drivesize\!-a "warning=((free%3C10%) and (free%3C4G))" "critical=((free%3C5%) and (free%3CG))" "top-syntax=%(status) %(problem_list)" "detail-syntax=%(drive) Total: %(size) - Used: %(used) (%(used_pct)%) - Free: %(free) (%(free_pct)%)" "drive=c"&check_interval=5&retry_interval=1&max_check_attempts=5&check_period=xi_timeperiod_24x7&contact_groups=Application Support Team - Monitoring,Server Hosting - Windows&notification_interval=1440&notification_period=xi_timeperiod_24x7&_xiwizard=nrpewindows&applyconfig=1'

This didn't work either.

I then tried adding a space before and after %3C

This worked:

curl -XPOST "http://nagiosserver/nagiosxi/api/v1/con ... y&pretty=1" -d 'host_name=new_server&service_description=Disk Usage - C&use=xiwizard_itassistwindowsserver_nrpe_service&check_command=check_nrpe\!check_drivesize\!-a "warning=((free %3C 10%) and (free %3C 4G))" "critical=((free %3C 5%) and (free %3C G))" "top-syntax=%(status) %(problem_list)" "detail-syntax=%(drive) Total: %(size) - Used: %(used) (%(used_pct)%) - Free: %(free) (%(free_pct)%)" "drive=c"&check_interval=5&retry_interval=1&max_check_attempts=5&check_period=xi_timeperiod_24x7&contact_groups=Application Support Team - Monitoring,Server Hosting - Windows&notification_interval=1440&notification_period=xi_timeperiod_24x7&_xiwizard=nrpewindows&applyconfig=1'

However, I'm wondering if there is a way of using the < symbol without adding a space before and after %3C

E.g I've been asked if I can make the string in $ARG2$ to look like: -a "warning=((free<10%) and (free<4G))" etc rather than a "warning=((free < 10%) and (free < 4G))"

Re: REST API Less than sign

Posted: Wed Feb 26, 2020 10:39 am
by jdunitz
We've tried a number of things to replicate what you're doing, and I see how the command gets cut off, as you noted.

Because the less-than is a special character, it has to have a space before and after it in the command. The way you did it with percent-3C is the only way that seems to work, other than also replacing the space with percent-20. Either way, though, there's got to be a space before and after the less-than.

Sorry this isn't how you wanted it to work...


--Jeffrey

Re: REST API Less than sign

Posted: Thu Feb 27, 2020 6:13 am
by andyb4u
Thank you for your response Jeffrey. At least now I know that I wasn't doing it incorrectly and there isn't a workaround. Everyday is a learning day :D

Thanks again,
Andy

Re: REST API Less than sign

Posted: Thu Feb 27, 2020 8:47 am
by scottwilkerson
andyb4u wrote:Thank you for your response Jeffrey. At least now I know that I wasn't doing it incorrectly and there isn't a workaround. Everyday is a learning day :D

Thanks again,
Andy
Have a great day!

Locking thread