Search in sources :

Example 1 with DeleteAlarmsRequest

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);
        }
    }
}
Also used : MetricAlarm(software.amazon.awssdk.services.cloudwatch.model.MetricAlarm) DeleteAlarmsRequest(software.amazon.awssdk.services.cloudwatch.model.DeleteAlarmsRequest) DescribeAlarmsResponse(software.amazon.awssdk.services.cloudwatch.model.DescribeAlarmsResponse) LinkedList(java.util.LinkedList) AfterClass(org.junit.AfterClass)

Example 2 with DeleteAlarmsRequest

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);
    }
}
Also used : CloudWatchException(software.amazon.awssdk.services.cloudwatch.model.CloudWatchException) DeleteAlarmsRequest(software.amazon.awssdk.services.cloudwatch.model.DeleteAlarmsRequest)

Aggregations

DeleteAlarmsRequest (software.amazon.awssdk.services.cloudwatch.model.DeleteAlarmsRequest)2 LinkedList (java.util.LinkedList)1 AfterClass (org.junit.AfterClass)1 CloudWatchException (software.amazon.awssdk.services.cloudwatch.model.CloudWatchException)1 DescribeAlarmsResponse (software.amazon.awssdk.services.cloudwatch.model.DescribeAlarmsResponse)1 MetricAlarm (software.amazon.awssdk.services.cloudwatch.model.MetricAlarm)1