예제 #1
0
    def update_expression(cls, expression_id, content, func, op, right_value,
                          uic_groups, max_step, priority, note, url, callback,
                          before_callback_sms, before_callback_mail,
                          after_callback_sms, after_callback_mail):
        e = Expression.get(expression_id)
        if not e:
            return 'no such expression %s' % expression_id

        a = Action.get(e.action_id)
        if not a:
            return 'no relation action'

        Action.update_dict(
            {
                'uic': uic_groups,
                'url': url,
                'callback': callback,
                'before_callback_sms': before_callback_sms,
                'before_callback_mail': before_callback_mail,
                'after_callback_sms': after_callback_sms,
                'after_callback_mail': after_callback_mail
            }, 'id=%s', [a.id])

        Expression.update_dict(
            {
                'expression': content,
                'func': func,
                'op': op,
                'right_value': right_value,
                'max_step': max_step,
                'priority': priority,
                'note': note,
            }, 'id=%s', [e.id])
        return ''
예제 #2
0
파일: api.py 프로젝트: masanmu/portal
def api_action_get(action_id):
    action_id = int(action_id)
    a = Action.get(action_id)
    if not a:
        return jsonify(msg="no such action")

    return jsonify(msg='', data=a.to_json())
예제 #3
0
def api_action_get(action_id):
    action_id = int(action_id)
    a = Action.get(action_id)
    if not a:
        return jsonify(msg="no such action")

    return jsonify(msg='', data=a.to_json())
예제 #4
0
    def insert_expression(cls, content, func, op, right_value, uic_groups, max_step, priority, note, url,
                          callback, before_callback_sms, before_callback_mail,
                          after_callback_sms, after_callback_mail, user_name):
        action_id = Action.insert({
            'uic': uic_groups,
            'url': url,
            'callback': callback,
            'before_callback_sms': before_callback_sms,
            'before_callback_mail': before_callback_mail,
            'after_callback_sms': after_callback_sms,
            'after_callback_mail': after_callback_mail,
        })

        if not action_id:
            return 'save action fail'

        expression_id = Expression.insert({
            'expression': content,
            'func': func,
            'op': op,
            'right_value': right_value,
            'max_step': max_step,
            'priority': priority,
            'note': note,
            'action_id': action_id,
            'create_user': user_name
        })

        if expression_id:
            return ''

        return 'save expression fail'
예제 #5
0
def expression_add_get():
    g.menu = 'expressions'
    a = None
    o = Expression.get(int(request.args.get('id', '0').strip()))
    if o:
        a = Action.get(o.action_id)
    return render_template('expression/add.html',
                           data={'action': a, 'expression': o, 'uic_address': UIC_ADDRESS['external']})
예제 #6
0
파일: template.py 프로젝트: chuanxd/portal
def template_action_update_post(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    uic = request.form['uic'].strip()
    url = request.form['url'].strip()
    callback = request.form['callback'].strip()
    before_callback_sms = request.form['before_callback_sms'].strip()
    before_callback_mail = request.form['before_callback_mail'].strip()
    after_callback_sms = request.form['after_callback_sms'].strip()
    after_callback_mail = request.form['after_callback_mail'].strip()

    if t.action_id > 0:
        # update
        Action.update_dict(
            {
                'uic': uic,
                'url': url,
                'callback': callback,
                'before_callback_sms': before_callback_sms,
                'before_callback_mail': before_callback_mail,
                'after_callback_sms': after_callback_sms,
                'after_callback_mail': after_callback_mail
            },
            'id=%s',
            [t.action_id]
        )
    else:
        # insert
        action_id = Action.insert({
            'uic': uic,
            'url': url,
            'callback': callback,
            'before_callback_sms': before_callback_sms,
            'before_callback_mail': before_callback_mail,
            'after_callback_sms': after_callback_sms,
            'after_callback_mail': after_callback_mail
        })
        if action_id <= 0:
            return jsonify(msg='insert action fail')

        Template.update_dict({'action_id': action_id}, 'id=%s', [t.id])
    return jsonify(msg='')
예제 #7
0
def template_delete_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    if not t.writable(g.user_name):
        return jsonify(msg='no permission')

    Template.delete_one(tpl_id)
    action_id = t.action_id
    if action_id:
        Action.delete_one(action_id)

    Strategy.delete('tpl_id = %s', [tpl_id])

    GrpTpl.unbind_tpl(tpl_id)
    return jsonify(msg='')
예제 #8
0
파일: template.py 프로젝트: chuanxd/portal
def template_delete_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    if not t.writable(g.user_name):
        return jsonify(msg='no permission')

    Template.delete_one(tpl_id)
    action_id = t.action_id
    if action_id:
        Action.delete_one(action_id)

    Strategy.delete('tpl_id = %s', [tpl_id])

    GrpTpl.unbind_tpl(tpl_id)
    return jsonify(msg='')
예제 #9
0
def expression_view_get(eid):
    eid = int(eid)
    g.menu = 'expressions'
    a = None
    o = Expression.get(eid)
    if o:
        a = Action.get(o.action_id)
    else:
        return 'no such expression'
    return render_template('expression/view.html', data={'action': a, 'expression': o})
예제 #10
0
def expression_view_get(eid):
    eid = int(eid)
    g.menu = "expressions"
    a = None
    o = Expression.get(eid)
    if o:
        a = Action.get(o.action_id)
    else:
        return "no such expression"
    return render_template("expression/view.html", data={"action": a, "expression": o}, config=config)
예제 #11
0
def template_action_update_post(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    uic = request.form['uic'].strip()
    url = request.form['url'].strip()
    callback = request.form['callback'].strip()
    before_callback_sms = request.form['before_callback_sms'].strip()
    before_callback_mail = request.form['before_callback_mail'].strip()
    after_callback_sms = request.form['after_callback_sms'].strip()
    after_callback_mail = request.form['after_callback_mail'].strip()

    if t.action_id > 0:
        # update
        Action.update_dict(
            {
                'uic': uic,
                'url': url,
                'callback': callback,
                'before_callback_sms': before_callback_sms,
                'before_callback_mail': before_callback_mail,
                'after_callback_sms': after_callback_sms,
                'after_callback_mail': after_callback_mail
            }, 'id=%s', [t.action_id])
    else:
        # insert
        action_id = Action.insert({
            'uic': uic,
            'url': url,
            'callback': callback,
            'before_callback_sms': before_callback_sms,
            'before_callback_mail': before_callback_mail,
            'after_callback_sms': after_callback_sms,
            'after_callback_mail': after_callback_mail
        })
        if action_id <= 0:
            return jsonify(msg='insert action fail')

        Template.update_dict({'action_id': action_id}, 'id=%s', [t.id])
    return jsonify(msg='')
예제 #12
0
def expression_add_get():
    g.menu = "expressions"
    a = None
    o = Expression.get(int(request.args.get("id", "0").strip()))
    if o:
        a = Action.get(o.action_id)
    return render_template(
        "expression/add.html",
        data={"action": a, "expression": o, "uic_address": UIC_ADDRESS["external"]},
        config=config,
    )
예제 #13
0
def template_update_get(tpl_id):
    g.menu = 'templates'
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    t.parent = Template.get(t.parent_id)
    ss = Strategy.select_vs(where='tpl_id = %s', params=[tpl_id], order='metric')
    t.action = Action.get(t.action_id)
    return render_template('template/update.html', data={'tpl': t, 'ss': ss, 'uic': UIC_ADDRESS['external']})
예제 #14
0
def expression_add_get():
    g.menu = 'expressions'
    a = None
    o = Expression.get(int(request.args.get('id', '0').strip()))
    if o:
        a = Action.get(o.action_id)
    return render_template('expression/add.html',
                           data={
                               'action': a,
                               'expression': o,
                               'uic_address': UIC_ADDRESS['external']
                           })
예제 #15
0
파일: expression.py 프로젝트: Cepave/portal
    def update_expression(cls, expression_id, content, func, op, right_value, uic_groups, max_step, priority, note, url,
                          callback, before_callback_sms, before_callback_mail,
                          after_callback_sms, after_callback_mail):
        e = Expression.get(expression_id)
        if not e:
            return 'no such expression %s' % expression_id

        a = Action.get(e.action_id)
        if not a:
            return 'no relation action'

        Action.update_dict(
            {
                'uic': uic_groups,
                'url': url,
                'callback': callback,
                'before_callback_sms': before_callback_sms,
                'before_callback_mail': before_callback_mail,
                'after_callback_sms': after_callback_sms,
                'after_callback_mail': after_callback_mail
            },
            'id=%s',
            [a.id]
        )

        Expression.update_dict(
            {
                'expression': content,
                'func': func,
                'op': op,
                'right_value': right_value,
                'max_step': max_step,
                'priority': priority,
                'note': note,
            },
            'id=%s',
            [e.id]
        )
        return ''
예제 #16
0
def expression_view_get(eid):
    eid = int(eid)
    g.menu = 'expressions'
    a = None
    o = Expression.get(eid)
    if o:
        a = Action.get(o.action_id)
    else:
        return 'no such expression'
    return render_template('expression/view.html',
                           data={
                               'action': a,
                               'expression': o
                           })
예제 #17
0
def template_delete_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    data = {'templateId': tpl_id}
    alarmAdUrl = config.JSONCFG['shortcut'][
        'falconUIC'] + "/api/v1/alarmadjust/whentempletedeleted"
    if not t:
        return jsonify(msg='no such template')

    if not t.writable(g.user_name):
        return jsonify(msg='no permission')

    Template.delete_one(tpl_id)
    action_id = t.action_id
    if action_id:
        Action.delete_one(action_id)

    Strategy.delete('tpl_id = %s', [tpl_id])

    GrpTpl.unbind_tpl(tpl_id)
    respCode = post2FeUpdateEventCase(alarmAdUrl, data)
    if respCode != 200:
        log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data))
    return jsonify(msg='')
예제 #18
0
def expressions_get():
    g.menu = "expressions"
    page = int(request.args.get("p", 1))
    limit = int(request.args.get("limit", 6))
    query = request.args.get("q", "").strip()
    mine = request.args.get("mine", "1")
    me = g.user_name if mine == "1" else None
    vs, total = Expression.query(page, limit, query, me)
    for v in vs:
        v.action = Action.get(v.action_id)
    return render_template(
        "expression/list.html",
        data={"vs": vs, "total": total, "query": query, "limit": limit, "page": page, "mine": mine},
        config=config,
    )
예제 #19
0
def template_update_get(tpl_id):
    g.menu = 'templates'
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    t.parent = Template.get(t.parent_id)
    ss = Strategy.select_vs(where='tpl_id = %s',
                            params=[tpl_id],
                            order='metric')
    t.action = Action.get(t.action_id)
    return render_template('template/update.html',
                           data={
                               'tpl': t,
                               'ss': ss,
                               'uic': UIC_ADDRESS['external']
                           })
예제 #20
0
def expressions_get():
    g.menu = 'expressions'
    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 6))
    query = request.args.get('q', '').strip()
    mine = request.args.get('mine', '1')
    me = g.user_name if mine == '1' else None
    vs, total = Expression.query(page, limit, query, me)
    for v in vs:
        v.action = Action.get(v.action_id)
    return render_template('expression/list.html',
                           data={
                               'vs': vs,
                               'total': total,
                               'query': query,
                               'limit': limit,
                               'page': page,
                               'mine': mine,
                           })
예제 #21
0
def expressions_get():
    g.menu = 'expressions'
    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 6))
    query = request.args.get('q', '').strip()
    mine = request.args.get('mine', '1')
    me = g.user_name if mine == '1' else None
    vs, total = Expression.query(page, limit, query, me)
    for v in vs:
        v.action = Action.get(v.action_id)
    return render_template(
        'expression/list.html',
        data={
            'vs': vs,
            'total': total,
            'query': query,
            'limit': limit,
            'page': page,
            'mine': mine,
        }
    )