ICinga2 API客户端。
icinga2p的Python项目详细描述
ICinga2 API
一个icinga2 api客户端,请参见http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-api以了解有关icinga2api的更多信息。
安装
pip install icinga2py
开发指南
make init
运行示例
. 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参考
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
用法
fromicinga2_api.apiimportApifrompprintimportpprint# init api instanceapi=Api(['config-master.localdomain','icinga-api1.localdomin','icinga-api2.localdomin'],(username,passwd),'path of your ca cert')# /objects/hostsprintapi.objects.hosts.get(attrs=["name"])pprint(api.objects.hosts.get(attrs=["name"],filter='host.name == "sindar1a"'))# /config/packagespprint(api.config.packages.dae.post())printapi.config.packages.dae.delete()pprint(api.config.packages.get())pprint(api.config.stages.dae.url('sindar33a-1458219125-0').get())## upload config filefiles={'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 stagesMAX_STAGE_RESERVED=3r=api.config.packages.get()forpkginr.get('results',[]):ifpkg['name']!='dae':continueremove_cnt=max(len(pkg['stages'])-MAX_STAGE_RESERVED,0)remove_stages=pkg['stages'][:remove_cnt]print'going to remove',remove_stagesforstageinremove_stages:api.config.stages.dae.url(stage).delete()pprint(api.config.packages.get())
注释
- 仅支持高级筛选器
- 仅支持http basic auth
- 我认为icinga2 api中存在一个bug,当需要操作配置包时,最好只查询一个主机(集群配置主机)。