Skip to content

Commit

Permalink
feat(backend): 故障自愈优化 #6574
Browse files Browse the repository at this point in the history
feat(backend): 故障自愈优化 #6574
# Reviewed, transaction id: 17155
  • Loading branch information
zhangzhw8 committed Sep 3, 2024
1 parent f209824 commit e602b0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 17 additions & 11 deletions dbm-ui/backend/db_monitor/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 json
import urllib.parse

from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -100,7 +99,9 @@ class MonitorPolicySerializer(AuditedSerializer, serializers.ModelSerializer):
event_url = serializers.SerializerMethodField(method_name="get_event_url")

def get_event_url(self, obj):
"""监控事件跳转链接"""
"""
监控事件跳转链接
"""

bk_biz_id = obj.bk_biz_id or env.DBA_APP_BK_BIZ_ID
query_string = urllib.parse.urlencode(
Expand Down Expand Up @@ -137,7 +138,9 @@ class Meta:

class MonitorPolicyUpdateSerializer(AuditedSerializer, serializers.ModelSerializer):
class TargetSerializer(serializers.Serializer):
"""告警目标"""
"""
告警目标
"""

class TargetRuleSerializer(serializers.Serializer):
key = serializers.ChoiceField(choices=TargetLevel.get_choices())
Expand All @@ -147,7 +150,9 @@ class TargetRuleSerializer(serializers.Serializer):
rule = TargetRuleSerializer()

class TestRuleSerializer(serializers.Serializer):
"""检测规则"""
"""
检测规则
"""

class TestRuleConfigSerializer(serializers.Serializer):
method = serializers.ChoiceField(choices=OperatorEnum.get_choices())
Expand Down Expand Up @@ -218,6 +223,10 @@ class ListModuleSerializer(ListClusterSerializer):


class AlarmCallBackDataSerializer(serializers.Serializer):
"""
告警回调数据
"""

class CallBackMessageSerializer(serializers.Serializer):
event = serializers.DictField(help_text=_("告警事件"))
strategy = serializers.DictField(help_text=_("监控策略"))
Expand All @@ -234,19 +243,16 @@ def to_internal_value(self, data):
data = super().to_internal_value(data)
ticket_types = []

# 取告警负责人作为单据创建人
try:
data["creator"] = json.loads(data["appointees"].replace("'", '"'))[0]
except IndexError:
data["creator"] = "system"

# 取关联的的故障自愈处理单据
for label in data["callback_message"].get("labels") or []:
if label.startswith("NEED_AUTOFIX"):
ticket_type = label.split("/")[1]
if ticket_type in TicketType.get_values():
ticket_types.append(ticket_type)

# 未匹配到故障自愈处理单据
if not ticket_types:
raise AutofixException(_("未匹配到对应的故障自愈处理单据,请确认是否配置正确"))
data["ticket_types"] = ticket_types

data.update({"ticket_types": ticket_types, "creator": "bkmonitor"})
return data
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ class SQLServerClearFlowBuilder(BaseSQLServerTicketFlowBuilder):
inner_flow_builder = SQLServerClearFlowParamBuilder
inner_flow_name = _("SQLServer 同步数据")
retry_type = FlowRetryType.MANUAL_RETRY
default_need_itsm = False
default_need_manual_confirm = False

0 comments on commit e602b0f

Please sign in to comment.