Page 1 of 2
Delete service using REST API error on XI version 5.6.5
Posted: Wed Jul 24, 2019 1:13 pm
by JosephH
Trying to delete services in pending status using Rest API got the following error:
{
"error": "Could not remove services. Failed services may not exist.",
"services": [],
"failed": ["servername - Virtual Memory Usage"]
}
Here are what I found out:
1. all the services in pending status are configured passive
2. I can use REST API to get all the services back for this host
3. In CCM, there is no services listed under this service configuration name: servername.cfg
Any help is greatly appreciated.
Thanks
Joseph
Re: Delete service using REST API error on XI version 5.6.5
Posted: Wed Jul 24, 2019 3:15 pm
by lmiltchev
Can you show us the actual REST API command that you used, and the service config?
Re: Delete service using REST API error on XI version 5.6.5
Posted: Thu Jul 25, 2019 6:44 am
by JosephH
Here is the command to get the service status from SOAP UI, which returns 1 record:
Code: Select all
https://linuxserver/nagiosxi/api/v1/objects/servicestatus?apikey=ApiKey&pretty=1&host_name=hostname&has_been_checked=0&name=virtual%20memory%20usage
Here is the command I used from SOAP UI for deleting service:(and got the error)
Code: Select all
https://linuxserver/nagiosxi/api/v1/config/service?apikey=ApiKey&pretty=1&host_name=hostname&service_description=Virtual Memory Usage
and the service configure file for this host: (no Virtual Memory Usage, only Ping)
define service {
host_name hostname
service_description Ping
check_command check-host-alive
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
notifications_enabled 0
contacts xxxx
_xiwizard linux_snmp
register 1
}
###############################################################################
#
# Services configuration file
#
# END OF FILE
#
###############################################################################
Re: Delete service using REST API error on XI version 5.6.5
Posted: Thu Jul 25, 2019 12:02 pm
by lmiltchev
Are you applying configuration? Add "&applyconfig=1" to your command - the service won't get deleted, until you apply configuration.
Re: Delete service using REST API error on XI version 5.6.5
Posted: Thu Jul 25, 2019 12:31 pm
by JosephH
I believe it is error-ed out before running "&applyconfig=1"
Re: Delete service using REST API error on XI version 5.6.5
Posted: Thu Jul 25, 2019 4:15 pm
by lmiltchev
So, was the service present, then deleted via the REST API, regardless of the error shown after running the delete command? You said that you could only see "Ping" service on this host, so the "Virtual Memory Usage" must have been deleted.
When you said:
Here is the command I used from SOAP UI...
did you mean you used this tool:
https://www.soapui.org/?
I was hoping to see the REST API command, run from the command line, along with the output of it...
Example:
Code: Select all
[root@main-nagios-xi ~]# curl -XDELETE "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=xxx&pretty=1&host_name=testapihost&service_description=PING&applyconfig=1"
{
"success": "Removed services from the system. Config applied, Nagios Core was restarted.",
"services": [
"testapihost - PING"
],
"failed": [
]
}
Did you use this:
Code: Select all
https://linuxserver/nagiosxi/api/v1/config/service?apikey=ApiKey&pretty=1&host_name=hostname&service_description=Virtual Memory Usage
or this:
Code: Select all
https://linuxserver/nagiosxi/api/v1/config/service?apikey=ApiKey&pretty=1&host_name=hostname&service_description=Virtual%20Memory%20Usage
- can you clarify?
I believe it is error-ed out before running "&applyconfig=1"
You are correct. Can you apply configuration by running the command below?
Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/applyconfig?apikey=xxx"
Re: Delete service using REST API error on XI version 5.6.5
Posted: Fri Jul 26, 2019 10:48 am
by JosephH
Hi lmiltchev,
Thank you so much for willing to help.
1. I used SoapUI by SMART BARE, a window desktop console application. it is from
https://www.soapui.org/
2. Even before deleting the service, the service configuration file only have Ping defined, we define all others using passive. And all the passive checks shown on the service status panel in pending status. We use get service status API can get this service info back.
3. I ran the curl command as below and error-ed.
curl -k -XDELETE "
https://linuxserver/nagiosxi/api/v1/con ... lyconfig=1"
{
"error": "Could not find a unique id for this service."
}
4. Yes, I can run the following command
curl -XPOST "
http://x.x.x.x/nagiosxi/api/v1/system/a ... apikey=xxx"
Thank you,
Joseph
Re: Delete service using REST API error on XI version 5.6.5
Posted: Fri Jul 26, 2019 5:00 pm
by lmiltchev
Do you see the service in the GUI?
Can you find it now by running the command below?
Code: Select all
curl -XGET "http://xxx/nagiosxi/api/v1/objects/servicestatus?apikey=xxx&pretty=1&host_name=hostname&has_been_checked=0&name=virtual%20memory%20usage"
You said that you used these commands:
Code: Select all
https://linuxserver/nagiosxi/api/v1/objects/servicestatus?apikey=ApiKey&pretty=1&host_name=hostname&has_been_checked=0&name=virtual%20memory%20usage
Code: Select all
https://linuxserver/nagiosxi/api/v1/config/service?apikey=ApiKey&pretty=1&host_name=hostname&service_description=Virtual Memory Usage
Do you have two different services - "virtual memory usage" and "Virtual Memory Usage", or you have one (this is a typo)?
Do you have any errors / crashed tables in the db?
or
Are you seeing the same issue after restarting services?
Code: Select all
service nagios stop
service ndo2db retart
service nagios start
Re: Delete service using REST API error on XI version 5.6.5
Posted: Mon Aug 05, 2019 2:29 pm
by JosephH
Hi lmiltchev,
To answer your questions:
1. Do you see the service in the GUI?
Yes. I can see it from service status for this host in Pending status.
2. Can you find it now by running the command below?
Yes. I got the info back by running the following command:
https://linuxserver/nagiosxi/api/v1/obj ... ry%20usage
3. Do you have two different services - "virtual memory usage" and "Virtual Memory Usage", or you have one (this is a typo)?
I only have one service named "Virtual Memory Usage". It was a typo.
4. Do you have any errors / crashed tables in the db?
I do not have permission to read this file "/var/log/mariadb/mariadb/log". I may ask admin to take a look.
5. Are you seeing the same issue after restarting services?
I believe so since we restarted few times. I will check with Admin to be sure.
Thanks
Joseph
Re: Delete service using REST API error on XI version 5.6.5
Posted: Tue Aug 06, 2019 9:08 am
by lmiltchev
Is the "Virtual Memory Usage" service added to multiple hosts or a hostgroup?