def addMonitor(req):
print req.get_full_path()
host=req.GET['monitor_name']
ip=req.GET['monitor_ip']
group=req.GET['group']
temp=req.GET['temp']
a=add_host(host,ip,group,temp)
print '---------------------'
print a
print type(a)
try:
code= a['error']
print '---------------------'
return HttpResponse(code['data'])
except:
return HttpResponse('add success')
/api/addMonitor/?env=pro&temp=10001&group=1&monitor_ip=1.1.1.1&monitor_name=2000
---------------------
{u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'Invalid params.', u'code': -32602, u'data': u'Host with the same name "2000" already exists.'}}
<type 'dict'>
---------------------
[13/Dec/2017 10:42:25] "GET /api/addMonitor/?env=pro&temp=10001&group=1&monitor_ip=1.1.1.1&monitor_name=2000 HTTP/1.1" 200 46
[13/Dec/2017 10:42:35] "GET /api/addMonitor?env=pro&temp=10001&group=1&monitor_ip=1.1.1.1&monitor_name=3000 HTTP/1.1" 301 0
/api/addMonitor/?env=pro&temp=10001&group=1&monitor_ip=1.1.1.1&monitor_name=3000
---------------------
{u'jsonrpc': u'2.0', u'result': {u'hostids': [u'10114']}, u'id': 1}
<type 'dict'>
[13/Dec/2017 10:42:36] "GET /api/addMonitor/?env=pro&temp=10001&group=1&monitor_ip=1.1.1.1&monitor_name=3000 HTTP/1.1" 200 11
zabbix 判断主机添加是否成功
a=[1,2,3,4]
try:
code=a[9]
print '1111111'
except:
print '2222222'
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/templates/a11.py
2222222
a=[1,2,3,4]
try:
code=a[1]
print '1111111'
except:
print '2222222'
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/templates/a11.py
1111111