day update

pull/26/head
halcyon 2015-12-02 23:39:17 +08:00
parent 88fbcabcbb
commit f6dbec1436
5 changed files with 139 additions and 71 deletions

View File

@ -312,7 +312,14 @@ def get_ansible_asset_info(asset_ip, setup_info):
disk_need = {} disk_need = {}
for disk_name, disk_info in disk_all.iteritems(): for disk_name, disk_info in disk_all.iteritems():
if disk_name.startswith('sd') or disk_name.startswith('hd') or disk_name.startswith('vd'): if disk_name.startswith('sd') or disk_name.startswith('hd') or disk_name.startswith('vd'):
disk_need[disk_name] = disk_info.get("size") disk_size = disk_info.get("size")
if 'M' in disk_size:
disk_format = round(float(disk_size[:-2]) / 1000, 0)
elif 'T' in disk_size:
disk_format = round(float(disk_size[:-2]) * 1000, 0)
else:
disk_format = float(disk_size)
disk_need[disk_name] = disk_format
all_ip = setup_info.get("ansible_all_ipv4_addresses") all_ip = setup_info.get("ansible_all_ipv4_addresses")
other_ip_list = all_ip.remove(asset_ip) if asset_ip in all_ip else [] other_ip_list = all_ip.remove(asset_ip) if asset_ip in all_ip else []
other_ip = ','.join(other_ip_list) if other_ip_list else '' other_ip = ','.join(other_ip_list) if other_ip_list else ''
@ -325,7 +332,7 @@ def get_ansible_asset_info(asset_ip, setup_info):
cpu = cpu_type + ' * ' + unicode(cpu_cores) cpu = cpu_type + ' * ' + unicode(cpu_cores)
memory = setup_info.get("ansible_memtotal_mb") memory = setup_info.get("ansible_memtotal_mb")
try: try:
memory_format = round((int(memory) / 1000), 1) memory_format = int(round((int(memory) / 1000), 0))
except Exception: except Exception:
memory_format = memory memory_format = memory
disk = disk_need disk = disk_need

View File

@ -6,6 +6,7 @@ from jumpserver.api import *
from jumpserver.models import Setting from jumpserver.models import Setting
from jasset.forms import AssetForm, IdcForm from jasset.forms import AssetForm, IdcForm
from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS
from jperm.perm_api import get_group_asset_perm
from jperm.ansible_api import Tasks, MyRunner from jperm.ansible_api import Tasks, MyRunner
from jperm.perm_api import gen_resource from jperm.perm_api import gen_resource
@ -410,6 +411,19 @@ def asset_detail(request):
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情' header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
asset_id = request.GET.get('id', '') asset_id = request.GET.get('id', '')
asset = get_object(Asset, id=asset_id) asset = get_object(Asset, id=asset_id)
perm_info = get_group_asset_perm(asset)
log = Log.objects.filter(host=asset.hostname)
if perm_info:
user_perm = []
for perm, value in perm_info.items():
if perm == 'user':
for user, role_dic in value.items():
user_perm.append([user, role_dic.get('role', '')])
elif perm == 'user_group':
user_group_perm = value
elif perm == 'rule':
user_rule_perm = value
asset_record = AssetRecord.objects.filter(asset=asset).order_by('-alert_time') asset_record = AssetRecord.objects.filter(asset=asset).order_by('-alert_time')
return my_render('jasset/asset_detail.html', locals(), request) return my_render('jasset/asset_detail.html', locals(), request)

View File

@ -277,3 +277,16 @@ def get_push_info(push_id, arg):
@register.filter(name='get_cpu_core') @register.filter(name='get_cpu_core')
def get_cpu_core(cpu_info): def get_cpu_core(cpu_info):
return cpu_info.split('* ')[1] if cpu_info else '' return cpu_info.split('* ')[1] if cpu_info else ''
@register.filter(name='get_disk_info')
def get_disk_info(disk_info):
try:
disk_size = 0
if disk_info:
disk_dic = ast.literal_eval(disk_info)
for disk, size in disk_dic.items():
disk_size += size
disk_size = int(disk_size)
except Exception:
disk_size = ''
return disk_size

View File

@ -186,26 +186,65 @@
</div> </div>
</div> </div>
<div class="ibox-content ibox-heading"> <div class="ibox-content ibox-heading">
<h3>主机所有授权的用户</h3> <h3>主机所有授权的信息</h3>
<small><i class="fa fa-map-marker"></i> 包含了此主机所有授权的用户.</small> <small><i class="fa fa-map-marker"></i> 包含了此主机所有授权的信息.</small>
</div> </div>
<div class="ibox-content"> <div class="ibox-content">
<div> <div>
{# <div class="text-left">#} <div class="text-left">
{# <table class="table">#} {% if perm_info %}
{# {% if user_permed_list %}#} <table class="table">
{# {% for user in user_permed_list %}#} <p>授权用户信息</p>
{# <tr>#} <td class="text-navy">授权用户</td>
{# <td class="text-navy">{{ user.name }}</td>#} <td class="text-navy">系统角色</td>
{# <td>{{ user.dept.name }}</td>#} {% for perm in user_perm %}
{# <td><a href="/juser/user_detail/?id={{ user.id }}">详情</a></td>#} <tr>
{# </tr>#} <td class="text-navy"><a href="/juser/user_detail/?id={{ perm.0.id }}">{{ perm.0 }}</a></td>
{# {% endfor %}#} <td>
{# {% else %}#} <table class="table">
{# <p class="text-center">(暂无)</p>#} {% if perm.1 %}
{# {% endif %}#} {% for role in perm.1 %}
{# </table>#} <tr>
{# </div>#} <td class="text-navy"><a href="/jperm/role/perm_role_detail/?id={{ role.id }}">{{ role }}</a></td>
</tr>
{% endfor %}
{% endif %}
</table>
</td>
</tr>
{% endfor %}
</table>
{% if user_group_perm %}
<table class="table">
<p>授权用户组信息</p>
<td class="text-navy">授权用户组</td>
<td class="text-navy">组详情</td>
{% for user_group in user_group_perm %}
<tr>
<td class="text-navy">{{ user_group }}</td>
<td class="text-navy"><a href="/juser/user_list/?gid={{ user_group.id }}">详情</a></td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if user_rule_perm %}
<table class="table">
<p>授权规则信息</p>
<td class="text-navy">授权规则</td>
<td class="text-navy">详情</td>
{% for rule in user_rule_perm %}
<tr>
<td class="text-navy">{{ rule }}</td>
<td class="text-navy"><a href="/jperm/perm_rule_detail/?id={{ rule.id }}">详情</a></td>
</tr>
{% endfor %}
</table>
{% endif %}
{% else %}
<p class="text-center">(暂无)</p>
{% endif %}
</div>
</div> </div>
</div> </div>
<div class="ibox-title"> <div class="ibox-title">
@ -275,49 +314,47 @@
<small><i class="fa fa-map-marker"></i> 此主机最近一周用户登录信息.</small> <small><i class="fa fa-map-marker"></i> 此主机最近一周用户登录信息.</small>
</div> </div>
<div class="ibox-content inspinia-timeline"> <div class="ibox-content inspinia-timeline">
{# {% if log %}#} {% if log %}
{# {% for l in log %}#} {% for l in log %}
{# <div class="timeline-item">#} <div class="timeline-item">
{# <div class="row">#} <div class="row">
{# <div class="col-xs-5 date">#} <div class="col-xs-5 date">
{# <i class="fa fa-info-circle"></i>#} <i class="fa fa-info-circle"></i>
{# <small class="text-navy">{{ l.user }}</small>#} <small class="text-navy">{{ l.user }}</small>
{# <br/>#} <br/>
{# <strong>{{l.dept_name}}</strong>#} </div>
{# </div>#} <div class="col-xs-7 content no-top-border">
{# <div class="col-xs-7 content no-top-border">#} <p class="m-b-xs"><strong>详细信息</strong></p>
{# <p class="m-b-xs"><strong>详细信息</strong></p>#} <p>来源IP: {{ l.remote_ip }}</p>
{# <p>来源IP: {{ l.remote_ip }}</p>#} <p>开始: {{ l.start_time |date:"Y-m-d H:i:s" }}</p>
{# <p>开始: {{ l.start_time |date:"Y-m-d H:i:s" }}</p>#} <p>结束: {{ l.end_time |date:"Y-m-d H:i:s" }}</p>
{# <p>结束: {{ l.end_time |date:"Y-m-d H:i:s" }}</p>#} </div>
{# </div>#} </div>
{# </div>#} </div>
{# </div>#} {% endfor %}
{# {% endfor %}#} <button id="show" class="btn btn-primary btn-block m-t"><i class="fa fa-arrow-down"></i> 所有 </button>
{# <button id="show" class="btn btn-primary btn-block m-t"><i class="fa fa-arrow-down"></i> 所有 </button>#} <div id='more' style="display: none">
{# <div id='more' style="display: none">#} <br/>
{# <br/>#} {% for l in log_more %}
{# {% for l in log_more %}#} <div class="timeline-item">
{# <div class="timeline-item">#} <div class="row">
{# <div class="row">#} <div class="col-xs-5 date">
{# <div class="col-xs-5 date">#} <i class="fa fa-info-circle"></i>
{# <i class="fa fa-info-circle"></i>#} <small class="text-navy">{{ l.user }}</small>
{# <small class="text-navy">{{ l.user }}</small>#} <br/>
{# <br/>#} </div>
{# <strong>{{l.dept_name}}</strong>#} <div class="col-xs-7 content no-top-border">
{# </div>#} <p class="m-b-xs"><strong>详细信息</strong></p>
{# <div class="col-xs-7 content no-top-border">#} <p>来源IP: {{ l.remote_ip }}</p>
{# <p class="m-b-xs"><strong>详细信息</strong></p>#} <p>开始: {{ l.start_time |date:"Y-m-d H:i:s" }}</p>
{# <p>来源IP: {{ l.remote_ip }}</p>#} <p>结束: {{ l.end_time |date:"Y-m-d H:i:s" }}</p>
{# <p>开始: {{ l.start_time |date:"Y-m-d H:i:s" }}</p>#} </div>
{# <p>结束: {{ l.end_time |date:"Y-m-d H:i:s" }}</p>#} </div>
{# </div>#} </div>
{# </div>#} {% endfor %}
{# </div>#} {% else %}
{# {% endfor %}#} <p class="text-center">(暂无)</p>
{# {% else %}#} {% endif %}
{# <p class="text-center">(暂无)</p>#}
{# {% endif %}#}
</div> </div>
</div> </div>

View File

@ -121,22 +121,19 @@
<td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'> <td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'>
<input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks"> <input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks">
</td> </td>
<td class="text-center hostname"> {{ asset.hostname|default_if_none:"" }} </td> <td class="text-center hostname"> <a href="/jasset/asset_detail/?id={{ asset.id }}">{{ asset.hostname|default_if_none:"" }}</a></td>
<td class="text-center"> {{ asset.ip|default_if_none:"" }} </td> <td class="text-center"> {{ asset.ip|default_if_none:"" }} </td>
<td class="text-center"> {{ asset.idc.name|default_if_none:"" }} </td> <td class="text-center"> {{ asset.idc.name|default_if_none:"" }} </td>
<td class="text-center">{{ asset.group.all|group_str2 }}</td> <td class="text-center">{{ asset.group.all|group_str2 }}</td>
{# <td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>#} {# <td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>#}
<td class="text-center">{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}</td> <td class="text-center">{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}</td>
<td class="text-center"> {{ asset.cpu|get_cpu_core }} </td> <td class="text-center"> {{ asset.cpu|get_cpu_core }} </td>
<td class="text-center"> {{ asset.memory }}{% if asset.memory %}G{% endif %} </td> <td class="text-center"> {{ asset.memory }}{% if asset.memory %}G{% endif %}</td>
<td class="text-center"> {{ asset.disk }} </td> <td class="text-center"> {{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %}</td>
<td class="text-center" data-editable='false'> <td class="text-center" data-editable='false'>
<a href="/jasset/asset_detail/?id={{ asset.id }}" class="btn btn-xs btn-primary">详情</a> <a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a>
{% ifnotequal session_role_id 0 %} <a value="{{ asset.id }}" class="conn btn btn-xs btn-warning">连接</a>
<a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a> <a value="/jasset/asset_del/?id={{ asset.id }}" class="btn btn-xs btn-danger asset_del">删除</a>
<a value="{{ asset.id }}" class="conn btn btn-xs btn-warning">连接</a>
<a value="/jasset/asset_del/?id={{ asset.id }}" class="btn btn-xs btn-danger asset_del">删除</a>
{% endifnotequal %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}