def oplogs(): query = OperationLog.query filterForm = OplogFilterForm(formdata=request.args) keyword = filterForm.keyword.data if keyword and keyword != '': keyword = keyword.strip() query = query.filter(db.or_( OperationLog.terminal_ip.ilike('%'+keyword+'%'), OperationLog.summary.ilike('%'+keyword+'%'))) user = filterForm.uid.data if user : query = query.filter(OperationLog.uid == user.id) ip = filterForm.ip.data if ip: query = query.filter(OperationLog.terminal_ip == ip) start_date = filterForm.start_date.data if start_date: query = query.filter(OperationLog.created_at >= start_date) end_date = filterForm.end_date.data if end_date: query = query.filter(OperationLog.created_at <= end_date) table = make_table(query, OperationLogTable) return render_template('/system/oplogs.html', table=table, filterForm=filterForm)
def authenticate(clazz, login, passwd): user = clazz.query.filter(db.or_(User.username == login, User.email == login)).first() if user: authenticated = user.check_passwd(passwd) else: authenticated = False return user, authenticated
def classes(): query = AlarmClass.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': query = query.filter(db.or_(AlarmClass.name.ilike('%'+keyword+'%'), AlarmClass.alias.ilike('%'+keyword+'%'))) table = make_table(query, AlarmClassTable) return render_template("/alarms/classes/index.html", table=table, filterForm=form)
def users(): query = User.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': kw = '%' + keyword + '%' query = query.filter(db.or_(User.name.ilike(kw), User.email.ilike(kw), User.role.has(Role.name.ilike(kw)))) table = make_table(query, UserTable) return render_template('users/index.html', table=table, form=form)
def modules(): form = SearchForm(formdata=request.args) cls, table_cls = Module, ModuleTable query = cls.query if form.keyword.data: ikeyword = '%' + form.keyword.data + '%' query = query.filter(db.or_(cls.name.ilike(ikeyword), cls.alias.ilike(ikeyword))) table = make_table(query, table_cls) return render_template('admin/modules/index.html', table = table, form=form)
def users(): query = User.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': kw = '%' + keyword + '%' query = query.filter( db.or_(User.name.ilike(kw), User.email.ilike(kw), User.role.has(Role.name.ilike(kw)))) table = make_table(query, UserTable) return render_template('users/index.html', table=table, form=form)
def timeperiods(): query = TimePeriod.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': ikeyword = '%' + keyword + '%' query = query.filter(db.or_(TimePeriod.name.ilike(ikeyword), TimePeriod.alias.ilike(ikeyword))) table = make_table(query, TimePeriodTable) return render_template('/system/timeperiods/index.html', filterForm = form, table=table)
def monitors(): form = SearchForm(formdata=request.args) cls, table_cls = Monitor, MonitorTable query = cls.query if form.keyword.data: ikeyword = '%' + form.keyword.data + '%' query = query.filter(db.or_(cls.category.ilike(ikeyword), cls.vendor.ilike(ikeyword), cls.remark.ilike(ikeyword))) table = make_table(query, table_cls) return render_template('admin/monitors/index.html', table = table, form=form)
def permissions(): form = SearchForm(formdata=request.args) cls, table_cls = Permission, PermissionTable query = cls.query if form.keyword.data: ikeyword = '%' + form.keyword.data + '%' query = query.filter(db.or_(cls.endpoint.ilike(ikeyword), cls.name.ilike(ikeyword), cls.operation.ilike(ikeyword))) table = make_table(query, table_cls) return render_template('admin/permissions/index.html', table = table, form=form)
def seclogs(): query = SecurityLog.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': keyword = keyword.strip() query = query.filter(db.or_( SecurityLog.terminal_ip.ilike('%'+keyword+'%'), SecurityLog.user.has(User.username.ilike('%'+keyword+'%')))) table = make_table(query, SecurityLogTable) return render_template('/system/seclogs.html', filterForm=form, table=table)
def metrics(): query = Metric.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': ikeyword = '%' + keyword + '%' query = query.filter(db.or_(Metric.name.ilike(ikeyword), Metric.grp.ilike(ikeyword), Metric.alias.ilike(ikeyword))) table = make_table(query, MetricTable) return render_template('system/metrics/index.html', filterForm=form, table=table)
def sysoids(): form = SearchForm(formdata=request.args) cls, table_cls = SysOid, SysOidTable query = cls.query if form.keyword.data: ikeyword = '%' + form.keyword.data + '%' query = query.filter(db.or_(cls.sysoid.ilike(ikeyword), cls.disco.ilike(ikeyword), cls.mib.ilike(ikeyword), cls.remark.ilike(ikeyword))) table = make_table(query, table_cls) return render_template('admin/sysoids/index.html', table = table, form=form)
def thresholds(): query = Threshold.query form = SearchForm(formdata=request.args) keyword = form.keyword.data if keyword and keyword != '': ikeyword = '%' + keyword + '%' query = query.filter(db.or_(Threshold.name.ilike(ikeyword), Threshold.alias.ilike(ikeyword), Threshold.category.has(Category.alias.ilike(ikeyword)), Threshold.summary.ilike(ikeyword))) table = make_table(query, ThresholdTable) return render_template("system/thresholds/index.html", filterForm = form, table=table)
def miboids(mib=None): form = SearchForm(formdata=request.args) cls, table_cls = Miboid, MiboidTable mib = cls.query.first().mib if not mib else mib if not mib: abort(404) query = cls.query.filter_by(mib=mib) if form.keyword.data: ikeyword = '%' + form.keyword.data + '%' query = query.filter(db.or_(cls.name.ilike(ikeyword), cls.alias.ilike(ikeyword))) table = make_table(query, table_cls) kwargs = { 'menuid' : mib, 'form' : form, 'table' : table, 'mib' : mib, } return render_template("admin/miboids/index.html", **kwargs)
def alarm_filter(cls, query, form): """告警过滤""" severity = form.alarm_severity.data if severity is not None: query = query.filter(cls.severity == severity.id) alarm_class = form.alarm_class.data if alarm_class: query = query.filter(cls.class_id == alarm_class.id) start_date = form.start_date.data if start_date: query = query.filter(cls.first_occurrence >= start_date) end_date = form.end_date.data if end_date: query = query.filter(cls.first_occurrence <= end_date) keyword = form.keyword.data if keyword and keyword != '': query = query.filter(db.or_( cls.alarm_alias.ilike('%'+keyword+'%'), cls.node.has(Node.addr.ilike('%'+keyword+'%')), cls.node.has(Node.alias.ilike('%'+keyword+'%')))) return query