运维python进行(三) 用python写一个自己zabbix的调用方法
class Zbx_api(object):def zbx_create_host(self,hostname,inter_ip,group_id,temlpate_id):
self.hostname = hostname
self.inter_ip = inter_ip
self.group_id = group_id
self.temlpate_id = temlpate_id
'''创建主机
hostname :主机名
inter_ip :主机IP
gourp_id :组id
template_id : 监控模版id
zbx_create_host('salt-node1','192.168.198.116','4','10001')
'''
zbx_action = 'host.create'
zbx_params = '''{
"host": "%s",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "%s",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "%s"
}
],
"templates": [
{
"templateid": "%s"
}
],
"inventory_mode": 0,
"inventory": {
"macaddress_a": "nginxs.net",
"macaddress_b": "nginxs.net"
}
}''' % (hostname,inter_ip,group_id,temlpate_id)
r=Zbx_base_api(zbx_action,zbx_params)
return r.zbx_req()
页:
[1]