Slow api?
Posted: Thu Mar 09, 2017 8:12 am
Hello,
I made this cript which is able to delete a service, all services and / or a host in Nagios XI with the help of the api. After I loop through all the services, I try to delete the host, but I get an error as all the services haven't been deleted yet it seems. When I check the CCM I can slowly see the deleted services go away one by one.
Why is this so slow? I have no performance issues on my server (as long as I don't apply configuration) .. Are the api queries queued somewhere? Where can I check if the queue is empty?
As a reference this is the script:
Yes I know I could put a sleep in there, but
- I rather just start the host deletion asap
- I would like to know how to monitor this api queue
- I would like to know why this is so slow (and this for only one host)
Grtz
Willem
I made this cript which is able to delete a service, all services and / or a host in Nagios XI with the help of the api. After I loop through all the services, I try to delete the host, but I get an error as all the services haven't been deleted yet it seems. When I check the CCM I can slowly see the deleted services go away one by one.
Why is this so slow? I have no performance issues on my server (as long as I don't apply configuration) .. Are the api queries queued somewhere? Where can I check if the queue is empty?
As a reference this is the script:
Code: Select all
#!/bin/bash
Debug=0
Verbose=1
source /tmp/daf_linux_functions.sh
NagiosServer="@option.nagiosserver@"
NagiosApiKey="@option.nagiosapikey@"
NagiosHost="@option.nagioshost@"
NagiosService="@option.nagiosservice@"
WriteLog Verbose Info "Verifying host \"$NagiosHost\" on $NagiosServer"
NagHostCheck="$(curl -s -XGET "https://$NagiosServer/nagiosxi/api/v1/objects/host?apikey=$NagiosApiKey&pretty=1&host_name=$NagiosHost&records=1" | jq -r .hostlist.recordcount)"
if [[ "$NagHostCheck" = "1" ]] ; then WriteLog Output Info "Host $NagiosHost verified. "
else WriteLog Output Info "Host $NagiosHost not found. Exiting. " ; exit 2 ; fi
if [[ "$NagiosService" != 'All' ]] ; then
WriteLog Output Info "Attempting to remove service $NagiosService of host $NagiosHost. "
CurlResult=$(curl -s -XDELETE "https://$NagiosServer/nagiosxi/api/v1/config/service?apikey=$NagiosApiKey&pretty=1&host_name=$NagiosHost&service_description=$NagiosService" | jq .)
case $CurlResult in
*error*) WriteLog Output Error "Error: $(echo "$CurlResult" | jq -r .error)" ; exit 2 ;;
*success*) WriteLog Output Info "Success: $(echo "$CurlResult" | jq -r .success)" ; exit 0;;
*) WriteLog Output Error "Unknown curl result: $CurlResult" ; exit 3;;
esac
else
WriteLog Output Info "Attempting to remove host ${NagiosHost}. "
CurlGetResult=$(curl -s -XGET "https://$NagiosServer/nagiosxi/api/v1/objects/service?apikey=$NagiosApiKey&pretty=1&host_name=$NagiosHost" | jq .)
WriteLog Debug Info "CurlGetResult: $CurlGetResult"
ServiceCount=$(echo $CurlGetResult | jq -r .servicelist.recordcount)
if [[ $ServiceCount = "1" ]] ; then
ServiceName=$(echo $CurlGetResult | jq -r .servicelist.service.service_description)
WriteLog Output Info "Attempting to remove the only service $ServiceName of host $NagiosHost. "
CurlResult=$(curl -s -XDELETE "https://$NagiosServer/nagiosxi/api/v1/config/service?apikey=$NagiosApiKey&pretty=1&host_name=$NagiosHost&service_description=$ServiceName" | jq .)
case $CurlResult in
*error*) WriteLog Output Error "Error: $(echo "$CurlResult" | jq -r .error)" ;;
*success*) WriteLog Output Info "Success: $(echo "$CurlResult" | jq -r .success)" ;;
*) WriteLog Output Error "Unknown curl result: $CurlResult" ; exit 3;;
esac
else
WriteLog Output Info "Looping through $ServiceCount services"
for ((i=0; i<$ServiceCount; i++)); do
ServiceName=$(echo $CurlGetResult | jq -r .servicelist.service[$i].service_description)
WriteLog Output Info "Attempting to remove service $ServiceName of host $NagiosHost. "
CurlResult=$(curl -s -XDELETE "https://$NagiosServer/nagiosxi/api/v1/config/service?apikey=$NagiosApiKey&pretty=1&host_name=$NagiosHost&service_description=$ServiceName" | jq .)
case $CurlResult in
*error*) WriteLog Output Error "Error: $(echo "$CurlResult" | jq -r .error)" ;;
*success*) WriteLog Output Info "Success: $(echo "$CurlResult" | jq -r .success)" ;;
*) WriteLog Output Error "Unknown curl result: $CurlResult" ; exit 3;;
esac
done
fi
WriteLog Output Info "All $ServiceCount services of $NagiosHost deleted successfully. "
WriteLog Output Info "Attempting to remove host $NagiosHost. "
CurlResult=$(curl -s -XDELETE "https://$NagiosServer/nagiosxi/api/v1/config/host?apikey=$NagiosApiKey&pretty=1&host_name=$NagiosHost" | jq .)
case $CurlResult in
*error*) WriteLog Output Error "Error: $(echo "$CurlResult" | jq -r .error)" ; exit 2 ;;
*success*) WriteLog Output Info "Success: $(echo "$CurlResult" | jq -r .success)" ; exit 0;;
*) WriteLog Output Error "Unknown curl result: $CurlResult" ; exit 3;;
esac
fi
exit 3- I rather just start the host deletion asap
- I would like to know how to monitor this api queue
- I would like to know why this is so slow (and this for only one host)
Grtz
Willem