mirror of
https://github.com/veops/cmdb.git
synced 2025-08-25 20:09:00 +08:00
perf(api): net device auto discovery
This commit is contained in:
@@ -12,6 +12,7 @@ from sqlalchemy import func
|
|||||||
from api.extensions import db
|
from api.extensions import db
|
||||||
from api.lib.cmdb.auto_discovery.const import CLOUD_MAP
|
from api.lib.cmdb.auto_discovery.const import CLOUD_MAP
|
||||||
from api.lib.cmdb.auto_discovery.const import DEFAULT_INNER
|
from api.lib.cmdb.auto_discovery.const import DEFAULT_INNER
|
||||||
|
from api.lib.cmdb.auto_discovery.const import NET_DEVICE_NAMES
|
||||||
from api.lib.cmdb.auto_discovery.const import PRIVILEGED_USERS
|
from api.lib.cmdb.auto_discovery.const import PRIVILEGED_USERS
|
||||||
from api.lib.cmdb.cache import AttributeCache
|
from api.lib.cmdb.cache import AttributeCache
|
||||||
from api.lib.cmdb.cache import AutoDiscoveryMappingCache
|
from api.lib.cmdb.cache import AutoDiscoveryMappingCache
|
||||||
@@ -252,6 +253,7 @@ class AutoDiscoveryCITypeCRUD(DBMixin):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
|
db.session.commit()
|
||||||
rules = cls.cls.get_by(to_dict=True)
|
rules = cls.cls.get_by(to_dict=True)
|
||||||
|
|
||||||
for rule in rules:
|
for rule in rules:
|
||||||
@@ -718,6 +720,12 @@ class AutoDiscoveryCICRUD(DBMixin):
|
|||||||
|
|
||||||
build_relations_for_ad_accept.apply_async(args=(adc.to_dict(), ci_id, ad_key2attr), queue=CMDB_QUEUE)
|
build_relations_for_ad_accept.apply_async(args=(adc.to_dict(), ci_id, ad_key2attr), queue=CMDB_QUEUE)
|
||||||
|
|
||||||
|
ci_type = CITypeCache.get(adc.type_id)
|
||||||
|
if ci_type and ci_type.name in NET_DEVICE_NAMES and 'ports' in adc.instance:
|
||||||
|
from api.tasks.cmdb import add_net_device_ports
|
||||||
|
add_net_device_ports.apply_async(args=(ci_id, adc.instance['ports']),
|
||||||
|
queue=CMDB_QUEUE)
|
||||||
|
|
||||||
adc.update(is_accept=True,
|
adc.update(is_accept=True,
|
||||||
accept_by=nickname or current_user.nickname,
|
accept_by=nickname or current_user.nickname,
|
||||||
accept_time=datetime.datetime.now(),
|
accept_time=datetime.datetime.now(),
|
||||||
|
@@ -4,6 +4,8 @@ from api.lib.cmdb.const import AutoDiscoveryType
|
|||||||
|
|
||||||
PRIVILEGED_USERS = ("cmdb_agent", "worker", "admin")
|
PRIVILEGED_USERS = ("cmdb_agent", "worker", "admin")
|
||||||
|
|
||||||
|
NET_DEVICE_NAMES = {"switch", 'router', 'firewall', 'printer'}
|
||||||
|
|
||||||
DEFAULT_INNER = [
|
DEFAULT_INNER = [
|
||||||
dict(name="阿里云", en="aliyun", type=AutoDiscoveryType.HTTP, is_inner=True, is_plugin=False,
|
dict(name="阿里云", en="aliyun", type=AutoDiscoveryType.HTTP, is_inner=True, is_plugin=False,
|
||||||
option={'icon': {'name': 'caise-aliyun'}, "en": "aliyun"}),
|
option={'icon': {'name': 'caise-aliyun'}, "en": "aliyun"}),
|
||||||
@@ -41,8 +43,12 @@ DEFAULT_INNER = [
|
|||||||
option={'icon': {'name': 'caise-luyouqi'}}),
|
option={'icon': {'name': 'caise-luyouqi'}}),
|
||||||
dict(name="防火墙", type=AutoDiscoveryType.SNMP, is_inner=True, is_plugin=False,
|
dict(name="防火墙", type=AutoDiscoveryType.SNMP, is_inner=True, is_plugin=False,
|
||||||
option={'icon': {'name': 'caise-fanghuoqiang'}}),
|
option={'icon': {'name': 'caise-fanghuoqiang'}}),
|
||||||
dict(name="打印机", type=AutoDiscoveryType.SNMP, is_inner=True, is_plugin=False,
|
# dict(name="打印机", type=AutoDiscoveryType.SNMP, is_inner=True, is_plugin=False,
|
||||||
option={'icon': {'name': 'caise-dayinji'}}),
|
# option={'icon': {'name': 'caise-dayinji'}}),
|
||||||
|
dict(name="光纤交换机", type=AutoDiscoveryType.SNMP, is_inner=True, is_plugin=False,
|
||||||
|
option={'icon': {'name': 'caise-fiber'}}),
|
||||||
|
dict(name="F5", type=AutoDiscoveryType.SNMP, is_inner=True, is_plugin=False,
|
||||||
|
option={'icon': {'name': 'caise-F5'}}),
|
||||||
]
|
]
|
||||||
|
|
||||||
CLOUD_MAP = {
|
CLOUD_MAP = {
|
||||||
|
@@ -1,37 +1,74 @@
|
|||||||
[{
|
[
|
||||||
"name":"manufacturer",
|
{
|
||||||
|
"name": "manufacturer",
|
||||||
"type": "文本",
|
"type": "文本",
|
||||||
"example":"HUAWEI Technology Co.,Ltd",
|
"example": "Huawei",
|
||||||
"desc":"制造产商"
|
"desc": "制造产商"
|
||||||
},{
|
},
|
||||||
"name":"sn",
|
{
|
||||||
|
"name": "sn",
|
||||||
"type": "文本",
|
"type": "文本",
|
||||||
"example":"102030059898",
|
"example": "102030059898",
|
||||||
"desc":"设备序列号"
|
"desc": "设备序列号"
|
||||||
},{
|
},
|
||||||
"name":"device_name",
|
{
|
||||||
|
"name": "name",
|
||||||
"type": "文本",
|
"type": "文本",
|
||||||
"example":"USG6525E",
|
"example": "USG6525E",
|
||||||
"desc":"设备名称"
|
"desc": "设备名称"
|
||||||
},{
|
},
|
||||||
"name":"device_model",
|
{
|
||||||
|
"name": "model",
|
||||||
"type": "文本",
|
"type": "文本",
|
||||||
"example":"2011.2.321.1.205",
|
"example": "2011.2.321.1.205",
|
||||||
"desc":"设备细分类型 结合相关产商获取相应的产品类型"
|
"desc": "设备细分类型 结合相关产商获取相应的产品类型"
|
||||||
},{
|
},
|
||||||
"name":"description",
|
{
|
||||||
|
"name": "description",
|
||||||
"type": "文本",
|
"type": "文本",
|
||||||
"example":"Huawei Vwersatile Routing Platform Software",
|
"example": "Huawei Vwersatile Routing Platform Software",
|
||||||
"desc":"设备描述"
|
"desc": "设备描述"
|
||||||
},{
|
},
|
||||||
"name":"manager_ip",
|
{
|
||||||
|
"name": "manager_ip",
|
||||||
"type": "文本",
|
"type": "文本",
|
||||||
"example":"192.168.1.1",
|
"example": "192.168.1.1",
|
||||||
"desc":"管理ip"
|
"desc": "管理ip"
|
||||||
}, {
|
},
|
||||||
"name":"ips",
|
{
|
||||||
|
"name": "ips",
|
||||||
"type": "文本、多值",
|
"type": "文本、多值",
|
||||||
"example":"192.168.1.1, 192.168.1.2",
|
"example": "192.168.1.1, 192.168.1.2",
|
||||||
"desc":"ips"
|
"desc": "ips"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"name": "uptime",
|
||||||
|
"type": "文本",
|
||||||
|
"example": "2023-04-15 10:00:00",
|
||||||
|
"desc": "启动时间"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "snmp_version",
|
||||||
|
"type": "文本",
|
||||||
|
"example": "v2c",
|
||||||
|
"desc": "SNMP版本"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "port_num",
|
||||||
|
"type": "整数",
|
||||||
|
"example": 24,
|
||||||
|
"desc": "端口数量"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ports",
|
||||||
|
"type": "json",
|
||||||
|
"example": "",
|
||||||
|
"desc": "设备的端口列表"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "neighbors",
|
||||||
|
"type": "json",
|
||||||
|
"example": "",
|
||||||
|
"desc": "设备的邻居列表"
|
||||||
|
}
|
||||||
]
|
]
|
@@ -376,6 +376,29 @@ def build_relations_for_ad_accept(adc, ci_id, ad_key2attr):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@celery.task(name="cmdb.add_net_device_ports", queue=CMDB_QUEUE)
|
||||||
|
@reconnect_db
|
||||||
|
def add_net_device_ports(ci_id, ports):
|
||||||
|
from api.lib.cmdb.ci import CIRelationManager
|
||||||
|
from api.lib.cmdb.ci import CIManager
|
||||||
|
from api.lib.cmdb.cache import CITypeCache
|
||||||
|
|
||||||
|
port_type = CITypeCache.get("net_port")
|
||||||
|
if not port_type:
|
||||||
|
current_app.logger.warning("CIType net port is not found")
|
||||||
|
return
|
||||||
|
|
||||||
|
for port in ports:
|
||||||
|
try:
|
||||||
|
port_id = CIManager.add(port_type.id, is_auto_discovery=True, _is_admin=True, **port)
|
||||||
|
|
||||||
|
CIRelationManager.add(ci_id, port_id,
|
||||||
|
valid=False,
|
||||||
|
source=RelationSourceEnum.AUTO_DISCOVERY)
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning("add_net_device_ports failed: {}".format(e))
|
||||||
|
|
||||||
|
|
||||||
@celery.task(name="cmdb.dcim_calc_u_free_count", queue=CMDB_QUEUE)
|
@celery.task(name="cmdb.dcim_calc_u_free_count", queue=CMDB_QUEUE)
|
||||||
@reconnect_db
|
@reconnect_db
|
||||||
def dcim_calc_u_free_count():
|
def dcim_calc_u_free_count():
|
||||||
|
Reference in New Issue
Block a user