mirror of https://github.com/jumpserver/jumpserver
Merge branch 'cmdb' into dev
commit
a04bb100bf
|
@ -311,8 +311,12 @@ def write_excel(asset_all):
|
|||
group_all = '/'.join(group_list)
|
||||
status = asset.get_status_display()
|
||||
idc_name = asset.idc.name if asset.idc else u''
|
||||
system_type = asset.system_type if asset.idc else u''
|
||||
system_version = asset.system_version if asset.idc else u''
|
||||
system_os = unicode(system_type) + unicode(system_version)
|
||||
|
||||
alter_dic = [asset.hostname, asset.ip, idc_name, asset.mac, asset.remote_ip, asset.cpu, asset.memory,
|
||||
asset.disk, (asset.system_type + asset.system_version), asset.cabinet, group_all, status,
|
||||
asset.disk, system_os, asset.cabinet, group_all, status,
|
||||
asset.comment]
|
||||
data.append(alter_dic)
|
||||
format = workbook.add_format()
|
||||
|
@ -381,13 +385,13 @@ def excel_to_db(excel_file):
|
|||
row = table.row_values(row_num)
|
||||
if row:
|
||||
ip, port, hostname, use_default_auth, username, password, group = row
|
||||
print ip
|
||||
use_default_auth = 1 if use_default_auth == u'默认' else 0
|
||||
if get_object(Asset, ip=ip):
|
||||
continue
|
||||
if ip and port:
|
||||
asset = Asset(ip=ip,
|
||||
port=port,
|
||||
hostname=hostname,
|
||||
use_default_auth=use_default_auth,
|
||||
username=username,
|
||||
password=password
|
||||
|
|
|
@ -37,8 +37,8 @@ class AssetGroup(models.Model):
|
|||
class IDC(models.Model):
|
||||
name = models.CharField(max_length=32, verbose_name=u'机房名称')
|
||||
bandwidth = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机房带宽')
|
||||
linkman = models.CharField(max_length=16, null=True, verbose_name=u'联系人')
|
||||
phone = models.CharField(max_length=32, verbose_name=u'联系电话')
|
||||
linkman = models.CharField(max_length=16, blank=True, null=True, verbose_name=u'联系人')
|
||||
phone = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'联系电话')
|
||||
address = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"机房地址")
|
||||
network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段")
|
||||
date_added = models.DateField(auto_now=True, null=True)
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
import ast
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
from jasset.asset_api import *
|
||||
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 ansible_api import Tasks
|
||||
|
@ -13,7 +13,7 @@ from ansible_api import Tasks
|
|||
@require_role('admin')
|
||||
def group_add(request):
|
||||
"""
|
||||
Add asset group
|
||||
Group add view
|
||||
添加资产组
|
||||
"""
|
||||
header_title, path1, path2 = u'添加资产组', u'资产管理', u'添加资产组'
|
||||
|
@ -47,7 +47,7 @@ def group_add(request):
|
|||
@require_role('admin')
|
||||
def group_edit(request):
|
||||
"""
|
||||
Edit asset group
|
||||
Group edit view
|
||||
编辑资产组
|
||||
"""
|
||||
header_title, path1, path2 = u'编辑主机组', u'资产管理', u'编辑主机组'
|
||||
|
@ -89,7 +89,10 @@ def group_edit(request):
|
|||
|
||||
@require_role('admin')
|
||||
def group_detail(request):
|
||||
""" 主机组详情 """
|
||||
"""
|
||||
Group detail view
|
||||
主机组详情
|
||||
"""
|
||||
header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
|
||||
group_id = request.GET.get('id', '')
|
||||
group = get_object(AssetGroup, id=group_id)
|
||||
|
@ -121,7 +124,7 @@ def group_list(request):
|
|||
@require_role('admin')
|
||||
def group_del(request):
|
||||
"""
|
||||
del asset group
|
||||
Group delete view
|
||||
删除主机组
|
||||
"""
|
||||
group_ids = request.GET.get('id', '')
|
||||
|
@ -293,7 +296,7 @@ def asset_list(request):
|
|||
s = write_excel(asset_find)
|
||||
if s[0]:
|
||||
file_name = s[1]
|
||||
smg = 'excel文件已生成,请点击下载!'
|
||||
smg = u'excel文件已生成,请点击下载!'
|
||||
return my_render('jasset/asset_excel_download.html', locals(), request)
|
||||
assets_list, p, assets, page_range, current_page, show_first, show_end = pages(asset_find, request)
|
||||
return my_render('jasset/asset_list.html', locals(), request)
|
||||
|
@ -330,13 +333,20 @@ def asset_update(request):
|
|||
return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id)
|
||||
name = request.session.get('username', 'admin')
|
||||
if asset.use_default_auth:
|
||||
username = 'root'
|
||||
password = '123456'
|
||||
default = Setting.objects.all()
|
||||
if default:
|
||||
default = default[0]
|
||||
username = default.default_user
|
||||
password = default.default_password
|
||||
port = default.default_port
|
||||
else:
|
||||
return HttpResponse(u'没有设置默认用户名和密码!')
|
||||
else:
|
||||
username = asset.username
|
||||
password = asset.password
|
||||
port = asset.port
|
||||
|
||||
resource = [{"hostname": asset.ip, "port": asset.port,
|
||||
resource = [{"hostname": asset.ip, "port": port,
|
||||
"username": username, "password": password}]
|
||||
|
||||
ansible_instance = Tasks(resource)
|
||||
|
@ -446,16 +456,17 @@ def idc_del(request):
|
|||
"""
|
||||
IDC delete view
|
||||
"""
|
||||
uuid = request.GET.get('uuid', '')
|
||||
idc = get_object_or_404(IDC, uuid=uuid)
|
||||
idc.delete()
|
||||
uuid = request.GET.get('id', '')
|
||||
idc = get_object(IDC, id=uuid)
|
||||
if idc:
|
||||
idc.delete()
|
||||
return HttpResponseRedirect('/jasset/idc_list/')
|
||||
|
||||
|
||||
@require_role('admin')
|
||||
def asset_upload(request):
|
||||
"""
|
||||
Upload file view
|
||||
Upload asset excel file view
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
excel_file = request.FILES.get('file_name', '')
|
||||
|
|
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.
Binary file not shown.
|
@ -31,11 +31,11 @@
|
|||
<table class="table">
|
||||
<tr>
|
||||
<td class="text-navy">IP</td>
|
||||
<td>{{ asset.ip }}</td>
|
||||
<td>{{ asset.ip|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">主机名</td>
|
||||
<td>{{ asset.hostname }}</td>
|
||||
<td>{{ asset.hostname|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">其他IP</td>
|
||||
|
@ -53,11 +53,11 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">远控IP</td>
|
||||
<td>{{ asset.remote_ip }}</td>
|
||||
<td>{{ asset.remote_ip|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">端口</td>
|
||||
<td>{{ asset.port }}</td>
|
||||
<td>{{ asset.port|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
@ -66,7 +66,7 @@
|
|||
<table class="table">
|
||||
{% for asset_group in asset.group.all %}
|
||||
<tr>
|
||||
<td>{{ asset_group.name }}</td>
|
||||
<td>{{ asset_group.name|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
@ -79,19 +79,19 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">机房</td>
|
||||
<td>{{ asset.idc.name }}</td>
|
||||
<td>{{ asset.idc.name|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">硬件厂商型号</td>
|
||||
<td>{{ asset.brand }}</td>
|
||||
<td>{{ asset.brand|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">CPU</td>
|
||||
<td>{{ asset.cpu }}</td>
|
||||
<td>{{ asset.cpu|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">内存</td>
|
||||
<td>{{ asset.memory }}M</td>
|
||||
<td>{{ asset.memory|default_if_none:"" }}{% if asset.memory %}M{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">硬盘</td>
|
||||
|
@ -100,7 +100,7 @@
|
|||
{% if asset.disk %}
|
||||
{% for disk, value in asset.disk|str_to_dic %}
|
||||
<tr>
|
||||
<td><span class="text-navy">{{ disk }}</span>     {{ value }}</td>
|
||||
<td><span class="text-navy">{{ disk|default_if_none:"" }}</span>     {{ value|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
@ -109,35 +109,35 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">资产编号</td>
|
||||
<td>{{ asset.number }}</td>
|
||||
<td>{{ asset.number|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">SN</td>
|
||||
<td>{{ asset.sn }}</td>
|
||||
<td>{{ asset.sn|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">主机类型</td>
|
||||
<td>{{ asset.get_asset_type_display }}</td>
|
||||
<td>{{ asset.get_asset_type_display|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">系统版本</td>
|
||||
<td>{{ asset.system_type }} {{ asset.system_version }}</td>
|
||||
<td>{{ asset.system_type|default_if_none:"" }} {{ asset.system_version|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">运行环境</td>
|
||||
<td>{{ asset.get_env_display }}</td>
|
||||
<td>{{ asset.get_env_display|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">机器状态</td>
|
||||
<td>{{ asset.get_status_display }}</td>
|
||||
<td>{{ asset.get_status_display|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">机柜号</td>
|
||||
<td>{{ asset.cabinet }}</td>
|
||||
<td>{{ asset.cabinet|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">机柜位置</td>
|
||||
<td>{{ asset.position }}</td>
|
||||
<td>{{ asset.position|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">激活</td>
|
||||
|
@ -149,7 +149,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">备注</td>
|
||||
<td>{{ asset.comment }}</td>
|
||||
<td>{{ asset.comment|default_if_none:"" }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<div class="col-md-12 column">
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h4>
|
||||
</h4> <strong>Nice!</strong> excel文件已生成请点击 <a href="/static/files/excels/{{ file_name }}" target="_blank" class="alert-link">下载</a>
|
||||
<strong>Nice!</strong> excel文件已生成请点击 <a href="/static/files/excels/{{ file_name }}" target="_blank" class="alert-link">下载</a>
|
||||
</div>
|
||||
</div>
|
|
@ -119,12 +119,12 @@
|
|||
<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"> {{ asset.ip }} </td>
|
||||
<td class="text-center"> {{ asset.hostname }} </td>
|
||||
<td class="text-center"> {{ asset.idc.name }} </td>
|
||||
<td class="text-center"> {{ asset.ip|default_if_none:"" }} </td>
|
||||
<td class="text-center"> {{ asset.hostname|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 }}{{ asset.system_version }}</td>
|
||||
<td class="text-center">{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}</td>
|
||||
<td class="text-center"> {{ asset.use_default_auth|bool2str }} </td>
|
||||
<td class="text-center" data-editable='false'>
|
||||
<a href="/jasset/asset_detail/?id={{ asset.id }}" class="btn btn-xs btn-primary">详情</a>
|
||||
|
@ -169,17 +169,17 @@
|
|||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#editable').editableTableWidget({editor: $('<textarea>')});
|
||||
$('.asset_del').click(function(){
|
||||
var row = $(this).closest('tr');
|
||||
$.get(
|
||||
$(this).attr('value'),
|
||||
{},
|
||||
function(data){
|
||||
alert(data);
|
||||
row.remove()
|
||||
}
|
||||
)
|
||||
if (confirm("确定删除")) {
|
||||
$.get(
|
||||
$(this).attr('value'),
|
||||
{},
|
||||
function (data) {
|
||||
row.remove()
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
@ -75,12 +75,12 @@
|
|||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="" class="col-sm-2 control-label">主机<span class="red-fonts">*</span></label>
|
||||
<label for="" class="col-sm-2 control-label">主机</label>
|
||||
<div class="col-sm-4">
|
||||
<div>
|
||||
<select id="assets" name="assets" class="form-control m-b" size="12" multiple>
|
||||
{% for asset in asset_all %}
|
||||
<option value="{{ asset.id }}">{{ asset.ip }}</option>
|
||||
<option value="{{ asset.id }}">{{ asset.hostname|default_if_none:"" }} - {{ asset.ip|default_if_none:"" }} - {{ asset.port|default_if_none:"" }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -133,12 +133,12 @@
|
|||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
fields: {
|
||||
"j_group": {
|
||||
"name": {
|
||||
rule: "required",
|
||||
tip: "输入业务组名",
|
||||
tip: "输入主机组名",
|
||||
ok: "",
|
||||
msg: {required: "业务组名必须填写!"},
|
||||
data: {'data-ok':"业务组名可以使用"}
|
||||
msg: {required: "主机组名必须填写!"},
|
||||
data: {'data-ok':"主机组名可以使用"}
|
||||
}
|
||||
},
|
||||
valid: function(form) {
|
||||
|
|
|
@ -52,17 +52,17 @@
|
|||
<tbody>
|
||||
{% for asset in contacts.object_list %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center" name="j_id" value="{{ asset.id }}" data-editable='false'><input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks"></td>
|
||||
<td class="text-center" name="j_ip"> {{ asset.ip }} </td>
|
||||
<td class="text-center" name="j_port"> {{ asset.port }} </td>
|
||||
<td class="text-center" name="j_idc"> {{ asset.idc.name }} </td>
|
||||
<td class="text-center" name="j_id" value="{{ asset.id|default_if_none:"" }}" data-editable='false'><input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks"></td>
|
||||
<td class="text-center" name="j_ip"> {{ asset.ip|default_if_none:"" }} </td>
|
||||
<td class="text-center" name="j_port"> {{ asset.port|default_if_none:"" }} </td>
|
||||
<td class="text-center" name="j_idc"> {{ asset.idc.name|default_if_none:"" }} </td>
|
||||
<td class="text-center" name="j_group">{{ asset.bis_group.all | group_str2 }}</td>
|
||||
<td class="text-center" name="j_active"> {{ asset.is_active|bool2str }} </td>
|
||||
<td class="text-center"> {{ asset.date_added|date:"Y-m-d H:i:s" }} </td>
|
||||
<td class="text-center" name="j_comment"> {{ asset.comment }} </td>
|
||||
<td class="text-center" name="j_comment"> {{ asset.comment|default_if_none:"" }} </td>
|
||||
<td class="text-center" data-editable='false'>
|
||||
<a href="/jasset/host_detail/?id={{ asset.id }}" class="iframe btn btn-xs btn-primary">详情</a>
|
||||
<a href="/jasset/host_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="/jasset/asset_detail/?id={{ asset.id }}" class="iframe btn btn-xs btn-primary">详情</a>
|
||||
<a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="/jasset/group_del_host/?id={{ asset.id }}&gid={{ group.id }}" class="btn btn-xs btn-danger">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
<div>
|
||||
<select id="assets" name="assets" class="form-control m-b" size="12" multiple>
|
||||
{% for asset in asset_no_select %}
|
||||
<option value="{{ asset.id }}">{{ asset.ip }}</option>
|
||||
<option value="{{ asset.id }}">{{ asset.hostname|default_if_none:"" }} - {{ asset.ip|default_if_none:"" }} - {{ asset.port|default_if_none:"" }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -103,7 +103,7 @@
|
|||
<div>
|
||||
<select id="asset_select" name="asset_select" class="form-control m-b" size="12" multiple>
|
||||
{% for asset in asset_select %}
|
||||
<option value="{{ asset.id }}">{{ asset.ip }}</option>
|
||||
<option value="{{ asset.id }}">{{ asset.hostname|default_if_none:"" }} - {{ asset.ip|default_if_none:"" }} - {{ asset.port|default_if_none:"" }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<td class="text-center">
|
||||
<a href="/jasset/group_detail/?id={{ asset_group.id }}" class="btn btn-xs btn-info">详情</a>
|
||||
<a href="/jasset/group_edit/?id={{ asset_group.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a value="/jasset/group_del/?id={{ asset_group.id }}" id="del" class="btn btn-xs btn-danger">删除</a>
|
||||
<a value="/jasset/group_del/?id={{ asset_group.id }}" class="btn btn-xs btn-danger group_del">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -88,16 +88,17 @@
|
|||
{% block self_footer_js %}
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#del').click(function(){
|
||||
$('.group_del').click(function(){
|
||||
var row = $(this).closest('tr');
|
||||
$.get(
|
||||
$(this).attr('value'),
|
||||
{},
|
||||
function(data){
|
||||
row.remove();
|
||||
alert(data)
|
||||
}
|
||||
)
|
||||
if (confirm('确定删除')) {
|
||||
$.get(
|
||||
$(this).attr('value'),
|
||||
{},
|
||||
function (data) {
|
||||
row.remove();
|
||||
}
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
$('#del_check').click(function(){
|
||||
|
@ -111,15 +112,12 @@
|
|||
{id: check_array.join(',')},
|
||||
function(data){
|
||||
$('tr.gradeX input:checked').closest('tr').remove();
|
||||
alert(data);
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<a><i class="fa fa-cube"></i> <span class="nav-label">资产管理</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
{# <li class="host_add host_add_multi"><a href="/jasset/host_add/">添加资产</a></li>#}
|
||||
<li class="host_list host_detail host_edit"><a href="/jasset/asset_list/">查看资产<span class="label label-info pull-right">{{ host_active_num }}/{{ host_total_num}}</span></a></li>
|
||||
<li class="asset_list asset_detail asset_edit"><a href="/jasset/asset_list/">查看资产<span class="label label-info pull-right">{{ host_active_num }}/{{ host_total_num}}</span></a></li>
|
||||
<li class="idc_list idc_detail idc_edit"><a href="/jasset/idc_list/">查看IDC</a></li>
|
||||
<li class="group_add"><a href="/jasset/group_add/">添加主机组</a></li>
|
||||
<li class="group_list group_detail group_edit"><a href="/jasset/group_list/">查看主机组</a></li>
|
||||
|
|
Loading…
Reference in New Issue