forked from TencentBlueKing/blueking-dbm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): 巡检通用框架 TencentBlueKing#9120
- Loading branch information
Showing
25 changed files
with
360 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1. 报告结果 _model_ 继承 `BaseReportABS` | ||
2. 报告结果视图继承 `ReportBaseViewSet` | ||
3. 视图 | ||
3. 示例可以参考 `dbm-ui/backend/db_report/views/mysql/mysqlbackup_check_view.py` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
|
||
from django.apps import AppConfig | ||
|
||
from backend.db_report.register import register_all_reports | ||
|
||
|
||
class DbReportConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "backend.db_report" | ||
|
||
def ready(self): | ||
register_all_reports() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding:utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from django.utils.translation import ugettext_lazy as _ | ||
from django_filters import rest_framework as filters | ||
from django_filters.rest_framework import DjangoFilterBackend | ||
|
||
from backend.configuration.models import DBAdministrator | ||
|
||
|
||
class ReportListFilter(filters.FilterSet): | ||
manage = filters.CharFilter( | ||
field_name="manage", method="filter_manage", label=_("处理类型"), help_text=_("todo待我处理/assist待我协助") | ||
) | ||
cluster = filters.CharFilter(field_name="cluster", method="filter_cluster", label=_("集群名")) | ||
|
||
def filter_manage(self, queryset, name, value): | ||
username = self.request.user.username | ||
db_type = self.request.path.strip("/").split("/")[1] | ||
manage_bizs, assist_bizs = DBAdministrator.get_manage_bizs(db_type, username) | ||
# 待我处理 | ||
if value == "todo": | ||
return queryset.filter(bk_biz_id__in=manage_bizs) | ||
# 待我协助 | ||
elif value == "assist": | ||
return queryset.filter(bk_biz_id__in=assist_bizs) | ||
# 其他情况忽略 | ||
return queryset | ||
|
||
def filter_cluster(self, queryset, name, value): | ||
cluster = value.split(",") | ||
if len(cluster) == 1: | ||
return queryset.filter(cluster__icontains=cluster[0]) | ||
else: | ||
return queryset.filter(cluster__in=cluster) | ||
|
||
|
||
class ReportFilterBackend(DjangoFilterBackend): | ||
filterset_base = ReportListFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
import logging | ||
import os | ||
from collections import defaultdict | ||
from typing import Dict, List | ||
|
||
from backend.utils.register import re_import_modules | ||
from config import BASE_DIR | ||
|
||
logger = logging.getLogger("root") | ||
|
||
db_report_maps: Dict[str, List] = defaultdict(list) | ||
|
||
|
||
def register_report(db_type): | ||
"""巡检视图的注册器""" | ||
|
||
def decorator(report_cls): | ||
db_report_maps[db_type].append(report_cls) | ||
|
||
return decorator | ||
|
||
|
||
def register_all_reports(): | ||
"""递归注册当前目录下所有的巡检报告""" | ||
re_import_modules(path=os.path.join(BASE_DIR, "backend/db_report/views"), module_path="backend.db_report.views") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.