def check(): file = applog.Applog() file.addLog("##################start check#######################") check_ids = request.get_json() hostinfos = [] for check_id in check_ids: host = Host.query.get_or_404(check_id['host_id']) hostinfo = { 'id': host.id, 'role': host.role, 'ip': host.ip, 'status': 'OK', 'sshPort': host.ssh_port, 'sshUser': host.ssh_user, 'sshPassword': host.ssh_passwd, 'httpPort': host.http_port, 'httpUser': host.http_user, 'httpPassword': host.http_passwd, 'check_item': check_id['cas_define_check_id'] } hostinfos.append(hostinfo) data = {} if not hostinfos: data['data'] = "未添加设备" else: text = hostStatusCheck(hostinfos) if text: data['data'] = "巡检结果:" + str(text) else: result = Check(hostinfos) record(result) data['data'] = "巡检结果:" + "巡检完成" file.addLog("##################end check#######################") file.closeLofile() return json.dumps(data)
from requests.auth import HTTPDigestAuth import xmltodict, requests from shell.Cas3Data import Cas3Data from shell import applog logfile = applog.Applog() class Cas5Data(Cas3Data): def cvkVswitch(self, cvk): if cvk['status'] == '1': response = requests.get(self.url + 'host/id/' + cvk['id'] + '/vswitch', cookies=self.cookies) contxt1 = response.text response.close() dict2 = xmltodict.parse(contxt1) # print(dict2) li = [] if 'list' in dict2.keys(): # 5.0为host dict1 = dict2['list'] else: return li temp = [] if isinstance(dict1, dict): if isinstance(dict1['vSwitch'], dict): temp.append(dict1['vSwitch']) else: temp = dict1['vSwitch'].copy() for h in temp: temp1 = {} temp1['name'] = h['name']