zabbix二次开发之批量添加web监控
2016-02-26 18:37
507 查看
zabbix 添加web监控始终是大问题,不能自动发现只能手动添加
写了个py脚本
写了个py脚本
#!/usr/bin/env python # -*- coding: utf-8 -*- import json import urllib2 import sys class zabbixtools: def __init__(self): self.url = "Zabbixserver" self.header = {"Content-Type": "application/json"} self.authID = self.user_login() def user_login(self): data = json.dumps( { "jsonrpc": "2.0", "method": "user.login", "params": { "user": "USER", "password": "PASSWORD" }, "id": 0 }) request = urllib2.Request(self.url,data) for key in self.header: request.add_header(key,self.header[key]) try: result = urllib2.urlopen(request) except URLError as e: print "Auth Failed, Please Check Your Name And Password:",e.code else: response = json.loads(result.read()) result.close() authID = response['result'] return authID def get_data(self,data,hostip=""): request = urllib2.Request(self.url,data) for key in self.header: request.add_header(key,self.header[key]) try: result = urllib2.urlopen(request) except URLError as e: if hasattr(e, 'reason'): print 'We failed to reach a server.' print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The server could not fulfill the request.' print 'Error code: ', e.code return 0 else: response = json.loads(result.read()) result.close() return response def host_create(self): data = json.dumps( { "jsonrpc": "2.0", "method": "httptest.create", "params": { "hostid": "10788", "name": "Homepage", "steps": [ { "name": "1", "url": "http://mycompany.com", "no": 1 } ] }, "auth": self.authID, "id": 1, }) res = self.get_data(data) print res def main(): test = zabbixtools() test.host_create() if __name__ == "__main__": main()
相关文章推荐
- Linux基础命令(1)
- tomcat相关
- opencv split 报错
- Linux之V4L2基础编程
- Linux之vi命令
- linux学习路线
- Linux基础
- 室内定位值得参考的网站
- linux系统创建SFTP用户及设置其chroot权限
- shell 脚本格式化输出
- openwrt tftp 烧录openwrt-ramips-mt7628-mt7628-squashfs-sysupgrade.bin
- 深入浅出node.js游戏服务器开发1——基础架构与框架介绍
- 使用golang来设计我们的Ubuntu Scope
- UVA Open Credit System 11078 (技巧求区间最大值) 好题
- centos6.6-zabbix2.4.5安装实战
- maven 查询网站
- 【手把手教你全文检索】Apache Lucene初探
- eclipse中启动tomcat的问题
- linux 命令c语言代码实现
- tomcat 5.5 动态加载类