0

Create Logging Destination

by
Published Dec 20, 2024

To create a new destination, send a POST request to `/v2/monitoring/sinks/destinations`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Create Logging Destination
7
 * To create a new destination, send a POST request to `/v2/monitoring/sinks/destinations`.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  body: {
12
    name?: string;
13
    type: "opensearch_dbaas" | "opensearch_ext";
14
    config: {
15
      credentials?: { username?: string; password?: string };
16
      endpoint: string;
17
      cluster_uuid?: string;
18
      cluster_name?: string;
19
      index_name?: string;
20
      retention_days?: number;
21
    };
22
  },
23
) {
24
  const url = new URL(
25
    `https://api.digitalocean.com/v2/monitoring/sinks/destinations`,
26
  );
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42