コード例 #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
ファイル: expression.py プロジェクト: xiaojianwu/open-falcon
    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
ファイル: expression.py プロジェクト: Liuyanglong/portal
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
ファイル: expression.py プロジェクト: Liuyanglong/portal
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
ファイル: expression.py プロジェクト: chuanxd/portal
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
ファイル: expression.py プロジェクト: chuanxd/portal
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
ファイル: expression.py プロジェクト: chuanxd/portal
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
ファイル: expression.py プロジェクト: Liuyanglong/portal
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,
        }
    )