diff --git a/packages/discord_gcp_alerts/lib/src/gcp_alert_handler.dart b/packages/discord_gcp_alerts/lib/src/gcp_alert_handler.dart index 2bd314d8..580f3933 100644 --- a/packages/discord_gcp_alerts/lib/src/gcp_alert_handler.dart +++ b/packages/discord_gcp_alerts/lib/src/gcp_alert_handler.dart @@ -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, diff --git a/packages/discord_gcp_alerts/lib/src/models/gcp_alert.dart b/packages/discord_gcp_alerts/lib/src/models/gcp_alert.dart index 8b09aaca..e9120e7a 100644 --- a/packages/discord_gcp_alerts/lib/src/models/gcp_alert.dart +++ b/packages/discord_gcp_alerts/lib/src/models/gcp_alert.dart @@ -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; diff --git a/packages/discord_gcp_alerts/lib/src/models/gcp_alert.g.dart b/packages/discord_gcp_alerts/lib/src/models/gcp_alert.g.dart index 14c93e81..ee0d36bc 100644 --- a/packages/discord_gcp_alerts/lib/src/models/gcp_alert.g.dart +++ b/packages/discord_gcp_alerts/lib/src/models/gcp_alert.g.dart @@ -33,11 +33,13 @@ Incident _$IncidentFromJson(Map 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' }, ); diff --git a/packages/discord_gcp_alerts/test/src/gcp_alert_handler_test.dart b/packages/discord_gcp_alerts/test/src/gcp_alert_handler_test.dart index 828c0679..389e5549 100644 --- a/packages/discord_gcp_alerts/test/src/gcp_alert_handler_test.dart +++ b/packages/discord_gcp_alerts/test/src/gcp_alert_handler_test.dart @@ -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,