feat(discord_gcp_alerts): include policy name in alert title (#431)

This commit is contained in:
Felix Angelov
2023-05-03 10:23:33 -05:00
committed by GitHub
parent a3a630f59a
commit 1cb81545c3
4 changed files with 10 additions and 3 deletions
@@ -18,10 +18,11 @@ Handler gcpAlertHandler({required String webhookUrl, http.Client? client}) {
final url = incident?.url;
final resource = incident?.resourceName;
final conditionName = incident?.conditionName;
final policyName = incident?.policyName ?? 'GCP Alert';
final discordPayload = {
'embeds': [
{
'title': 'GCP Alert',
'title': '🚨 $policyName 🚨',
'description': summary,
'url': url,
'color': 0xFF0000,
@@ -37,6 +37,7 @@ class Incident {
this.summary,
this.resourceName,
this.conditionName,
this.policyName,
});
/// Creates an [Incident] from a JSON [Map].
@@ -52,6 +53,9 @@ class Incident {
/// A summary of the incident.
final String? summary;
/// The name of the policy associated with the incident.
final String? policyName;
/// The name of the resource.
final String? resourceName;
@@ -33,11 +33,13 @@ Incident _$IncidentFromJson(Map<String, dynamic> json) => $checkedCreate(
summary: $checkedConvert('summary', (v) => v as String?),
resourceName: $checkedConvert('resource_name', (v) => v as String?),
conditionName: $checkedConvert('condition_name', (v) => v as String?),
policyName: $checkedConvert('policy_name', (v) => v as String?),
);
return val;
},
fieldKeyMap: const {
'resourceName': 'resource_name',
'conditionName': 'condition_name'
'conditionName': 'condition_name',
'policyName': 'policy_name'
},
);
@@ -94,7 +94,7 @@ void main() {
body: json.encode({
'embeds': [
{
'title': 'GCP Alert',
'title': '🚨 projects/12345/alertPolicies/12345 🚨',
'description': 'Test Incident',
'url': 'http://www.example.com',
'color': 16711680,