//native
type Signoz = {
apiKey: string;
baseUrl: string;
};
/**
* Update an existing alert rule
*
*/
export async function main(
auth: Signoz,
id: string,
body: {} & {
alert: string;
alertType:
| "LOGS_BASED_ALERT"
| "METRIC_BASED_ALERT"
| "TRACES_BASED_ALERT"
| "EXCEPTIONS_BASED_ALERT";
description?: string;
ruleType: "threshold_rule" | "promql_rule";
evalWindow?: string;
frequency?: string;
condition: {
target: {};
matchType: "0" | "1" | "2" | "3" | "4" | "5";
op: "0" | "1" | "2" | "3" | "4";
compositeQuery: {
builderQueries?: {};
chQueries?: {};
promQueries?: {};
panelType: "graph" | "table" | "value" | "list" | "trace";
queryType: "builder" | "clickhouse_sql" | "promql";
unit?: string;
fillGaps?: false | true;
};
targetUnit?: string;
selectedQueryName?: string;
alertOnAbsent?: false | true;
absentFor?: number;
requireMinPoints?: false | true;
requiredNumPoints?: number;
};
labels?: { key?: string; value?: string };
annotations?: { key?: string; value?: string };
disabled?: false | true;
source?: string;
preferredChannels?: string[];
version?: string;
},
) {
const url = new URL(`https://${auth.baseUrl}/api/v1/rules/${id}`);
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"SIGNOZ-API-KEY": auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago