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,当需要操作配置包时,最好只查询一个主机(集群配置主机)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Grid loadmask(true)在gxt中不起作用   java将字符串索引转换为整数   为什么Java泛型适用于基元数组,但不适用于基元数组?   java如何让Azure应用程序服务Tomcat将所有80/443流量转发到运行在同一应用程序服务上的JBoss   具有多个值的java转换映射到树?   java如何设置SQL server连接URL?   java设置了多个相互独立的JFrame   安全性在JAVA中如何使用RSAPrivateKey的密码短语?   java不能使用比Apache Velocity中更大的条件   如何在Java中打印字符串的所有排列   停止Android Studio自动导入java。sql。日期   对象简单计算器程序java   java如何在安卓中使用“&”符号作为字符串?   java Connect,为我的安卓应用程序从REST API发布和获取数据