0

Update Logging Destination

by
Published Dec 20, 2024

To update the details of a destination, send a PATCH request to `/v2/monitoring/sinks/destinations/${destination_uuid}`.

Script digitalocean Verified

The script

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

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