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.
API configure service with special character in description
-
dsynapalos
- Posts: 23
- Joined: Tue Jun 25, 2019 2:26 am
Re: API configure service with special character in descript
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.
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
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
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
Please replace this file with the one I've attached (unzip it first):
Code: Select all
/usr/local/nagiosxi/html/api/includes/utils.inc.phpYou 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
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:
"https://<ip>/nagiosxi/api/v1/config/service/ConfigName/Ser%2Fvice?apikey=<apikey>'&pretty=1&display_name=ServiceDisplayName&applyconfig=1"
Looking forward to hearing from you.
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:
Substituting the escape character "/" with the url encoding "%2F" still results in error:{
"error": "Could not update the service specified. Does the service exist?"
}
"https://<ip>/nagiosxi/api/v1/config/service/ConfigName/Ser%2Fvice?apikey=<apikey>'&pretty=1&display_name=ServiceDisplayName&applyconfig=1"
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?<!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>
Looking forward to hearing from you.
Re: API configure service with special character in descript
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:What is the ETA of the 5.6.4 patch?
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
Hello there,
with the update live, all configurations went through correctly.
Thank you very much for the swift resolution.
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
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!