forked from triaquae/MadKing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
65,748 additions
and
227 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,4 +170,7 @@ def by_asset_type(self): | |
tree.append(node_dic) | ||
|
||
|
||
return json.dumps(tree) | ||
return json.dumps(tree) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#_*_coding:utf-8_*_ | ||
|
||
from assets import models | ||
from django.db.models import Count | ||
import random | ||
|
||
class AssetDashboard(object): | ||
'''首页画图需要的数据都在这里生产''' | ||
def __init__(self,reqeust): | ||
self.requeset = reqeust | ||
self.asset_list = models.Asset.objects.all() | ||
self.data = {} | ||
|
||
def searilize_page(self): | ||
'''生成页面需要的数据''' | ||
self.data['asset_categories'] = self.get_asset_categories() | ||
self.data['asset_status_list'] = self.get_asset_status_statistics() | ||
self.data['business_load'] = self.get_business_load() | ||
|
||
def get_business_load(self): | ||
'''调用监控等系统,得到每个业务线的负载率''' | ||
|
||
dataset = { | ||
'names':[], | ||
'data':{'load':[], 'left':[]} #left是为了填充百分比用的 | ||
} | ||
|
||
|
||
for obj in models.BusinessUnit.objects.filter(parent_level=None): | ||
load_val = random.randint(1,100) #这是个模拟数据,模拟各业务线的使用率负载 | ||
dataset['names'].append(obj.name) | ||
dataset['data']['load'].append(load_val) | ||
dataset['data']['left'].append(100-load_val) | ||
print('business load ',dataset) | ||
return dataset | ||
def get_asset_status_statistics(self): | ||
'''资产状态分类统计''' | ||
queryset = list( self.asset_list.values('status').annotate(value=Count('status'))) | ||
dataset = { | ||
'names':[], | ||
'data':[] | ||
} | ||
for index,item in enumerate(queryset): | ||
for db_val, display_name in models.Asset.status_choices: | ||
if db_val == item['status']: | ||
queryset[index]['name'] = display_name | ||
if db_val ==0:#online | ||
queryset[index]['itemStyle'] ={ | ||
'normal': {'color': 'yellowgreen'} | ||
} | ||
#queryset[index]['selected'] = True | ||
|
||
#print(queryset) | ||
dataset['names'] = [item['name'] for item in queryset] | ||
dataset['data'] = queryset | ||
return dataset | ||
def get_asset_categories(self): | ||
'''按资产类型进行分类''' | ||
|
||
dataset ={ | ||
'names':[], | ||
'data':[] | ||
} | ||
prefetch_data = { | ||
models.Server:None, | ||
models.NetworkDevice:None, | ||
models.SecurityDevice:None, | ||
models.Software:None, | ||
} | ||
for key in prefetch_data: | ||
data_list = list(key.objects.values('sub_asset_type').annotate(total=Count('sub_asset_type'))) | ||
for index,category in enumerate(data_list): | ||
for db_val,display_name in key.sub_assset_type_choices: | ||
if category['sub_asset_type'] == db_val: | ||
data_list[index]['name'] = display_name | ||
|
||
for item in data_list: | ||
dataset['names'].append(item['name']) | ||
dataset['data'].append(item['total']) | ||
#prefetch_data[key] = data_list | ||
return dataset | ||
# print("prefecth data",prefetch_data) | ||
# print("dataset",dataset) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-11-16 09:50 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('assets', '0007_networkdevice_model'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='software', | ||
name='sub_asset_type', | ||
field=models.SmallIntegerField(choices=[(0, 'OS'), (1, '办公\\开发软件'), (2, '业务软件')], default=0, verbose_name='服务器类型'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-11-17 03:35 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('assets', '0008_software_sub_asset_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='asset', | ||
name='status', | ||
field=models.SmallIntegerField(choices=[(0, '在线'), (1, '已下线'), (2, '未知'), (3, '故障'), (4, '备用')], default=0), | ||
), | ||
] |
Binary file added
BIN
+883 Bytes
assets/migrations/__pycache__/0008_software_sub_asset_type.cpython-35.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+362 Bytes
(110%)
assets/templatetags/__pycache__/custom_tag.cpython-35.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
cffi==1.8.3 | ||
cryptography==1.5.2 | ||
Django==1.10.2 | ||
idna==2.1 | ||
paramiko==2.0.2 | ||
pyasn1==0.1.9 | ||
pycparser==2.16 | ||
PyMySQL==0.7.9 | ||
PyYAML==3.12 | ||
six==1.10.0 | ||
SQLAlchemy==1.1.2 | ||
SQLAlchemy-Utils==0.32.9 |
Oops, something went wrong.