Example #1
0
def overview(request):
    context = {}
    context.update(csrf(request))
    grains = salt_api.overview(request).values()
    minions_os = {}
    minions_virtual = {}
    for grain in grains:
        try:
            minions_os[grain["osfullname"] + grain["osrelease"]] += 1
            minions_virtual[grain["virtual"]] += 1
        except KeyError:
            minions_os[grain["osfullname"] + grain["osrelease"]] = 1
            minions_virtual[grain["virtual"]] = 1
    try:
        cursor = connection.cursor()
        host_num = cursor.execute(
            "select id,fun,time,success from  \
		(select id,fun,time,success from salt.salt_returns where \
		success='0' order by id desc) as b group by id limit 10;"
        )
        hosts = cursor.fetchall()
        error_host = []
        for host in hosts:
            error_host.append({"id": host[0], "fun": host[1], "time": host[2], "success": host[3]})
    except:
        error_host = []

    context["minions_os"] = minions_os
    context["minions_virtual"] = minions_virtual
    context["minions_num"] = len(grains)
    context["error_host"] = error_host
    return render_to_response("auto_overview.html", context)
Example #2
0
def minions(request):
    current_page = int(request.GET.get("page", 0))
    page_sum = 15
    page_extra = 3
    grains = salt_api.overview(request).values()
    try:
        cursor = connection.cursor()
        host_num = cursor.execute(
            "select host_id,time from \
            (select host_id,time from fluent.salt_result order \
            by id desc ) as b group by host_id;"
        )
        hosts_time = cursor.fetchall()
        now = datetime.datetime.now()
        times_diff = {}
        for host_time in hosts_time:
            time_dist = now - host_time[1]
            times_diff[host_time[0]] = str(time_dist).split(".")[0]
    except:
        times_diff = {}
    for grain in grains:
        grain["IP"] = grain["id"].split(".")[0].replace("_", ".")
        grain["time_diff"] = times_diff.get(grain["id"], "无")
    context = common.my_page(request, len(grains))
    context["page_tables"] = grains[current_page * page_sum : (current_page + 1) * page_sum]
    return render_to_response("auto_minions.html", context)
Example #3
0
def detail(request):
    target = request.GET.get("target", "")
    if target:
        grain = salt_api.overview(request)
        state = salt_api.get_state(target)
    state = repr(json.dumps(state, sort_keys=True, indent=4))
    state = state.replace("\\n", "<br/>").replace(" ", "&nbsp;")
    context = {"grain": grain, "state": state}
    return render_to_response("auto_detail.html", context)
Example #4
0
def detail(request):
    target = request.GET.get('target','')
    if target:
        grain = salt_api.overview(request)
        state = salt_api.get_state(target)
    state = repr(json.dumps(state,sort_keys=True, indent=4))
    state = state.replace('\\n','<br/>').replace(' ','&nbsp;')
    context = {
            'grain':grain,
            'state':state
        }
    return render_to_response('auto_detail.html', context)