REST API Less than sign

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
andyb4u
Posts: 114
Joined: Tue Aug 15, 2017 1:58 am

REST API Less than sign

Post 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))"
User avatar
jdunitz
Posts: 235
Joined: Wed Feb 05, 2020 2:50 pm

Re: REST API Less than sign

Post 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
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!
andyb4u
Posts: 114
Joined: Tue Aug 15, 2017 1:58 am

Re: REST API Less than sign

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: REST API Less than sign

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked