0

Create or update the Log Export configuration for a cluster

by
Published Oct 17, 2025

Can be used by the following roles assigned at the organization, folder or cluster scope: - ORG_ADMIN - CLUSTER_ADMIN - CLUSTER_OPERATOR_WRITER

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * Create or update the Log Export configuration for a cluster
7
 * Can be used by the following roles assigned at the organization, folder or cluster scope:
8
- ORG_ADMIN
9
- CLUSTER_ADMIN
10
- CLUSTER_OPERATOR_WRITER
11

12
 */
13
export async function main(
14
  auth: Cockroachdb,
15
  cluster_id: string,
16
  body: {
17
    auth_principal: string;
18
    aws_external_id?: string;
19
    azure_shared_key?: string;
20
    groups?: {
21
      channels: string[];
22
      log_name: string;
23
      min_level?: "UNSPECIFIED" | "WARNING" | "ERROR" | "FATAL";
24
      redact?: false | true;
25
    }[];
26
    log_name: string;
27
    omitted_channels?: string[];
28
    redact?: false | true;
29
    region?: string;
30
    type: "AWS_CLOUDWATCH" | "GCP_CLOUD_LOGGING" | "AZURE_LOG_ANALYTICS";
31
  },
32
) {
33
  const url = new URL(
34
    `https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}/logexport`,
35
  );
36

37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51