예제 #1
0
파일: host.py 프로젝트: open-falcon/portal
def group_hosts_list(group_id):
    g.xbox = request.args.get('xbox', '')
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 10))
    query = request.args.get('q', '')
    maintaining = request.args.get('maintaining', '0')
    vs, total = Host.query(page, limit, query, maintaining, group_id)
    return render_template(
        'host/index.html',
        data={
            'vs': vs,
            'total': total,
            'query': query,
            'limit': limit,
            'page': page,
            'maintaining': maintaining,
            'group': group,
        }
    )
예제 #2
0
def host_groups_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 = []
        h = {}
        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] )
            h["id"] = host_id
            h["hostname"] = host_name


    groups = [HostGroup.read('id = %s', [group_id]) for group_id in group_ids]
    return render_template('host/groups.html', groups=groups, host=h)
예제 #3
0
파일: host.py 프로젝트: open-falcon/portal
def host_maintain_post():
    begin = int(request.form['begin'].strip())
    end = int(request.form['end'].strip())
    host_ids = request.form['host_ids'].strip()
    if begin <= 0 or end <= 0:
        return jsonify(msg='begin or end is invalid')

    return jsonify(msg=Host.maintain(begin, end, host_ids))
예제 #4
0
def host_maintain_post():
    begin = int(request.form['begin'].strip())
    end = int(request.form['end'].strip())
    host_ids = request.form['host_ids'].strip()
    if begin <= 0 or end <= 0:
        return jsonify(msg='begin or end is invalid')

    return jsonify(msg=Host.maintain(begin, end, host_ids))
예제 #5
0
파일: api.py 프로젝트: missuzhang/portal
def api_group_hosts_json(grp_name):
    group = HostGroup.read(where='grp_name = %s', params=[grp_name])
    if not group:
        return jsonify(msg='no such group %s' % grp_name)

    vs, _ = Host.query(1, 10000000, '', '0', group.id)
    names = [v.hostname for v in vs]
    return jsonify(msg='', data=names)
예제 #6
0
def host_groups_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)
    groups = [HostGroup.read('id = %s', [group_id]) for group_id in group_ids]
    return render_template('host/groups.html', groups=groups, host=h)
예제 #7
0
파일: host.py 프로젝트: open-falcon/portal
def host_groups_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)
    groups = [HostGroup.read('id = %s', [group_id]) for group_id in group_ids]
    return render_template('host/groups.html', groups=groups, host=h)
예제 #8
0
def api_group_hosts_json(grp_name):
    group = HostGroup.read(where="id = %s", params=[grp_name])
    if not group:
        group = HostGroup.read(where="grp_name = %s", params=[grp_name])
        if not group:
            return jsonify(msg="no such group %s" % grp_name)

    vs, _ = Host.query(1, 10000000, "", "0", group.id)
    names = [v.hostname for v in vs]
    return jsonify(msg="", data=names)
예제 #9
0
def api_group_hosts_json(grp_name):
    group = HostGroup.read(where='id = %s', params=[grp_name])
    if not group:
        group = HostGroup.read(where='grp_name = %s', params=[grp_name])
        if not group:
            return jsonify(msg='no such group %s' % grp_name)

    vs, _ = Host.query(1, 10000000, '', '0', group.id)
    names = [v.hostname for v in vs]
    return jsonify(msg='', data=names)
예제 #10
0
파일: host.py 프로젝트: open-falcon/portal
def group_hosts_export(group_id):
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    vs, _ = Host.query(1, 10000000, '', '0', group_id)
    names = [v.hostname for v in vs]
    response = make_response('\n'.join(names))
    response.headers["content-type"] = "text/plain"
    return response
예제 #11
0
def group_hosts_export(group_id):
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    vs, _ = Host.query(1, 10000000, '', '0', group_id)
    names = [v.hostname for v in vs]
    response = make_response('\n'.join(names))
    response.headers["content-type"] = "text/plain"
    return response
예제 #12
0
파일: host.py 프로젝트: Cepave/portal
def host_maintain_post():
    begin = int(request.form['begin'].strip())
    end = int(request.form['end'].strip())
    host_ids = request.form['host_ids'].strip()
    alarmAdUrl = config.JSONCFG['shortcut']['falconUIC'] + "/api/v1/alarmadjust/whenendpointonmaintain"
    if begin <= 0 or end <= 0:
        return jsonify(msg='begin or end is invalid')
    for host_id in host_ids.split(","):
        data = {'hostId': host_id, 'maintainBegin': begin, 'maintainEnd': end}
        respCode = post2FeUpdateEventCase(alarmAdUrl, data)
        if respCode != 200:
            log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data))
    return jsonify(msg=Host.maintain(begin, end, host_ids))
예제 #13
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())
예제 #14
0
파일: host.py 프로젝트: open-falcon/portal
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())
예제 #15
0
def host_maintain_post():
    begin = int(request.form['begin'].strip())
    end = int(request.form['end'].strip())
    host_ids = request.form['host_ids'].strip()
    alarmAdUrl = config.JSONCFG['shortcut'][
        'falconUIC'] + "/api/v1/alarmadjust/whenendpointonmaintain"
    if begin <= 0 or end <= 0:
        return jsonify(msg='begin or end is invalid')
    for host_id in host_ids.split(","):
        data = {'hostId': host_id, 'maintainBegin': begin, 'maintainEnd': end}
        respCode = post2FeUpdateEventCase(alarmAdUrl, data)
        if respCode != 200:
            log.error(alarmAdUrl + " got " + str(respCode) + " with " +
                      str(data))
    return jsonify(msg=Host.maintain(begin, end, host_ids))
예제 #16
0
def group_hosts_list(group_id):
    g.xbox = request.args.get('xbox', '')
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 10))
    query = request.args.get('q', '')
    maintaining = request.args.get('maintaining', '0')
    if not os.path.exists( str(EXTERNAL_NODES) ):
        vs, total = Host.query(page, limit, query, maintaining, group_id)
    else:
        (status, output) =  commands.getstatusoutput(EXTERNAL_NODES + " GetHostGroup " + group.grp_name + " "+ str(page) + " " + str(limit) )
        vs = []
        total = 0
        if status == 0:
            decodejson = json.loads( output )         
            for i in decodejson:
                node = {}
                node["id"] = i
                node["hostname"] = decodejson[i]
                vs.append(node)
                total = total + 1

    for index in range( len(vs) ):
        vs[index]["maintain_begin"] = group.maintain_begin    
        vs[index]["maintain_end"] = group.maintain_end    

    return render_template(
        'host/index.html',
        data={
            'vs': vs,
            'total': total,
            'query': query,
            'limit': limit,
            'page': page,
            'maintaining': maintaining,
            'group': group,
        }
    )
예제 #17
0
def group_hosts_list(group_id):
    g.xbox = request.args.get('xbox', '')
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 10))
    query = request.args.get('q', '')
    maintaining = request.args.get('maintaining', '0')
    vs, total = Host.query(page, limit, query, maintaining, group_id)
    return render_template('host/index.html',
                           data={
                               'vs': vs,
                               'total': total,
                               'query': query,
                               'limit': limit,
                               'page': page,
                               'maintaining': maintaining,
                               'group': group,
                           })
예제 #18
0
파일: api.py 프로젝트: masanmu/portal
def api_marathon_health():
    marathon_stats = request.get_json()

    if marathon_stats["eventType"] == "deployment_success":
        action_type = marathon_stats["plan"]["steps"][-1]["actions"][-1]["type"]
        app = marathon_stats["plan"]["steps"][-1]["actions"][-1]["app"].lstrip("/")
        if action_type == "StopApplication":
            grp_id = HostGroup.query_grp_id(app)
            if grp_id > 0:
                group_service.delete_group(grp_id)
        else:
            grp_id = HostGroup.create(app,"root",1)
            if grp_id < 0:
                grp_id = HostGroup.query_grp_id(app)
                if grp_id < 0:
                    return 'grp_name no exist'
            import requests,json
            r = requests.get(MARATHON_ADDRESS+"/v2/apps/"+app)
            app_info = json.loads(r.text)
            marathon_hosts = []
            for i in app_info["app"]["tasks"]:
                marathon_hosts.append(i["host"])
            vs,_ = Host.query(1, 10000000, '', '0', grp_id)
            of_names = [v.hostname for v in vs]

            of_names_set = set(of_names)
            marathon_hosts_set = set(marathon_hosts)
            delete_hosts = list(of_names_set - marathon_hosts_set)
            add_hosts = list(marathon_hosts_set - of_names_set)

            for h in add_hosts:
                msg = GroupHost.bind(grp_id,h)
            of_ids = [int(v.id) for v in vs if v.hostname in delete_hosts]
            if len(delete_hosts)>0:
                ids = ",".join('%s' % id for id in of_ids)
                msg = GroupHost.unbind(int(grp_id[0]),ids)
    return 'ok'
예제 #19
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())
예제 #20
0
파일: host.py 프로젝트: open-falcon/portal
def host_reset_post():
    host_ids = request.form['host_ids'].strip()
    return jsonify(msg=Host.no_maintain(host_ids))
예제 #21
0
def host_reset_post():
    host_ids = request.form['host_ids'].strip()
    return jsonify(msg=Host.no_maintain(host_ids))