From 8cc3766c16ee7e554ff00ba1a21209177fe8b8a6 Mon Sep 17 00:00:00 2001 From: gaohongsong Date: Mon, 9 Oct 2023 17:28:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E5=91=8A=E8=AD=A6=E7=BB=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=A1=A5=E5=85=85=20close=20#1291?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_monitor/serializers.py | 5 +++++ dbm-ui/backend/db_monitor/views/notice_group.py | 10 +++++++++- dbm-ui/scripts/snippets/uninstall_hdfs.sh | 2 -- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dbm-ui/backend/db_monitor/serializers.py b/dbm-ui/backend/db_monitor/serializers.py index 5d36c77a46..0f25648bdd 100644 --- a/dbm-ui/backend/db_monitor/serializers.py +++ b/dbm-ui/backend/db_monitor/serializers.py @@ -41,6 +41,11 @@ class DashboardUrlSerializer(serializers.Serializer): class NoticeGroupSerializer(AuditedSerializer, serializers.ModelSerializer): + used_count = serializers.SerializerMethodField() + + def get_used_count(self, obj): + return self.context["group_used"].get(obj.id, 0) + class Meta: model = NoticeGroup fields = "__all__" diff --git a/dbm-ui/backend/db_monitor/views/notice_group.py b/dbm-ui/backend/db_monitor/views/notice_group.py index fb22995b74..46e45bbca5 100644 --- a/dbm-ui/backend/db_monitor/views/notice_group.py +++ b/dbm-ui/backend/db_monitor/views/notice_group.py @@ -8,6 +8,8 @@ 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 collections import Counter + import django_filters from django.db.models import Q from django.utils.decorators import method_decorator @@ -21,7 +23,7 @@ from backend.components import CCApi, CmsiApi from backend.configuration.constants import PLAT_BIZ_ID from backend.db_monitor import serializers -from backend.db_monitor.models import NoticeGroup +from backend.db_monitor.models import MonitorPolicy, NoticeGroup from backend.db_monitor.serializers import NoticeGroupSerializer from backend.iam_app.handlers.drf_perm import DBManageIAMPermission @@ -86,6 +88,12 @@ class MonitorNoticeGroupViewSet(viewsets.AuditedModelViewSet): def _get_custom_permissions(self): return [DBManageIAMPermission()] + def get_serializer_context(self): + context = super().get_serializer_context() + notify_groups = MonitorPolicy.objects.exclude(notify_groups=[]).values_list("notify_groups", flat=True) + context["group_used"] = dict(Counter([item for group in notify_groups for item in group])) + return context + @common_swagger_auto_schema(operation_summary=_("查询通知类型"), tags=[SWAGGER_TAG]) @action(methods=["GET"], detail=False) def get_msg_type(self, request, *args, **kwargs): diff --git a/dbm-ui/scripts/snippets/uninstall_hdfs.sh b/dbm-ui/scripts/snippets/uninstall_hdfs.sh index b4c3ed72da..a566a7866b 100644 --- a/dbm-ui/scripts/snippets/uninstall_hdfs.sh +++ b/dbm-ui/scripts/snippets/uninstall_hdfs.sh @@ -20,8 +20,6 @@ ps -ef | grep haproxy | grep -v grep | awk '{print $2}' | xargs kill -s 9 ps -ef | grep telegraf | grep -v grep | awk '{print $2}' | xargs kill -s 9 ps -ef | grep -i filebeat | grep -v grep | awk '{print $2}' | xargs kill -s 9 -crontab -r - userdel -f hadoop userdel -f telegraf userdel -f haproxy