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_asserts(): #获取所有资产的信息 _asserts = Assets.get_list() _idcs = dict(Assets.get_idcs()) return render_template('asserts.html',asserts=_asserts,_idcs=_idcs)