def asset_update(): if request.method == 'GET': # 返回更新资产模版给dialog页面 _id = request.args.get('aid', '') _asset_list = [] for i in asset.get_list(): if i.get('id') == int(_id): _asset_list.append(i) print asset.get_idc() return render_template('asset/asset_update.html', asset_list=_asset_list, idcs=asset.get_idc()) else: print request.form # POST传过来的数据太多了,我们使用for循环遍历获取所有数据,存放到一个dict中。 lists = ['ip','hostname','idc_id','purchase_date','warranty','vendor','model','admin','business','os','cpu','ram','disk','id'] asset_dict = {} for i in lists: asset_dict['_'+i] = request.form.get(i, '') # 检查资产信息 is_ok, error = asset.validate_update(asset_dict) msg = '' if is_ok: if asset.update(asset_dict): msg = '更新资产成功!' else: msg = '更新资产失败!' return json.dumps({'is_ok': is_ok, 'msg': msg, 'error': error})
def asset_list(): _asset_list = [] for i in asset.get_list(): _rt_list = asset.get_by_id(i.get('idc_id')) i['idc_id'] = _rt_list[0][1] _asset_list.append(i) return render_template('assets.html', asset_list=_asset_list)
def asset_list(): _asset_list = [] for i in asset.get_list(): _rt_list = asset.get_by_id(i.get('idc_id')) i['idc_id'] = _rt_list[0][1] #((2L, u'\u6570\u5317', 0L),) _asset_list.append(i) return render_template('asset/asset_list.html',asset_list=_asset_list)
def edit_asset(): asset_id = request.form.get("asset_id") print '资产ID', asset_id idcs = asset.idcs_list() _asset = asset.get_list(asset_id) print '打印资产', _asset return render_template('asset_update.html', idcs=idcs, asset=_asset[0])
def modify_asset(): index = int(request.args.get('index', '')) _assets = asset.get_list() _idcs = [('1', u'北京-亦庄'), ('2', u'北京-酒仙桥'), ('3', u'北京-西单'), ('4', u'北京-东单')] return render_template('asset_modify.html', idcs=_idcs, asset=_assets[index - 1])
def asset_update(): _id = request.args.get('id', '') _asset_list = [] for i in asset.get_list(): if i.get('id') == int(_id): _asset_list.append(i) return render_template('asset_update.html', asset_list=_asset_list, idcs=asset.get_idc())
def assets(): color, msg = request.args.get('color', ''), request.args.get('msg', '') _assets = asset.get_list() if msg: return render_template('asset.html', assets=_assets, username=session.get('username', ''), privilege=session.get('privilege', ''), color=color, msg=msg) # for i in range(0,len(_assets)): # _assets[i]['purchase_date']=_assets[i]['purchase_date'].strftime("%Y-%m-%d") return render_template('asset.html', assets=_assets, username=session.get('username', ''), privilege=session.get('privilege', ''))
def monitor(): #_ip_list = ['192.168.137.101'] _cnt, _asset_list = asset.get_list() _title = 'CPU&内存告警' for _asset in _asset_list: _ip = _asset['ip'] _cpu_alarm, _ram_alarm = has_alarm(_ip) _content_list = ['主机{ip}告警'.format(ip=_ip)] if _cpu_alarm: _content_list.append('CPU连续 {cnt} 次超过{percent}%'.format( cnt=CNT, percent=CPU_PERCENT)) if _ram_alarm: _content_list.append('内存连续 {cnt} 次超过{percent}%'.format( cnt=CNT, percent=RAM_PERCENT)) # 有报警内容才发送邮件 if len(_content_list) >= 2: # 发送邮件 sendemail(ALARM_RECIVERS, _title, ','.join(_content_list)) logger.info('send mail to:%s, titile: %s, msg:%s', ALARM_RECIVERS, _title, ','.join(_content_list))
def assets(): _assets = asset.get_list() print _assets return render_template('assets.html', assets=_assets)
def assets(): _cnt, _assets = asset.get_list() return render_template('assets.html', assets=_assets, idcs=asset.get_idc_list())
def assets_list(): # return render_template('asset_list.html') # _idcs = asset.get_idcs() # return render_template('asset_create.html',idcs=_idcs) _assets = asset.get_list() return render_template('asset_list.html',assets=_assets)
def assets(): assets = asset.get_list() return render_template('assets.html', assets=assets)