Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Created July 15, 2014 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanhandley/2fa35c1cb9821251d70e to your computer and use it in GitHub Desktop.
Save seanhandley/2fa35c1cb9821251d70e to your computer and use it in GitHub Desktop.

Running Icinga Commands via the REST API

I'm trying to automatically have a host in Icinga be disabled temporarily while Foreman rebuilds it. This prevents dozens of unnecessary alerts being generated.

The API call is as follows:

http://icinga.sal01.datacentred.co.uk/icinga-web/web/api/cmd/cmd=DISABLE_ALL_NOTIFICATIONS/authkey=mykey/target=host/data=myhost

The JSON result is:

{"success":true,"errors":[]}

There are no errors in the icinga or icinga-web log files and the host notifications remain enabled. I can disable them in the UI and this works fine (the red megaphone icon appears to denote the host is disabled).

Anything I'm doing incorrectly or anywhere I can look to debug further?

Thanks!

@clsa1
Copy link

clsa1 commented Jul 15, 2014

Hi,

the API call must be:

http://icinga.sal01.datacentred.co.uk/icinga-web/web/api/cmd/cmd=DISABLE_HOST_NOTIFICATIONS/authkey=mykey/target=[%7B%22instance%22:%22default%22,%22host%22:%22host%22,%22checktime%22:%221405427958%22%7D]/data=%7B%7D

for debugging execute

icinga2-enable-feature debuglog

and restart icinga2. There should be something like this in /var/log/icinga2/debug.log

tail -f /var/log/icinga2/debug.log | grep -A 4 ExternalCommandListener

[2014-07-15 15:14:34 +0200] information/ExternalCommandListener: Executing external command: [1405430074] DISABLE_HOST_NOTIFICATIONS;localhost
[2014-07-15 15:14:34 +0200] debug/DbEvents: add external command history
[2014-07-15 15:14:34 +0200] notice/ExternalCommandProcessor: Disabling notifications for host 'localhost'
[2014-07-15 15:14:34 +0200] debug/IdoMysqlConnection: Query: INSERT INTO icinga_externalcommands (command_args, command_name, command_type, endpoint_object_id, entry_time, instance_id) VALUES ('localhost', 'DISABLE_HOST_NOTIFICATIONS', '25', 1024, FROM_UNIXTIME(1405430074), 1)
[2014-07-15 15:14:34 +0200] debug/IdoMysqlConnection: Query: UPDATE icinga_hoststatus SET notifications_enabled = '0' WHERE host_object_id = 211 AND instance_id = 1

Hope this helps,

Clifford

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment