API configure service with special character in description

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

API configure service with special character in description

Post by dsynapalos »

Hello there,

I am trying to modify a service configuration using the REST API using a PUT request to apply my modification.
The relevant command is as follows:

PUT "http://#####/nagiosxi/api/v1/config/service/<config_name>/<service_description>apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"

All works well when modifying services with regular descriptions, but I am unable to use it on services containing special characters, namely '/'.

I.E.
(From Core Config Manager / Service Manager)

Config Name *
somehost
Description *
GigabitEthernet0/1Bandwidth

(From GET service)
[
{
"config_name": "somehost",
"host_name": [
"somehost"
],
"service_description": "GigabitEthernet0\/1Bandwidth",
"use": [
"xiwizard_switch_port_bandwidth_service"
],
"check_command": "check_xi_service_mrtgtraf!some.rrd!700,300!850,450!M!!!!",
"max_check_attempts": "5",
"check_interval": "5",
"retry_interval": "1",
"check_period": "xi_timeperiod_24x7",
"notification_interval": "60",
"notification_period": "xi_timeperiod_24x7",
"contacts": [
"nagiosadmin"
],
"register": "1"
}
]

The following urls are not able to reach the correct service.
They return a <Response [200]>
{
"error": "Could not update the service specified. Does the service exist?"
}

"http://#####/nagiosxi/api/v1/config/service/somehost/GigabitEthernet0/1Bandwidth&apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"

"http://#####/nagiosxi/api/v1/config/service/somehost/GigabitEthernet0%2F1Bandwidth&apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"

"http://#####/nagiosxi/api/v1/config/service/somehost/GigabitEthernet0\/1Bandwidth&apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"

"http://#####/nagiosxi/api/v1/config/service/somehost/GigabitEthernet0%5C%2F1Bandwidth&apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"

"http://#####/nagiosxi/api/v1/config/service/somehost/GigabitEthernet0\\/1Bandwidth&apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"

"http://#####/nagiosxi/api/v1/config/service/somehost/GigabitEthernet0\\\/1Bandwidth&apikey=***&pretty=1&SOME_CHANGE&applyconfig=1"
I am using python3 and the requests module to perform the request.

Removing the special character '/' makes the url work correctly but is highly inconvenient.

Is it possible to find the correct expression that can reach the service of the example?

Thank you for your time.
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: API configure service with special character in descript

Post by jomann »

Hello,

This has been fixed in the newest version of XI (5.6.4) and will be out soon. Currently it is impossible to escape the / character when doing a PUT request to the API for services. I can send you a patched version of the file if you'd like or you can wait for the bug fix release.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Re: API configure service with special character in descript

Post by dsynapalos »

Hello jomann, thank you for your reply.

Pleased to know that the matter is fixed and awaits implementation.

What is the ETA of the 5.6.4 patch? If it is scheduled to be released later that this weekend (7+/7/19) I would like for you to send me the patched file so I can keep up with the workload.

Regards
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: API configure service with special character in descript

Post by ssax »

Please replace this file with the one I've attached (unzip it first):

Code: Select all

/usr/local/nagiosxi/html/api/includes/utils.inc.php
You do not have the required permissions to view the files attached to this post.
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Re: API configure service with special character in descript

Post by dsynapalos »

Hello again,
I applied the new file but the problem persists. Let me elaborate.
Let us work on changing the Display name of a Service that has the Configuration Name: ConfigName and the Service Description: Ser/vice

According to the /nagiosxi/help/ section the correct action would be to send a "PUT" request to the following url:

"https://<ip>/nagiosxi/api/v1/config/service/<config_name>/<service_description>?apikey=<apikey>'&<attributetobechanged>=<value>&pretty=1&applyconfig=1"

In our example the url would be:

"https://<ip>/nagiosxi/api/v1/config/service/ConfigName/Ser/vice?apikey=<apikey>'&pretty=1&display_name=ServiceDisplayName&applyconfig=1"

The use of the escape character in Ser/vice in the url results in the following response text:
{
"error": "Could not update the service specified. Does the service exist?"
}
Substituting the escape character "/" with the url encoding "%2F" still results in error:

"https://<ip>/nagiosxi/api/v1/config/service/ConfigName/Ser%2Fvice?apikey=<apikey>'&pretty=1&display_name=ServiceDisplayName&applyconfig=1"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /nagiosxi/api/v1/config/service/ConfigName/Ser/vice was not found on this server.</p>
</body></html>
Am I in error in the url construction? Is there a correct way to create the url for the request, or is it another problem?

Looking forward to hearing from you.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API configure service with special character in descript

Post by lmiltchev »

What is the ETA of the 5.6.4 patch?
Nagios XI 5.6.4 should be released tomorrow, provided we are done with testing it. As @jomann mentioned, the issue has been fixed. I tested it in my dev XI box, and was able to change the display_name of a service, called "Ser/vice" without any issues. See below:

Code: Select all

# curl -XPUT "http://x.x.x.x/nagiosxi/api/v1/config/service/localhost/Ser/vice?apikey=xxx&pretty=1&display_name=ServiceDisplayName&applyconfig=1"
{
    "success": "Updated localhost :: Ser\/vice in the system. Config applied, Nagios Core was restarted."
}

Code: Select all

define service {
    host_name                   localhost
    service_description         Ser/vice    
    display_name                ServiceDisplayName
    ... 
    register                    1
}
Be sure to check out our Knowledgebase for helpful articles and solutions!
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Re: API configure service with special character in descript

Post by dsynapalos »

Hello there,
with the update live, all configurations went through correctly.
Thank you very much for the swift resolution.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API configure service with special character in descript

Post by lmiltchev »

I am glad your issue has been resolved! I am closing this topic. Thanks!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked