1
Find Monitors
One script reply has been approved by the moderators Verified
Created by rossmccrann 590 days ago Viewed 374 times
0
Submitted by rossmccrann Deno
Verified 590 days ago
1
import ApiClient from "https://deno.land/x/datadog_api/client.ts";
2
import V1MonitorsApi from "https://deno.land/x/datadog_api/v1/monitors.ts";
3

4
type Datadog = {
5
  apiKey: string;
6
  appKey: string;
7
  apiBase: string;
8
};
9
export async function main(dd_auth: Datadog) {
10
  let count = 0;
11
  // Set up a Monitors API client
12
  const datadog = new ApiClient(dd_auth);
13
  const monitorsApi = new V1MonitorsApi(datadog);
14

15
  let monitor_urls = [];
16
  // Search for relevant monitors via a metric filter
17
  for await (const monitor of monitorsApi.searchToEnd(`metric:trace*`)) {
18
    // Skip monitors that have a scoped environment set
19
    if (!monitor.query.includes("env:production")) continue;
20
    if (!monitor.query.includes("env:sandbox")) continue;
21

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

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