Using the Icinga Web API

by | Mar 12, 2021

Unfortunately, there is little to no documentation for using the Icinga Web API to perform monitoring actions such as scheduling downtimes. But it’s a simple thing and I’ll give you a quick example of how to do it. Using the Icinga Web API instead of the Icinga API gives you the advantages of the permission and restriction system, various authentication methods and auditing.

Icinga Web supports API access to all forms by simply adding the Accept: application/json header to the requests. In the following examples we plan downtimes for single and multiple hosts and services. The required fields for planning downtimes are the following:

  • type which is either fixed or flexible
  • start as UNIX timestamp
  • end as UNIX timestamp
  • comment

The following command creates a downtime for $hostname for the next hour.

curl -H "Accept: application/json" -u user:password \
"https://$server/icingaweb2/monitoring/host/schedule-downtime?host=$hostname" \
-F "type=fixed" \
-F "start=$(date +%s)" \
-F "end=$(expr $(date +%s) + 3600)" \
-F "comment=Reboot"

If you want to create downtimes for all services on this host as well, just add -F "all_services=1".

If you want to plan downtimes for multiple hosts, the URL looks like this:

https://$server/icingaweb2/monitoring/hosts/schedule-downtime?$filter

$filter can be used from the multi-select or list views, e.g. hostgroup_name=test-servers or ((host_name=db1)|(host_name=db2)).

Scheduling service downtimes is done using the following URLs:

https://$server/icingaweb2/monitoring/service/schedule-downtime?host=$hostname&service=$servicename

https://$server/icingaweb2/monitoring/services/schedule-downtime?$filter

If you want to use the API for other monitoring commands, use your browser’s developer tools to see which URL is used by the relevant forms and what data they POST.

You can also find more how-tos at community.icinga.com.

You May Also Like…

Subscribe to our Newsletter

A monthly digest of the latest Icinga news, releases, articles and community topics.