Skip to main content

icinga2-api

An icinga2 API client, see http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-api to learn more about icinga2 API.

Installation

pip install icinga2py

Development Guide

make init

Run Examples

. venv/bin/activate
cp examples/local_config.py.example examples/local_config.py
# edit examples/local_config.py
vi examples/local_config.py
python examples/example.py

Icinga2 API Reference

perm, url, SUPPORTS FILTERS

actions/<action>        /v1/actions Yes
config/query            /v1/config  No
config/modify           /v1/config  No
objects/query/<type>    /v1/objects Yes
objects/create/<type>   /v1/objects No
objects/modify/<type>   /v1/objects Yes
objects/delete/<type>   /v1/objects Yes
status/query/<type>     /v1/status  Yes
events/<type>           /v1/events  No
console                 /v1/console No

---

base url = /v1

GET     /objects/<type>[/<fullname>]    attrs, joins, meta, filter
PUT     /objects/<type>/<fullname>      templates, attrs
POST    /objects/<type>/<fullname>      attrs
DELETE  /objects/<type>[/<fullname>]    cascade, filter

/actions/<action>

/events     ?
/status     ?
/console    session,command,sandboaxed

GET     /config/packages
POST    /config/packages/<package>
DELETE  /config/packages/<package>
POST    /config/stages/<package>           files(file => content pairs)
GET     /config/stages/<package>/<stage>
DELETE  /config/stages/<package>/<stage>
GET     /config/files/<package>/<stage>/<path>

GET /types/<objectname>

*notes: <type> has to be replaced with the plural name of the object type

Usage

from icinga2_api.api import Api
from pprint import pprint

# init api instance
api = Api(['config-master.localdomain', 'icinga-api1.localdomin', 'icinga-api2.localdomin'],
          (username, passwd),
          'path of your ca cert')

# /objects/hosts
print api.objects.hosts.get(attrs=["name"])
pprint(api.objects.hosts.get(attrs=["name"], filter='host.name == "sindar1a"'))

# /config/packages
pprint(api.config.packages.dae.post())
print api.config.packages.dae.delete()
pprint(api.config.packages.get())
pprint(api.config.stages.dae.url('sindar33a-1458219125-0').get())

## upload config file
files = {
    'zones.d/global-templates/dae.conf': '// Hello DAE yesyesyes',
    'zones.d/checker/dae.conf': '// Hello DAE',
}
pprint(api.config.stages.dae.post(files=files))

## clean old config package stages
MAX_STAGE_RESERVED = 3
r = api.config.packages.get()
for pkg in r.get('results', []):
    if pkg['name'] != 'dae':
        continue
    remove_cnt = max(len(pkg['stages']) - MAX_STAGE_RESERVED, 0)
    remove_stages = pkg['stages'][:remove_cnt]
    print 'going to remove', remove_stages
    for stage in remove_stages:
        api.config.stages.dae.url(stage).delete()
pprint(api.config.packages.get())

## watch events
for event in api.events.watch(
    types=['Notification'],
    queue='my_queue',
):
    do_something_with(event)

NOTES

  • only support Advanced Filters
  • only support http basic auth
  • I think there's bug in icinga2 api, that you better query to only one host(your cluster config master) when you need to manipulate config package

Metadata

Release files for icinga2py 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for icinga2py 0.1.2
File Size Uploaded
icinga2py-0.1.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for icinga2py 0.1.2
File Interpreter ABI Platform
icinga2py-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.4 kB

Release files / icinga2py-0.1.2.tar.gz

Download URL icinga2py-0.1.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4047c676cd68f1dbfcb3178d3cb45ae1d9ecb2df9d7d270e17da86ffbf00db1d
BLAKE2b-256 checksum
How to use checksums
ba55e599729dd9957a502506c7e264351a6b974efa3a6f5c2e4bd5b03ffd9c92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.9

Release files / icinga2py-0.1.2-py3-none-any.whl

Download URL icinga2py-0.1.2-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17c3eb3740b826fe7eeb66cad32410f2d7965f53def3a1e57533301e12a92571
BLAKE2b-256 checksum
How to use checksums
181541c6848f6829fc4b9bb5788f43637daf748e34fe3b91d801c97f6dfc4998
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page