Skip to main content

An icinga2 API client.

Project description

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())

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icinga2py-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

icinga2py-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file icinga2py-0.1.1.tar.gz.

File metadata

  • Download URL: icinga2py-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.5

File hashes

Hashes for icinga2py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 50d4d7e0da9059565dc5df7f9691132ab7700dadedef3543d91bcece7580fd7d
MD5 e3143c640a55a099d1ad8888666afc05
BLAKE2b-256 3d42d074972a597561a58cbf469a5bdb1f20267640d339f6f5ca762304901b07

See more details on using hashes here.

File details

Details for the file icinga2py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: icinga2py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.5

File hashes

Hashes for icinga2py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c102ef8c86af8a6c04ad629b13207d2a130a28c640c4669d259f0b2ff0895bac
MD5 4daf24e1c1f295d34810418fa2bb050c
BLAKE2b-256 307ebca94b68017962253d4cf7665910410deb59a1d50dd8c1aae188797bb4e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page