def delete_asset(): _id = request.args.get('id') _asset,_error = Assets.get_by_id(_id=_id) if not _asset: _error = '资产不存在' else: _session_username = session['user']['username'] if User.check_is_admin(_session_username): Assets.delete(_id) flash("删除成功") else: flash('权限不够,只有管理员才能删除资产信息!') return redirect('/asserts/')
def monitor_inspace(): _id = request.args.get('id', '') _asset = Assets.get_by_key(_id) print _asset datetime_list, cpu_list, ram_list = Performs.get_list(_asset['ip']) # datetime_list = ['2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50','2016-7-10 19:16:50', '2016-7-10 19:16:50', '2016-7-10 19:16:50'] # cpu_list = [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] # ram_list = [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] return render_template('asserts_perform.html', datetime_list=json.dumps(datetime_list), cpu_list=json.dumps(cpu_list), ram_list=json.dumps(ram_list))
def add_asserts(): _sn = request.form.get('sn','') _ip = request.form.get('ip','') _hostname = request.form.get('hostname','') _os = request.form.get('os','') _cpu = request.form.get('cpu') _ram = request.form.get('ram') _disk = request.form.get('disk') _idc_id = request.form.get('idc_id') _admin = request.form.get('admin','') _business = request.form.get('business','') _purchase_date = request.form.get('purchase_date') _warranty = request.form.get('warranty') _vendor = request.form.get('vendor','') _model = request.form.get('model','') print request.form print "sn is %s,_idc_id is %s,_purchase_date is %s" %(_sn,_idc_id,_purchase_date) print _cpu _is_ok, _error = Assets.validate_create(_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_warranty,_vendor,_model) if _is_ok: Assets.create(_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_warranty,_vendor,_model) return json.dumps({'is_ok':_is_ok, 'error':_error, 'success':'添加成功'})
def modify_asset(): #获取表单上修改后的信息 _id = request.form.get('serverid','') _sn = request.form.get('sn','') _ip = request.form.get('ip','') _hostname = request.form.get('hostname','') _os = request.form.get('os','') _cpu = request.form.get('cpu') _ram = request.form.get('ram') _disk = request.form.get('disk') _idc_id = request.form.get('idc_id') _admin = request.form.get('admin','') _business = request.form.get('business','') _purchase_date = request.form.get('purchase_date') _warranty = request.form.get('warranty') _vendor = request.form.get('vendor','') _model = request.form.get('model','') print "id is %s,sn is %s,_idc_id is %s,_purchase_date is %s,_ram is %s" %(_id,_sn,_idc_id,_purchase_date,_ram) _is_ok, _error = Assets.validate_update(_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_warranty,_vendor,_model) print _is_ok if _is_ok: #print "hello" Assets.update(_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_warranty,_vendor,_model,_id) return json.dumps({'is_ok':_is_ok, 'error':_error, 'success':'更新成功'})
def monitor(): # _ip_list = ['192.168.1.35'] _assets = Assets.get_list() _title = 'CPU、内存告警' for _ast in _assets: _ip = _ast['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: sendmail(alarm_revices, _title, ','.join(_content_list)) logger.info('send mail to:%s ,title:%s ,msg:%s', alarm_revices, _title, ','.join(_content_list))
def get_asset_by_id(id): _rt,_error = Assets.get_by_id(id) return json.dumps(_rt,cls=ComplexEncoder)
def create_asserts(): _idcs = Assets.get_idcs() print _idcs return render_template('assert_create.html',idcs=_idcs)
def get_asserts(): #获取所有资产的信息 _asserts = Assets.get_list() _idcs = dict(Assets.get_idcs()) return render_template('asserts.html',asserts=_asserts,_idcs=_idcs)