fix(cloudwatch): retain metric-math alarm query definitions (#4594) #6
+33
-7
@@ -3,8 +3,6 @@ package io.github.hectorvent.floci.services.cloudwatch.metrics;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
|
||||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
|
||||||
import io.github.hectorvent.floci.services.cloudwatch.metrics.model.MetricAlarm;
|
import io.github.hectorvent.floci.services.cloudwatch.metrics.model.MetricAlarm;
|
||||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
@@ -22,6 +20,38 @@ import java.util.Map;
|
|||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class AlarmSnsNotifier {
|
public class AlarmSnsNotifier {
|
||||||
|
|
||||||
|
/** The names CloudWatch writes in the alarm message's Region field; other regions use their ID. */
|
||||||
|
private static final Map<String, String> REGION_NAMES = Map.ofEntries(
|
||||||
|
Map.entry("us-east-1", "US East (N. Virginia)"),
|
||||||
|
Map.entry("us-east-2", "US East (Ohio)"),
|
||||||
|
Map.entry("us-west-1", "US West (N. California)"),
|
||||||
|
Map.entry("us-west-2", "US West (Oregon)"),
|
||||||
|
Map.entry("ca-central-1", "Canada (Central)"),
|
||||||
|
Map.entry("ca-west-1", "Canada West (Calgary)"),
|
||||||
|
Map.entry("sa-east-1", "South America (Sao Paulo)"),
|
||||||
|
Map.entry("eu-west-1", "EU (Ireland)"),
|
||||||
|
Map.entry("eu-west-2", "EU (London)"),
|
||||||
|
Map.entry("eu-west-3", "EU (Paris)"),
|
||||||
|
Map.entry("eu-central-1", "EU (Frankfurt)"),
|
||||||
|
Map.entry("eu-central-2", "EU (Zurich)"),
|
||||||
|
Map.entry("eu-north-1", "EU (Stockholm)"),
|
||||||
|
Map.entry("eu-south-1", "EU (Milan)"),
|
||||||
|
Map.entry("eu-south-2", "EU (Spain)"),
|
||||||
|
Map.entry("me-south-1", "Middle East (Bahrain)"),
|
||||||
|
Map.entry("me-central-1", "Middle East (UAE)"),
|
||||||
|
Map.entry("il-central-1", "Israel (Tel Aviv)"),
|
||||||
|
Map.entry("af-south-1", "Africa (Cape Town)"),
|
||||||
|
Map.entry("ap-east-1", "Asia Pacific (Hong Kong)"),
|
||||||
|
Map.entry("ap-south-1", "Asia Pacific (Mumbai)"),
|
||||||
|
Map.entry("ap-south-2", "Asia Pacific (Hyderabad)"),
|
||||||
|
Map.entry("ap-northeast-1", "Asia Pacific (Tokyo)"),
|
||||||
|
Map.entry("ap-northeast-2", "Asia Pacific (Seoul)"),
|
||||||
|
Map.entry("ap-northeast-3", "Asia Pacific (Osaka)"),
|
||||||
|
Map.entry("ap-southeast-1", "Asia Pacific (Singapore)"),
|
||||||
|
Map.entry("ap-southeast-2", "Asia Pacific (Sydney)"),
|
||||||
|
Map.entry("ap-southeast-3", "Asia Pacific (Jakarta)"),
|
||||||
|
Map.entry("ap-southeast-4", "Asia Pacific (Melbourne)"));
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(AlarmSnsNotifier.class);
|
private static final Logger LOG = Logger.getLogger(AlarmSnsNotifier.class);
|
||||||
private static final DateTimeFormatter TIMESTAMP_FORMAT = DateTimeFormatter
|
private static final DateTimeFormatter TIMESTAMP_FORMAT = DateTimeFormatter
|
||||||
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT).withZone(ZoneOffset.UTC);
|
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT).withZone(ZoneOffset.UTC);
|
||||||
@@ -74,11 +104,7 @@ public class AlarmSnsNotifier {
|
|||||||
payload.put("NewStateValue", alarm.getStateValue());
|
payload.put("NewStateValue", alarm.getStateValue());
|
||||||
payload.put("NewStateReason", alarm.getStateReason());
|
payload.put("NewStateReason", alarm.getStateReason());
|
||||||
payload.put("StateChangeTime", timestamp(alarm.getStateUpdatedTimestamp()));
|
payload.put("StateChangeTime", timestamp(alarm.getStateUpdatedTimestamp()));
|
||||||
String regionName = AwsPartitions.forRegion(arn.region()).stream()
|
payload.put("Region", REGION_NAMES.getOrDefault(arn.region(), arn.region()));
|
||||||
.flatMap(partition -> partition.regions().stream())
|
|
||||||
.filter(region -> region.id().equals(arn.region()))
|
|
||||||
.map(AwsPartition.Region::description).findFirst().orElse(arn.region());
|
|
||||||
payload.put("Region", regionName);
|
|
||||||
payload.put("AlarmArn", alarm.getAlarmArn());
|
payload.put("AlarmArn", alarm.getAlarmArn());
|
||||||
payload.put("OldStateValue", oldState);
|
payload.put("OldStateValue", oldState);
|
||||||
payload.put("OKActions", alarm.getOkActions());
|
payload.put("OKActions", alarm.getOkActions());
|
||||||
|
|||||||
Reference in New Issue
Block a user