Search... Ctrl + K

Find Monitors (datadog)
One script reply has been approved by the moderators Verified

Created by rossmccrann 136 days ago Used 37 times 1 Point

No comments yet

Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.19.2/mod.ts";
import ApiClient from "https://deno.land/x/datadog_api/client.ts";
import V1MonitorsApi from "https://deno.land/x/datadog_api/v1/monitors.ts";

export async function main(
    dd_auth: wmill.Resource<"datadog">,
) {
    let count = 0;
    // Set up a Monitors API client
    const datadog = new ApiClient(dd_auth);
    const monitorsApi = new V1MonitorsApi(datadog);

    let monitor_urls = [];
    // Search for relevant monitors via a metric filter
    for await (const monitor of monitorsApi.searchToEnd(`metric:trace*`)) {

        // Skip monitors that have a scoped environment set
        if (!monitor.query.includes('env:production')) continue;
        if (!monitor.query.includes('env:sandbox')) continue;

        // return the monitor URL for further manual inspection
        monitor_urls.push(`https://app.datadoghq.eu/monitors/${monitor.id}`);
        count++;
    }

    // Return number of matched monitors as a summary
    return { count: count, monitor_urls: monitor_urls };
}

Submitted by rossmccrann 136 days ago

Edited 136 days ago

No comments yet