4
4
import base64
5
5
import dataclasses
6
6
import datetime
7
+ import json
7
8
import logging
8
9
import os
9
10
import random
@@ -215,8 +216,8 @@ def format_alert(event: dict) -> AlertDto:
215
216
severity = event .get ("ProblemSeverity" , None ),
216
217
lastReceived = datetime .datetime .now ().isoformat (),
217
218
fatigueMeter = random .randint (0 , 100 ),
218
- description = event . get (
219
- "ImpactedEntities"
219
+ description = json . dumps (
220
+ event . get ( "ImpactedEntities" , {})
220
221
), # was asked by a user (should be configurable)
221
222
source = ["dynatrace" ],
222
223
impact = event .get ("ProblemImpact" ),
@@ -233,17 +234,17 @@ def format_alert(event: dict) -> AlertDto:
233
234
)
234
235
# else, problem from the problem API
235
236
else :
236
- event .pop ("problemId" )
237
+ _id = event .pop ("problemId" )
237
238
name = event .pop ("displayId" )
238
239
status = event .pop ("status" )
239
240
severity = event .pop ("severityLevel" , None )
240
241
description = event .pop ("title" )
241
242
impact = event .pop ("impactLevel" )
242
243
tags = event .pop ("entityTags" )
243
244
impacted_entities = event .pop ("impactedEntities" , [])
244
- url = event .pop ("ProblemURL" )
245
+ url = event .pop ("ProblemURL" , None )
245
246
alert_dto = AlertDto (
246
- id = id ,
247
+ id = _id ,
247
248
name = name ,
248
249
status = status ,
249
250
severity = severity ,
@@ -336,7 +337,7 @@ def setup_webhook(
336
337
"notifyClosedProblems" : True ,
337
338
"notifyEventMergesEnabled" : True ,
338
339
# all the fields - https://docs.dynatrace.com/docs/observe-and-explore/notifications-and-alerting/problem-notifications/webhook-integration#example-json-with-placeholders
339
- "payload" : '{\n "State":"{State}",\n "ProblemID":"{ProblemID}",\n "ProblemTitle":"{ProblemTitle}",\n "ImpactedEntities": {ImpactedEntities},\n "PID": "{PID}",\n "ProblemDetailsJSON": {ProblemDetailsJSON},\n "ProblemImpact" : "{ProblemImpact}",\n "ProblemSeverity": "{ProblemSeverity}",\n "ProblemURL": "{ProblemURL}",\n "State": "{State}",\n "Tags": "{Tags}"\n "ProblemDetails": "{ProblemDetailsText}"\n "NamesOfImpactedEntities": "{NamesOfImpactedEntities}"\n "ImpactedEntity": "{ImpactedEntity}"\n "ImpactedEntityNames": "{ImpactedEntityNames}"\n "ProblemDetailsJSONv2": {ProblemDetailsJSONv2}\n \n }' ,
340
+ "payload" : '{\n "State":"{State}",\n "ProblemID":"{ProblemID}",\n "ProblemTitle":"{ProblemTitle}",\n "ImpactedEntities": {ImpactedEntities},\n "PID": "{PID}",\n "ProblemDetailsJSON": {ProblemDetailsJSON},\n "ProblemImpact" : "{ProblemImpact}",\n "ProblemSeverity": "{ProblemSeverity}",\n "ProblemURL": "{ProblemURL}",\n "State": "{State}",\n "Tags": "{Tags}", \n "ProblemDetails": "{ProblemDetailsText}", \n "NamesOfImpactedEntities": "{NamesOfImpactedEntities}", \n "ImpactedEntity": "{ImpactedEntity}", \n "ImpactedEntityNames": "{ImpactedEntityNames}", \n "ProblemDetailsJSONv2": {ProblemDetailsJSONv2}\n }' ,
340
341
},
341
342
}
342
343
actual_payload = [
0 commit comments