Skip to content

Commit

Permalink
feat(backend): 告警组接口补充 close #1291
Browse files Browse the repository at this point in the history
  • Loading branch information
Myfatguy11 authored and zhangzhw8 committed Oct 9, 2023
1 parent 7ffef41 commit 8cc3766
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions dbm-ui/backend/db_monitor/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
Expand Down
10 changes: 9 additions & 1 deletion dbm-ui/backend/db_monitor/views/notice_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions dbm-ui/scripts/snippets/uninstall_hdfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8cc3766

Please sign in to comment.