#!/bin/env zx

import { exit } from "process";

const regions = JSON.parse(await $`aws ec2 describe-regions`).Regions.map(r => r.RegionName).filter(r => r.startsWith("us-") || r.startsWith("eu-"));

console.log("Available regions:", regions);

let pricings = []

for (const region of regions) {
    let alarms = JSON.parse(await $`aws cloudwatch describe-alarms --region ${region}`).MetricAlarms;

    // Delete alarms that have InsufficientData state

    for (const alarm of alarms) {
        if (alarm.StateValue === "INSUFFICIENT_DATA") {
            console.log(`Deleting alarm: ${alarm.AlarmName} in region ${region}`);
            await $`aws cloudwatch delete-alarms --alarm-names ${alarm.AlarmName} --region ${region}`;
        }
    }
}