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

feature: 通知中心接入 (closed #2059) #2064

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions apps/node_man/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from bk_notice_sdk.views import api_call
from blueapps.utils.esbclient import get_client_by_user
from django.apps import AppConfig
from django.conf import settings
Expand Down Expand Up @@ -106,3 +107,18 @@ def init_settings(cls):
key=GlobalSettings.KeyEnum.REGISTER_WIN_SERVICE_WITH_PASS.value, defaults=dict(v_json=False)
)
settings.REGISTER_WIN_SERVICE_WITH_PASS = obj.v_json

# 注册消息中心app(适配各个环境只注册一次)
obj, _ = GlobalSettings.objects.get_or_create(
key=GlobalSettings.KeyEnum.ENABLE_NOTICE_CENTER.value, defaults=dict(v_json=False)
)
enable_notice_center: bool = obj.v_json
if not enable_notice_center:
response = api_call(
api_method="register_application", success_message="注册平台成功", error_message="注册平台异常", success_code=201
)
if response.get("result") is True:
GlobalSettings.update_config(key=GlobalSettings.KeyEnum.ENABLE_NOTICE_CENTER.value, value=True)
enable_notice_center: bool = True

settings.ENABLE_NOTICE_CENTER = enable_notice_center
2 changes: 2 additions & 0 deletions apps/node_man/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class KeyEnum(Enum):
BACKEND_SERVICE_POLLING_TIMEOUT = "BACKEND_SERVICE_POLLING_TIMEOUT"
# 管控区域新增主机黑名单,用于限制指定管控区域通过安装 Agent 新增主机,配置样例:[1, 2]
ADD_HOST_CLOUD_BLACKLIST = "ADD_HOST_CLOUD_BLACKLIST"
# 消息中心开关
ENABLE_NOTICE_CENTER = "ENABLE_NOTICE_CENTER"

key = models.CharField(_("键"), max_length=255, db_index=True, primary_key=True)
v_json = JSONField(_("值"))
Expand Down
4 changes: 3 additions & 1 deletion common/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from blueapps.account.conf import ConfFixture
from django.conf import settings
from django.utils.translation import ugettext as _
from version_log.utils import get_latest_version

from apps.core.concurrent.cache import FuncCacheDecorator
from apps.node_man import constants, models
from apps.node_man.handlers.iam import IamHandler
from apps.utils.local import get_request_username
from version_log.utils import get_latest_version

"""
context_processor for common(setting)
Expand Down Expand Up @@ -111,4 +111,6 @@ def mysetting(request):
"BK_DOMAIN": settings.BK_DOMAIN,
"BK_COMPONENT_API_URL": settings.BK_COMPONENT_API_OUTER_URL,
"ENABLE_AP_VERSION_MUTEX": get_ap_version_mutex(),
# 是否开启消息中心
"ENABLE_NOTICE_CENTER": settings.ENABLE_NOTICE_CENTER,
}
2 changes: 2 additions & 0 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"blueapps.opentelemetry.instrument_app",
# apigw
"apigw_manager.apigw",
# bk-notice
"bk_notice_sdk",
)

# 这里是默认的中间件,大部分情况下,不需要改动
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ bk-monitor-report==1.2.1


apigw-manager[cryptography]==1.1.5
cryptography==3.3.2
cryptography==3.3.2

# notice
bk-notice-sdk==1.2.0
3 changes: 3 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
specific language governing permissions and limitations under the License.
"""

from bk_notice_sdk import config as notice_config
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.urls import re_path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

from version_log import config

schema_view = get_schema_view(
Expand All @@ -38,6 +40,7 @@
url(r"^core/", include("apps.core.urls")),
url(r"^", include("apps.node_man.urls")),
url(r"^{}".format(config.ENTRANCE_URL), include("version_log.urls", namespace="version_log")),
url(r"^{}".format(notice_config.ENTRANCE_URL), include(("bk_notice_sdk.urls", "notice"), namespace="notice")),
]

if settings.ENVIRONMENT not in ["production", "prod"]:
Expand Down
Loading