#!/usr/bin/env python
#-*- coding: utf-8 -*-
import json
import urllib2
from urllib2 import urlerror
from login import zabbix_login
t=zabbix_login()
def hostid_get():
data = json.dumps(,},
"auth":t.user_login(),
"id": 1,
})request = urllib2.request(t.url, data)
for key in t.header:
request.add_header(key, t.header[key])
try:
result = urllib2.urlopen(request)
except urlerror as e:
if hasattr(e, 'reason'):
print 'zabbix server is faile'
print 'reason: ', e.reason
elif hasattr(e, 'code'):
print 'zabbix server not request.'
print 'error code: ', e.code
else:
response = json.loads(result.read())
result.close()
hostid=
hostname=
for host in response['result']:
return hostid,hostname
if __name__ == "__main__":
a,b=hostid_get()
i=0n=len(b)
for i in range(n):
print a[i],b[i]
通過python連線Oracle
一 安裝cx oracle pip install cx oracle即可 二 安裝instantclient windows方式 2.環境配置 import os os.environ nls lang simplified chinese china.utf8 os.environ tns ad...
通過python模擬SSH
通過python模擬ssh from time import import paramiko 定義乙個類,表示一台遠端linux主機 class linux object 通過ip,使用者名稱,密碼,超時時間初始化乙個遠端linux主機 def init self,ip,username,passw...
python編輯配置 通過python編輯配置檔案
import re pat re.compile enableprinter printerlist prnt1.port def jojo mat,dic return dic mat.group with open configfile rb as f content f.read f.seek...