Page 1 of 1

API configure service with special character in description

Posted: Fri Jun 28, 2019 7:36 am
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.

Re: API configure service with special character in descript

Posted: Fri Jun 28, 2019 10:13 am
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.

Re: API configure service with special character in descript

Posted: Mon Jul 01, 2019 1:28 am
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

Re: API configure service with special character in descript

Posted: Mon Jul 01, 2019 4:42 pm
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

Re: API configure service with special character in descript

Posted: Thu Jul 04, 2019 3:04 am
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.

Re: API configure service with special character in descript

Posted: Mon Jul 08, 2019 10:01 am
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
}

Re: API configure service with special character in descript

Posted: Wed Jul 10, 2019 8:08 am
by dsynapalos
Hello there,
with the update live, all configurations went through correctly.
Thank you very much for the swift resolution.

Re: API configure service with special character in descript

Posted: Wed Jul 10, 2019 8:34 am
by lmiltchev
I am glad your issue has been resolved! I am closing this topic. Thanks!