Skip to content

Instantly share code, notes, and snippets.

@mcktr
Last active April 2, 2019 16:39
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 mcktr/63040a8110aa5f2c966d2ae164ba4375 to your computer and use it in GitHub Desktop.
Save mcktr/63040a8110aa5f2c966d2ae164ba4375 to your computer and use it in GitHub Desktop.
Acknowledge host problem through Icinga 2 API using Python
#!/usr/bin/env python
import requests, json
# change localhost to your Icinga 2 API
url = 'https://localhost:5665/v1/actions/acknowledge-problem?type=Host&host='
header = {
'Accept': 'application/json'
}
# adjust author and comment to your needs
data = {
'author': 'icingaadmin',
'comment': 'Global outage. Working on it.'
}
# Change hostname to the affected host
hostname = 'myhostobject'
url += hostname
print url
# verify=False is lazy; better is to check the actual certificate
# an example can be found here https://icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#example-api-client-in-python
# change auth=('icinga', 'icinga') to your Icinga 2 API credentials
r = requests.post(url, headers=header, auth=('icinga', 'icinga'), data=json.dumps(data), verify=False)
print r.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment