use of software.amazon.awssdk.services.cloudwatch.model.DeleteAlarmsRequest in project aws-sdk-java-v2 by aws.
the class CloudWatchIntegrationTest method cleanupAlarms.
/**
* Cleans up any existing alarms before and after running the test suite
*/
@AfterClass
public static void cleanupAlarms() {
if (cloudwatch != null) {
DescribeAlarmsResponse describeResult = cloudwatch.describeAlarms(DescribeAlarmsRequest.builder().build());
Collection<String> toDelete = new LinkedList<>();
for (MetricAlarm alarm : describeResult.metricAlarms()) {
if (alarm.metricName().startsWith(CloudWatchIntegrationTest.class.getName())) {
toDelete.add(alarm.alarmName());
}
}
if (!toDelete.isEmpty()) {
DeleteAlarmsRequest delete = DeleteAlarmsRequest.builder().alarmNames(toDelete).build();
cloudwatch.deleteAlarms(delete);
}
}
}
use of software.amazon.awssdk.services.cloudwatch.model.DeleteAlarmsRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteAlarm method deleteCWAlarm.
// snippet-start:[cloudwatch.java2.delete_metrics.main]
public static void deleteCWAlarm(CloudWatchClient cw, String alarmName) {
try {
DeleteAlarmsRequest request = DeleteAlarmsRequest.builder().alarmNames(alarmName).build();
cw.deleteAlarms(request);
System.out.printf("Successfully deleted alarm %s", alarmName);
} catch (CloudWatchException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations