Merge branch 'dev' of git.coding.net:jumpserver/jumpserver into dev

pull/26/head
ibuler 2015-12-02 23:50:31 +08:00
commit 6080a861db
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 = {}
for disk_name, disk_info in disk_all.iteritems():
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")
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 ''
@ -325,7 +332,7 @@ def get_ansible_asset_info(asset_ip, setup_info):
cpu = cpu_type + ' * ' + unicode(cpu_cores)
memory = setup_info.get("ansible_memtotal_mb")
try:
memory_format = round((int(memory) / 1000), 1)
memory_format = int(round((int(memory) / 1000), 0))
except Exception:
memory_format = memory
disk = disk_need

View File

@ -6,6 +6,7 @@ from jumpserver.api import *
from jumpserver.models import Setting
from jasset.forms import AssetForm, IdcForm
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.perm_api import gen_resource
@ -410,6 +411,19 @@ def asset_detail(request):
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
asset_id = request.GET.get('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')
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')
def get_cpu_core(cpu_info):
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 class="ibox-content ibox-heading">
<h3>主机所有授权的用户</h3>
<small><i class="fa fa-map-marker"></i> 包含了此主机所有授权的用户.</small>
<h3>主机所有授权的信息</h3>
<small><i class="fa fa-map-marker"></i> 包含了此主机所有授权的信息.</small>
</div>
<div class="ibox-content">
<div>
{# <div class="text-left">#}
{# <table class="table">#}
{# {% if user_permed_list %}#}
{# {% for user in user_permed_list %}#}
{# <tr>#}
{# <td class="text-navy">{{ user.name }}</td>#}
{# <td>{{ user.dept.name }}</td>#}
{# <td><a href="/juser/user_detail/?id={{ user.id }}">详情</a></td>#}
{# </tr>#}
{# {% endfor %}#}
{# {% else %}#}
{# <p class="text-center">(暂无)</p>#}
{# {% endif %}#}
{# </table>#}
{# </div>#}
<div class="text-left">
{% if perm_info %}
<table class="table">
<p>授权用户信息</p>
<td class="text-navy">授权用户</td>
<td class="text-navy">系统角色</td>
{% for perm in user_perm %}
<tr>
<td class="text-navy"><a href="/juser/user_detail/?id={{ perm.0.id }}">{{ perm.0 }}</a></td>
<td>
<table class="table">
{% if perm.1 %}
{% for role in perm.1 %}
<tr>
<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 class="ibox-title">
@ -275,49 +314,47 @@
<small><i class="fa fa-map-marker"></i> 此主机最近一周用户登录信息.</small>
</div>
<div class="ibox-content inspinia-timeline">
{# {% if log %}#}
{# {% for l in log %}#}
{# <div class="timeline-item">#}
{# <div class="row">#}
{# <div class="col-xs-5 date">#}
{# <i class="fa fa-info-circle"></i>#}
{# <small class="text-navy">{{ l.user }}</small>#}
{# <br/>#}
{# <strong>{{l.dept_name}}</strong>#}
{# </div>#}
{# <div class="col-xs-7 content no-top-border">#}
{# <p class="m-b-xs"><strong>详细信息</strong></p>#}
{# <p>来源IP: {{ l.remote_ip }}</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>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# {% endfor %}#}
{# <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">#}
{# <br/>#}
{# {% for l in log_more %}#}
{# <div class="timeline-item">#}
{# <div class="row">#}
{# <div class="col-xs-5 date">#}
{# <i class="fa fa-info-circle"></i>#}
{# <small class="text-navy">{{ l.user }}</small>#}
{# <br/>#}
{# <strong>{{l.dept_name}}</strong>#}
{# </div>#}
{# <div class="col-xs-7 content no-top-border">#}
{# <p class="m-b-xs"><strong>详细信息</strong></p>#}
{# <p>来源IP: {{ l.remote_ip }}</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>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# {% endfor %}#}
{# {% else %}#}
{# <p class="text-center">(暂无)</p>#}
{# {% endif %}#}
{% if log %}
{% for l in log %}
<div class="timeline-item">
<div class="row">
<div class="col-xs-5 date">
<i class="fa fa-info-circle"></i>
<small class="text-navy">{{ l.user }}</small>
<br/>
</div>
<div class="col-xs-7 content no-top-border">
<p class="m-b-xs"><strong>详细信息</strong></p>
<p>来源IP: {{ l.remote_ip }}</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>
</div>
</div>
</div>
{% endfor %}
<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">
<br/>
{% for l in log_more %}
<div class="timeline-item">
<div class="row">
<div class="col-xs-5 date">
<i class="fa fa-info-circle"></i>
<small class="text-navy">{{ l.user }}</small>
<br/>
</div>
<div class="col-xs-7 content no-top-border">
<p class="m-b-xs"><strong>详细信息</strong></p>
<p>来源IP: {{ l.remote_ip }}</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>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-center">(暂无)</p>
{% endif %}
</div>
</div>

View File

@ -121,22 +121,19 @@
<td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'>
<input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks">
</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.idc.name|default_if_none:"" }} </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.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.memory }}{% if asset.memory %}G{% endif %} </td>
<td class="text-center"> {{ asset.disk }} </td>
<td class="text-center"> {{ asset.memory }}{% if asset.memory %}G{% endif %}</td>
<td class="text-center"> {{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %}</td>
<td class="text-center" data-editable='false'>
<a href="/jasset/asset_detail/?id={{ asset.id }}" class="btn btn-xs btn-primary">详情</a>
{% ifnotequal session_role_id 0 %}
<a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</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 %}
<a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</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>
</td>
</tr>
{% endfor %}