Hello Team
We would like your help to twick the REST API call a global schedule maintenance on all hosts and associated services
curl -XPOST "https://X.X.X.X/nagiosxi/api/v1/system/ ... Y&pretty=1" -d "comment=Test downtime creation&start=1554864688&end=1554865288&hosts[]=localhost"
Then we would like to delete this scheduled maintenance downtime
curl -XGET "https://X.X.X.X/nagiosxi/api/v1/objects ... Y&pretty=1"
Get the integer then place in this command
curl -XDELETE "https://X.X.X.X/nagiosxi/api/v1/system/ ... Y&pretty=1"
Thanks
Insurity
NagiosXI API Schedule Maintinance
Re: NagiosXI API Schedule Maintinance
You could place all of your hosts in a hostgroup, for example "allhosts". Then you could use a script like the one below to accomplish this:
Code: Select all
#!/bin/bash
# Define variables
ip=`ip addr | grep global | grep -m 1 'inet' | awk '/inet[^6]/{print substr($2,0)}' | sed 's|/.*||'`
apikey=`echo "select api_key from xi_users where username='nagiosadmin';" | mysql -uroot -pnagiosxi nagiosxi | tail -1`
# Schedule downtime for all hosts/services
curl -XPOST "http://$ip/nagiosxi/api/v1/system/scheduleddowntime?apikey=$apikey&pretty=1" -d "comment=Test downtime creation&start=`date +'%s'`&end=`date -d '+2 hours' +'%s'`&hostgroups[]=allhosts&all_services=1"
# Remove downtimes
for id in `curl -s -XGET "http://$ip/nagiosxi/api/v1/objects/downtime?apikey=$apikey&pretty=1" | grep "internal_id" | cut -d ':' -f2 | sed 's/[^0-9]*//g'`; do
curl -XDELETE "http://$ip/nagiosxi/api/v1/system/scheduleddowntime/$id?apikey=$apikey&pretty=1"
doneBe sure to check out our Knowledgebase for helpful articles and solutions!
Re: NagiosXI API Schedule Maintinance
Thanks for the help
When I try this in power shell no action is visible or register in Nagios UI end
Could it be the quotation in the variables you sent are not passing variables through?
Any recommendation?
Thansk
Insurity
When I try this in power shell no action is visible or register in Nagios UI end
Could it be the quotation in the variables you sent are not passing variables through?
Any recommendation?
Thansk
Insurity
Re: NagiosXI API Schedule Maintinance
This is NOT a power shell script. It's a bash script, and it is meant to be run from the command line on the Nagios XI server (in SSH/putty session)... Why are you running it in power shell?When I try this in power shell no action is visible or register in Nagios UI end
You can check to see if the variables resolve by using the echo command. For example:
Code: Select all
ip=`ip addr | grep global | grep -m 1 'inet' | awk '/inet[^6]/{print substr($2,0)}' | sed 's|/.*||'`
echo $ip
apikey=`echo "select api_key from xi_users where username='nagiosadmin';" | mysql -uroot -pnagiosxi nagiosxi | tail -1`
echo $apikeyYou can get a list of the "internal_id"s by running:
Code: Select all
curl -s -XGET "http://$ip/nagiosxi/api/v1/objects/downtime?apikey=$apikey&pretty=1" | grep "internal_id" | cut -d ':' -f2 | sed 's/[^0-9]*//g'Be sure to check out our Knowledgebase for helpful articles and solutions!