@@ -41,6 +41,39 @@ def cloudwatch_notification(message, region):
4141 }
4242
4343
44+ def guardduty_finding (message , region ):
45+ states = {'Low' : '#777777' , 'Medium' : 'warning' , 'High' : 'danger' }
46+ if region .startswith ("us-gov-" ):
47+ guardduty_url = "https://console.amazonaws-us-gov.com/guardduty/home?region="
48+ else :
49+ guardduty_url = "https://console.aws.amazon.com/guardduty/home?region="
50+
51+ if message ['detail' ]['severity' ] < 4.0 :
52+ severity = 'Low'
53+ elif message ['detail' ]['severity' ] < 7.0 :
54+ severity = 'Medium'
55+ else :
56+ severity = 'High'
57+
58+ return {
59+ "color" : states [severity ],
60+ "fallback" : "GuardDuty Finding: {}" .format (message ['detail' ]['title' ]),
61+ "fields" : [
62+ {"title" : "Description" , "value" : message ['detail' ]['description' ], "short" : False },
63+ {"title" : "Finding type" , "value" : message ['detail' ]['type' ], "short" : False },
64+ {"title" : "First Seen" , "value" : message ['detail' ]['service' ]['eventFirstSeen' ], "short" : True },
65+ {"title" : "Last Seen" , "value" : message ['detail' ]['service' ]['eventLastSeen' ], "short" : True },
66+ {"title" : "Severity" , "value" : severity , "short" : True },
67+ {"title" : "Count" , "value" : message ['detail' ]['service' ]['count' ], "short" : True },
68+ {
69+ "title" : "Link to Finding" ,
70+ "value" : guardduty_url + region + "#/findings?search=id%3D" + message ['detail' ]['id' ],
71+ "short" : False
72+ }
73+ ]
74+ }
75+
76+
4477def default_notification (subject , message ):
4578 attachments = {
4679 "fallback" : "A new message" ,
@@ -91,6 +124,10 @@ def notify_slack(subject, message, region):
91124 notification = cloudwatch_notification (message , region )
92125 payload ['text' ] = "AWS CloudWatch notification - " + message ["AlarmName" ]
93126 payload ['attachments' ].append (notification )
127+ elif "detail-type" in message and message ["detail-type" ] == "GuardDuty Finding" :
128+ notification = guardduty_finding (message , message ["region" ])
129+ payload ['text' ] = "Amazon GuardDuty Finding - " + message ["detail" ]["title" ]
130+ payload ['attachments' ].append (notification )
94131 elif "attachments" in message or "text" in message :
95132 payload = {** payload , ** message }
96133 else :
0 commit comments