Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: 监控(告警屏蔽范围)支持ipv6和ipv4主机 #7087

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions pipeline_plugins/components/collections/sites/open/monitor/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import ipaddress
from functools import partial

from django.conf import settings
Expand Down Expand Up @@ -37,21 +38,46 @@ def build_request_body(self, begin_time, bk_biz_id, shied_type, dimension_config
def get_ip_dimension_config(self, scope_value, bk_biz_id, username):
ip_list = scope_value.split(",")
if settings.ENABLE_IPV6:
hosts = cmdb.get_business_host_ipv6(
# 开启了IPV6 要同时查ipv6和ipv4
ipv4_list = []
ipv6_list = []

for ip in ip_list:
p_address = ipaddress.ip_address(ip)
if p_address.version == 6:
ipv6_list.append(ip)
else:
ipv4_list.append(ip)

ip_v6_hosts = cmdb.get_business_host_ipv6(
username=username,
bk_biz_id=bk_biz_id,
supplier_account=Business.objects.supplier_account_for_business(bk_biz_id),
host_fields=["bk_host_id", "bk_cloud_id", "bk_host_innerip", "bk_host_innerip_v6"],
ip_list=ip_list,
ip_list=ipv6_list,
)
# 监控接口不支持 host_id, 进支持 ip
host_without_innerip = [host for host in hosts if host["bk_host_innerip"] == ""]
host_without_innerip = [host for host in ip_v6_hosts if host["bk_host_innerip"] == ""]
if host_without_innerip:
raise Exception(
_("主机[{}]innerip字段为空,蓝鲸监控接口仅支持通过该字段进行ip传参").format(
",".join([str(host["bk_host_id"]) for host in host_without_innerip])
)
)

ip_v4_hosts = cmdb.get_business_host(
username=username,
bk_biz_id=bk_biz_id,
supplier_account=Business.objects.supplier_account_for_business(bk_biz_id),
host_fields=["bk_host_id", "bk_cloud_id", "bk_host_innerip"],
ip_list=ipv4_list,
)

if not ip_v4_hosts:
raise Exception(_("当前业务下未查询到ip信息, 请检查ip地址是否填写正确:{}").format(ipv4_list))

hosts = ip_v4_hosts + ip_v6_hosts

else:
hosts = cmdb.get_business_host(
username=username,
Expand Down
Loading