使用python的zabbix_api模块
2016-04-01 18:16
579 查看
使用python的zabbix_api模块,以下是简单的zabbix api的使用
zabbix api文档参考https://www.zabbix.com/documentation/2.2/manual/api/reference
安装zabbix_api模块
easy_install zabbix_api或者pip install zabbix_api安装模块
在zabbix上创建主机:
vim create_host.py
python create_host.py 172.16.133.134 即可将172.16.133.134加入zabbix,host_name为test,visible name为zabbix_test
本文出自 “漂泊的鱼” 博客,请务必保留此出处http://faded.blog.51cto.com/6375932/1759324
zabbix api文档参考https://www.zabbix.com/documentation/2.2/manual/api/reference
安装zabbix_api模块
easy_install zabbix_api或者pip install zabbix_api安装模块
在zabbix上创建主机:
vim create_host.py
#/usr/bin/env python from zabbix_api import ZabbixAPI import sys server = "http://172.16.133.133/zabbix" username = "Admin" password = "zabbix" zapi = ZabbixAPI(server=server, path="", log_level=0) zapi.login(username, password) ip = sys.argv[1] #获取主机组"Linux servers" 的groupid group_id = zapi.hostgroup.get({"output": "extend","filter": {"name": "Linux servers"}})[0]['groupid'] #获取模版"Template OS Linux"的templateid template_id = zapi.template.get({"output": "extend","filter": {"host": "Template OS Linux"}})[0]['templateid'] # 创建主机,加入主机组"Linux servers",链接模版"Template OS Linux" if zapi.host.exists({"host": "test"}): print 'host already exists' else: create_host=zapi.host.create({"host": "test","groups": [{"groupid": group_id}],"interfaces": [{"type": "1","main": "1","us eip": "1","ip": ip,"port": "10050","dns": ""}],"templates": [{"templateid": template_id}],"inventory_mode": -1,"name": "za bbix_test"}) print create_host
python create_host.py 172.16.133.134 即可将172.16.133.134加入zabbix,host_name为test,visible name为zabbix_test
本文出自 “漂泊的鱼” 博客,请务必保留此出处http://faded.blog.51cto.com/6375932/1759324
相关文章推荐
- 学习python单元测试框架nose之---02nose多进程并行测试
- IP地址地理位置接口(python版)
- 学习python单元测试框架nose之---01nose框架初探
- python 多线程
- A Byte of Python 笔记(9) 面向对象编程
- [Java学习] Iterator, foreach, generics and callback in Java, C# and Python
- Python kmean
- Install Python 3.5.1 on Windows
- python文件和目录操作方法大全(含实例)
- python rpyc的应用 ——聊天的功能(带认证)
- Python开发测试工具(一)—Monkey
- python之js/url/python互动
- numpy
- python依赖包numpy、scipy、scikit-learn运行冲突解决方案
- think python学习心得-(6)利用words.txt来进行填字游戏
- Python中的threading
- Spark入门(Python版)
- 安装配置远程ipython notebook
- Spark RDD 的Transformation与Action的常用功能总结(Python版本)
- 机器学习算法的Python实现 (1):logistics回归 与 线性判别分析(LDA)