Skip to content

Commit

Permalink
ztree for monitor test json tree completed
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed Sep 7, 2018
1 parent ef2ea49 commit b2de979
Show file tree
Hide file tree
Showing 45 changed files with 10,131 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmdb/idc.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def idc_edit(request, idc_id):

@login_required
@permission_verify()
def cabinet_list(request, cabinet_id):
def cabinet_list(request, idc_id):
temp_name = "cmdb/cmdb-header.html"
cab = Idc.objects.get(id=cabinet_id)
cab = Idc.objects.get(id=idc_id)
cabinets = cab.cabinet_set.all()
results = {
'temp_name': temp_name,
Expand Down
2 changes: 1 addition & 1 deletion cmdb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
url(r'^idc/add/$', idc.idc_add, name='idc_add'),
url(r'^idc/del/$', idc.idc_del, name='idc_del'),
url(r'^idc/edit/(?P<idc_id>\d+)/$', idc.idc_edit, name='idc_edit'),
url(r'^idc/cabinetlist/(?P<cabinet_id>\d+)/$', idc.cabinet_list, name='idc_cabinet_list'),
url(r'^idc/cabinetlist/(?P<idc_id>\d+)/$', idc.cabinet_list, name='idc_cabinet_list'),
url(r'^collect', api.collect, name='update_api'),
url(r'^get/host/', api.get_host, name='get_host'),
url(r'^get/group/', api.get_group, name='get_group'),
Expand Down
68 changes: 67 additions & 1 deletion monitor/system.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from django.shortcuts import render, HttpResponse
from cmdb.models import Host
from cmdb.models import Host, Idc, HostGroup
from appconf.product import Product
from django.contrib.auth.decorators import login_required
from accounts.permission import permission_verify
import json
import time
from monitor.api import GetSysData
from django.views.decorators.csrf import csrf_exempt

TIME_SECTOR = (
3600,
3600*3,
Expand Down Expand Up @@ -103,6 +106,7 @@ def get_net(request, hostname, timing, net_id):
def index(request):
temp_name = "monitor/monitor-header.html"
all_host = Host.objects.all()
idcs = Idc.objects.all()
return render(request, "monitor/index.html", locals())


Expand All @@ -129,3 +133,65 @@ def host_info(request, hostname, timing):
return render(request, "monitor/host_info.html", locals())


def host_tree():
host_node = []
for idc in Idc.objects.all():
single_server_list = []
for host in idc.host_set.all():
single_server_list.append({'name': host.hostname, 'url': "/monitor/system/{}/0/".format(host.hostname)})
cabinet_list = []
cabinets = idc.cabinet_set.all()
for cabinet in cabinets:
server_list = []
servers = cabinet.serverList.all()
for server in servers:
server_data = {'name': server.hostname, 'url': "/monitor/system/{}/0/".format(server.hostname)}
server_list.append(server_data)
cabinet_data = {'name': cabinet.name, 'children': server_list}
cabinet_list.append(cabinet_data)
del server_list
data = {"name": idc.name, "open": True, "children": cabinet_list + single_server_list }
del cabinet_list
host_node.append(data)
return host_node


def group_tree():
group_node = []
for group in HostGroup.objects.all():
server_list = []
servers = group.serverList.all()
for server in servers:
server_data = {'name': server.hostname, 'url': "/monitor/system/{}/0/".format(server.hostname)}
server_list.append(server_data)
group_data = {'name': group.name, 'children': server_list}
group_node.append(group_data)
del server_list
return group_node


def product_tree():
product_node = []
for pdt in Product.objects.all():
project_list = []
projects = pdt.project_set.all()
for pjs in projects:
server_list = []
servers = pjs.serverList.all()
for server in servers:
server_data = {'name': server.hostname, 'url': "/monitor/system/{}/0/".format(server.hostname)}
server_list.append(server_data)
project_data = {'name': pjs.name, 'children': server_list}
project_list.append(project_data)
del server_list
data = {"name": pdt.name, "open": True, "children": project_list}
del project_list
product_node.append(data)
return product_node


@login_required
@csrf_exempt
def tree_node(request):
all_node = host_tree() + group_tree() + product_tree()
return HttpResponse(json.dumps(all_node))
1 change: 1 addition & 0 deletions monitor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
urlpatterns = [
url(r'^system/$', system.index, name='monitor'),
url(r'^manage/del/all/$', manage.drop_sys_info, name='drop_all'),
url(r'^system/host/tree/$', system.tree_node, name='host_tree'),
url(r'^manage/del/range/(?P<timing>[0-9])/$', manage.del_monitor_data, name='del_monitor_data'),
url(r'^manage/$', manage.index, name='monitor_manage'),
url(r'^system/(?P<hostname>.+)/(?P<timing>\d+)/$', system.host_info, name='host_info'),
Expand Down
1 change: 1 addition & 0 deletions static/js/echarts.js

Large diffs are not rendered by default.

Loading

0 comments on commit b2de979

Please sign in to comment.