使用python的zabbix_api模块

使用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

#/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

时间: 2024-08-03 12:38:43

使用python的zabbix_api模块的相关文章

Python中subprocess 模块 创建并运行一个进程

python的subprocess模块,看到官方声明里说要尽力避免使用shell=True这个参数,于是测试了一下: from subprocess import call import shlex cmd = "cat test.txt; rm test.txt" call(cmd, shell=True) 运行之后: 1:打开并浏览了test.txt文件 2:删除了test.txt文件 from subprocess import call import shlex cmd = &

python时间处理模块 datetime time模块 deltetime模块

1 首先介绍time模块,因为简单 python 自带模块 本人使用time模块,只使用两个函数 time函数和sleep函数 import time a.     time.time()   函数 返回unix时间  常用作两个时间差的计算 b.     time.sleep()  休眠多久,精度为子秒(subsecond) In [90]: t1 = time.time() In [91]: t1 Out[91]: 1461400225.877932 In [92]: time.sleep(

python安装mysqldb模块

今天在阿里云一台新的服务器部署程序后台,发现上面的python缺少MySQLDB 模块,记录安装过程. 首先django程序,运行 python manage.py sycdb 报错: ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb MySQLdb模块的包名字叫mysql-python,于是pip安装之,(关于pip,可以参考这篇文章) 运行: pip install mysql-python

Python 利用pytesser模块识别图像文字

使用的是python的pytesser模块,原先想做的是图片中文识别,搞了一段时间了,在中文的识别上还是有很多问题,这里做记录分享. pytesser,OCR in Python using the Tesseract engine from Google.是谷歌OCR开源项目的一个模块,可将图片中的文字转换成文本(主要是英文). 1.pytesser安装 使用设备:win8 64位 PyTesser使用Tesseract OCR引擎,将图像转换到可接受的格式,然后执行tesseract提取出文

python学习--创建模块

昨天做了python客户端和服务器端通信,并把接收到的信息写到数据库,因为对数据库进行操作是个经常调用的行为,所以我想把调用数据库的操作写成一个module来给其它python程序调用,所以将昨天的服务器端程序拆分为两个文件: 1.主程序python.py #!/usr/bin/env python import socket import json import connmysql s = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) h

Python中time模块详解

在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主要调用C库,所以各个平台可能有所不同. UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时间.在中国为UTC+8.DST

[ python编程 ] subprocess模块学习总结

转载:http://www.jb51.net/article/48086.htm 从Python 2.4开始,Python引入subprocess模块来管理子进程,以取代一些旧模块的方法:如 os.system.os.spawn*.os.popen*.popen2.*.commands.*不但可以调用外部的命令作为子进程,而且可以连接到子进程的input/output/error管道,获取相关的返回信息. 一.subprocess以及常用的封装函数    运行python的时候,我们都是在创建并

定义一个方法get_page(url),url参数是需要获取网页内容的网址,返回网页的内容。提示(可以了解python的urllib模块)

1 定义一个方法get_page(url),url参数是需要获取网页内容的网址,返回网页的内容.提示(可以了解python的urllib模块) 2 import urllib.request 3 4 def get_page(url): 5 response = urllib.request.urlopen(url) 6 html = response.read() 7 return html 8 9 print(get_page(url='https://www.baidu,com'))

python之OS模块(对文件or目录操作)

OS模块 os,语义为操作系统,包含普遍的操作系统功能,与具体的平台无关.python编程时,处理文件和目录这些操作,就比如说:显示当前目录下所有文件/删除某个文件/获取文件大小-- os模块不受平台限制,也就是说:当我们要在linux中显示当前命令时就要用到pwd命令,而Windows中cmd命令行下就要用到这个,例如:这时候我们使用python中os模块的os.path.abspath(name)功能,甭管是linux或者Windows都可以获取当前的绝对路径. 常见函数列表 os.name