0

Create alert rule

by
Published Oct 17, 2025

Create a new alert rule with PromQL expression

Script qovery Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create alert rule
4
 * Create a new alert rule with PromQL expression
5
 */
6
export async function main(auth: RT.Qovery, body: AlertRuleCreationRequest) {
7
	const url = new URL(`https://api.qovery.com/api/alert-rules`)
8

9
	const response = await fetch(url, {
10
		method: 'POST',
11
		headers: {
12
			'Content-Type': 'application/json',
13
			Authorization: 'Token ' + auth.apiKey
14
		},
15
		body: JSON.stringify(body)
16
	})
17
	if (!response.ok) {
18
		const text = await response.text()
19
		throw new Error(`${response.status} ${text}`)
20
	}
21
	return await response.json()
22
}
23

24
/* eslint-disable */
25
/**
26
 * This file was automatically generated by json-schema-to-typescript.
27
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
28
 * and run json-schema-to-typescript to regenerate this file.
29
 */
30

31
/**
32
 * Alert severity level:
33
 *         - WARNING: Non-critical issue requiring attention
34
 *         - CRITICAL: Critical issue requiring immediate action
35
 */
36
export type AlertSeverity = 'WARNING' | 'CRITICAL'
37

38
export interface AlertRuleCreationRequest {
39
	/**
40
	 * Organization identifier
41
	 */
42
	organization_id: string
43
	/**
44
	 *  Cluster identifier where the rule will be deployed
45
	 */
46
	cluster_id: string
47
	/**
48
	 * Name of the alert rule
49
	 */
50
	name: string
51
	/**
52
	 * Description of what the alert monitors
53
	 *
54
	 */
55
	description: string
56
	/**
57
	 * PromQL expression to evaluate
58
	 */
59
	promql_expr: string
60
	/**
61
	 * Duration the condition must be true before firing (ISO-8601 duration format)
62
	 */
63
	for_duration: string
64
	severity: AlertSeverity
65
	/**
66
	 * Whether the alert rule is enabled
67
	 */
68
	enabled: boolean
69
	/**
70
	 * List of alert receiver IDs to send notifications to
71
	 *
72
	 * @minItems 1
73
	 */
74
	alert_receiver_ids: string[]
75
	presentation: AlertPresentation
76
	[k: string]: unknown
77
}
78
export interface AlertPresentation {
79
	summary?: string
80
	/**
81
	 * URL to runbook with remediation steps
82
	 */
83
	runbook_url?: string
84
	[k: string]: unknown
85
}
86