Skip to content

Commit

Permalink
feat(backend): agent2.0适配 close #1013
Browse files Browse the repository at this point in the history
  • Loading branch information
Myfatguy11 authored and zhangzhw8 committed Sep 7, 2023
1 parent c4c398d commit 84649fe
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
10 changes: 9 additions & 1 deletion dbm-ui/backend/components/gse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ def __init__(self):
base=GSE_APIGW_DOMAIN,
url="get_agent_status/",
module=self.MODULE,
description=_("Agent在线状态查询"),
description=_("Agent在线状态查询 - 1.0"),
)

self.list_agent_state = DataAPI(
method="POST",
base=GSE_APIGW_DOMAIN,
url="list_agent_state/",
module=self.MODULE,
description=_("查询Agent状态列表信息 - 2.0"),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def details_base(
"bk_biz_id": bk_biz_id,
"fields": [
"bk_host_id",
"bk_agent_id",
"bk_host_name",
"bk_os_type",
"bk_host_innerip",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def query_host_id_infos(
conditions,
start,
page_size,
["bk_host_id", "bk_host_innerip", "bk_host_innerip_v6", "bk_cloud_id"],
["bk_host_id", "bk_host_innerip", "bk_host_innerip_v6", "bk_cloud_id", "bk_agent_id"],
)

return {"total": resp["count"], "data": BaseHandler.format_host_id_infos(resp["info"], tree_node["bk_biz_id"])}
Expand Down
43 changes: 38 additions & 5 deletions dbm-ui/backend/db_services/ipchooser/query/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.core.cache import cache
from django.utils.translation import ugettext as _

from backend import env
from backend.bk_web.constants import CACHE_1D
from backend.components import CCApi
from backend.components.gse.client import GseApi
Expand Down Expand Up @@ -193,10 +194,8 @@ def query_cc_hosts(
return resp

@staticmethod
def fill_agent_status(cc_hosts, fill_key="status"):

if not cc_hosts:
return
def query_agent_one_status(cc_hosts, fill_key="status"):
"""查询agent1.0状态"""

index = 0
hosts, host_map = [], {}
Expand All @@ -211,9 +210,43 @@ def fill_agent_status(cc_hosts, fill_key="status"):
status_map = GseApi.get_agent_status({"hosts": hosts})

for ip_cloud, detail in status_map.items():
# agent在线状态,0为不在线,1为在线
cc_hosts[host_map[ip_cloud]][fill_key] = detail["bk_agent_alive"]
except KeyError as e:
logger.error("fill_agent_status exception: %s", e)
logger.error("query_agent_one_status exception: %s", e)

@staticmethod
def query_agent_two_status(cc_hosts, fill_key="status"):
"""查询agent2.0状态"""
index = 0
agent_id_list, host_map = [], {}
for cc_host in cc_hosts:
bk_agent_id = cc_host["bk_agent_id"]
agent_id_list.append(bk_agent_id)
host_map[bk_agent_id] = index
index += 1

try:
status_list = GseApi.list_agent_state({"agent_id_list": agent_id_list})

for status in status_list:
# Agent当前运行状态码, -1:未知 0:初始安装 1:启动中 2:运行中 3:有损状态 4:繁忙状态 5:升级中 6:停止中 7:解除安装
cc_hosts[host_map[status["bk_agent_id"]]][fill_key] = 1 if status["status_code"] == 2 else 0
except KeyError as e:
logger.error("query_agent_two_status exception: %s", e)

@staticmethod
def fill_agent_status(cc_hosts, fill_key="status"):
if not cc_hosts:
return

if env.GSE_AGENT_VERSION == "1.0":
ResourceQueryHelper.query_agent_one_status(cc_hosts, fill_key)
return

if env.GSE_AGENT_VERSION == "2.0":
ResourceQueryHelper.query_agent_two_status(cc_hosts, fill_key)
return

@staticmethod
def fill_cloud_name(cc_hosts):
Expand Down
3 changes: 3 additions & 0 deletions dbm-ui/backend/env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@

# 备份系统是否开启
BACKUP_SYSTEM_ENABLED = get_type_env(key="BACKUP_SYSTEM_ENABLED", _type=bool, default=False)

# Agent版本: 1.0/2.0
GSE_AGENT_VERSION = get_type_env(key="GSE_AGENT_VERSION", _type=str, default="1.0")

0 comments on commit 84649fe

Please sign in to comment.