1 | |
2 | type Signoz = { |
3 | apiKey: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Update an existing alert rule |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Signoz, |
12 | id: string, |
13 | body: {} & { |
14 | alert: string; |
15 | alertType: |
16 | | "LOGS_BASED_ALERT" |
17 | | "METRIC_BASED_ALERT" |
18 | | "TRACES_BASED_ALERT" |
19 | | "EXCEPTIONS_BASED_ALERT"; |
20 | description?: string; |
21 | ruleType: "threshold_rule" | "promql_rule"; |
22 | evalWindow?: string; |
23 | frequency?: string; |
24 | condition: { |
25 | target: {}; |
26 | matchType: "0" | "1" | "2" | "3" | "4" | "5"; |
27 | op: "0" | "1" | "2" | "3" | "4"; |
28 | compositeQuery: { |
29 | builderQueries?: {}; |
30 | chQueries?: {}; |
31 | promQueries?: {}; |
32 | panelType: "graph" | "table" | "value" | "list" | "trace"; |
33 | queryType: "builder" | "clickhouse_sql" | "promql"; |
34 | unit?: string; |
35 | fillGaps?: false | true; |
36 | }; |
37 | targetUnit?: string; |
38 | selectedQueryName?: string; |
39 | alertOnAbsent?: false | true; |
40 | absentFor?: number; |
41 | requireMinPoints?: false | true; |
42 | requiredNumPoints?: number; |
43 | }; |
44 | labels?: { key?: string; value?: string }; |
45 | annotations?: { key?: string; value?: string }; |
46 | disabled?: false | true; |
47 | source?: string; |
48 | preferredChannels?: string[]; |
49 | version?: string; |
50 | }, |
51 | ) { |
52 | const url = new URL(`https://${auth.baseUrl}/api/v1/rules/${id}`); |
53 |
|
54 | const response = await fetch(url, { |
55 | method: "PUT", |
56 | headers: { |
57 | "Content-Type": "application/json", |
58 | "SIGNOZ-API-KEY": auth.apiKey, |
59 | }, |
60 | body: JSON.stringify(body), |
61 | }); |
62 | if (!response.ok) { |
63 | const text = await response.text(); |
64 | throw new Error(`${response.status} ${text}`); |
65 | } |
66 | return await response.text(); |
67 | } |
68 |
|