示例#1
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']})
示例#2
0
文件: api.py 项目: masanmu/portal
def api_template_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such tpl')

    return jsonify(msg='', data=t.to_json())
示例#3
0
def api_template_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such tpl')

    return jsonify(msg='', data=t.to_json())
示例#4
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']
                           })
示例#5
0
def template_fork_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    new_id = t.fork(g.user_name)
    if new_id == -1:
        return jsonify(msg='name[copy_of_%s] has already existent' % t.tpl_name)
    return jsonify(msg='', id=new_id)
def template_fork_get(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    new_id = t.fork(g.user_name)
    if new_id == -1:
        return jsonify(msg='name[copy_of_%s] has already existent' %
                       t.tpl_name)
    return jsonify(msg='', id=new_id)
示例#7
0
def host_templates_get(host_id):
    host_id = int(host_id)

    h = Host.read('id = %s', params=[host_id])
    if not h:
        return jsonify(msg='no such host')

    group_ids = GroupHost.group_ids(h.id)

    templates = GrpTpl.tpl_set(group_ids)
    for v in templates:
        v.parent = Template.get(v.parent_id)
    return render_template('host/templates.html', config=config, **locals())
示例#8
0
def host_templates_get(host_id):
    host_id = int(host_id)

    h = Host.read('id = %s', params=[host_id])
    if not h:
        return jsonify(msg='no such host')

    group_ids = GroupHost.group_ids(h.id)

    templates = GrpTpl.tpl_set(group_ids)
    for v in templates:
        v.parent = Template.get(v.parent_id)
    return render_template('host/templates.html', **locals())
示例#9
0
def template_rename_post(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    name = request.form['name'].strip()
    parent_id = request.form.get('parent_id', '')
    if not parent_id:
        parent_id = 0

    Template.update_dict({'tpl_name': name, 'parent_id': parent_id}, 'id=%s', [tpl_id])
    return jsonify(msg='')
示例#10
0
def template_binds_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')

    groups = GrpTpl.grp_list(tpl_id)
    return render_template('template/groups.html', data={
        "gs": groups,
        "tpl": t,
        "uic_address": UIC_ADDRESS['external'],
    })
示例#11
0
def template_binds_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')

    groups = GrpTpl.grp_list(tpl_id)
    return render_template('template/groups.html',
                           data={
                               "gs": groups,
                               "tpl": t,
                               "uic_address": UIC_ADDRESS['external'],
                           })
示例#12
0
文件: api.py 项目: modeyang/portal
def api_strategies_by_tpl(tpl_id):
    tpls = []
    while True:
        t = Template.get(tpl_id)
        if t is None:
            break
        tpls.append(tpl_id)
        tpl_id = t.parent_id

    strategies = []
    for tpl_id in tpls:
        strategies.extend(Strategy.get_by_tpl(tpl_id))
    strategies = filter(lambda x: x is not None, strategies)
    if len(strategies) == 0:
        return jsonify(msg='can not get strategies by template id:%s' % tpl_id)
    return jsonify(msg='', data=[ss.to_json() for ss in strategies])
def template_rename_post(tpl_id):
    tpl_id = int(tpl_id)
    t = Template.get(tpl_id)
    if not t:
        return jsonify(msg='no such template')

    name = request.form['name'].strip()
    parent_id = request.form.get('parent_id', '')
    if not parent_id:
        parent_id = 0

    Template.update_dict({
        'tpl_name': name,
        'parent_id': parent_id
    }, 'id=%s', [tpl_id])
    return jsonify(msg='')
示例#14
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='')
示例#15
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='')
示例#16
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='')
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='')
示例#18
0
def templates_get():
    g.menu = 'templates'
    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 10))
    query = request.args.get('q', '').strip()
    mine = request.args.get('mine', '1')
    me = g.user_name if mine == '1' else None
    vs, total = Template.query(page, limit, query, me)
    for v in vs:
        v.parent = Template.get(v.parent_id)
    return render_template('template/list.html',
                           data={
                               'vs': vs,
                               'total': total,
                               'query': query,
                               'limit': limit,
                               'page': page,
                               'mine': mine,
                               'uic_address': UIC_ADDRESS['external'],
                           })
示例#19
0
def templates_get():
    g.menu = 'templates'
    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 10))
    query = request.args.get('q', '').strip()
    mine = request.args.get('mine', '1')
    me = g.user_name if mine == '1' else None
    vs, total = Template.query(page, limit, query, me)
    for v in vs:
        v.parent = Template.get(v.parent_id)
    return render_template(
        'template/list.html',
        data={
            'vs': vs,
            'total': total,
            'query': query,
            'limit': limit,
            'page': page,
            'mine': mine,
            'uic_address': UIC_ADDRESS['external'],
        }
    )
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='')
示例#21
0
def host_templates_get(host_id, host_name):

    if not os.path.exists( str(EXTERNAL_NODES) ):
        host_id = int(host_id)
        h = Host.read('id = %s', params=[host_id])
        if not h:
            return jsonify(msg='no such host')
        group_ids = GroupHost.group_ids(h.id)
    else:
        (status, output) =  commands.getstatusoutput(EXTERNAL_NODES + " GetHostGroupByHost " + host_id )
        group_ids = []
        if status == 0:
            decodejson = json.loads( output )         
            gname = "1"
            for i in decodejson:
                gname = gname + ",'" + decodejson[i] + "'"
            groupMsg = HostGroup.select(cols="id,grp_name", where="grp_name in (%s)" % gname)
            for m in groupMsg:
                group_ids.append( m[0] )

    templates = GrpTpl.tpl_set(group_ids)
    for v in templates:
        v.parent = Template.get(v.parent_id)
    return render_template('host/templates.html', **locals())