1//DOCS: https://prometheus.io/docs/alerting/latest/configuration/
2
3import { DataSourceJsonData } from '@grafana/data';
4
5export type AlertManagerCortexConfig = {
6  template_files: Record<string, string>;
7  alertmanager_config: AlertmanagerConfig;
8};
9
10export type TLSConfig = {
11  ca_file: string;
12  cert_file: string;
13  key_file: string;
14  server_name?: string;
15  insecure_skip_verify?: boolean;
16};
17
18export type HTTPConfigCommon = {
19  proxy_url?: string;
20  tls_config?: TLSConfig;
21};
22
23export type HTTPConfigBasicAuth = {
24  basic_auth: {
25    username: string;
26  } & ({ password: string } | { password_file: string });
27};
28
29export type HTTPConfigBearerToken = {
30  bearer_token: string;
31};
32
33export type HTTPConfigBearerTokenFile = {
34  bearer_token_file: string;
35};
36
37export type HTTPConfig = HTTPConfigCommon & (HTTPConfigBasicAuth | HTTPConfigBearerToken | HTTPConfigBearerTokenFile);
38
39export type EmailConfig = {
40  to: string;
41
42  send_resolved?: string;
43  from?: string;
44  smarthost?: string;
45  hello?: string;
46  auth_username?: string;
47  auth_password?: string;
48  auth_secret?: string;
49  auth_identity?: string;
50  require_tls?: boolean;
51  tls_config?: TLSConfig;
52  html?: string;
53  text?: string;
54  headers?: Record<string, string>;
55};
56
57export type WebhookConfig = {
58  url: string;
59
60  send_resolved?: boolean;
61  http_config?: HTTPConfig;
62  max_alerts?: number;
63};
64
65export type GrafanaManagedReceiverConfig = {
66  uid?: string;
67  disableResolveMessage: boolean;
68  secureFields?: Record<string, boolean>;
69  secureSettings?: Record<string, any>;
70  settings: Record<string, any>;
71  type: string;
72  name: string;
73  updated?: string;
74  created?: string;
75};
76
77export type Receiver = {
78  name: string;
79
80  email_configs?: EmailConfig[];
81  pagerduty_configs?: any[];
82  pushover_configs?: any[];
83  slack_configs?: any[];
84  opsgenie_configs?: any[];
85  webhook_configs?: WebhookConfig[];
86  victorops_configs?: any[];
87  wechat_configs?: any[];
88  grafana_managed_receiver_configs?: GrafanaManagedReceiverConfig[];
89  [key: string]: any;
90};
91
92type ObjectMatcher = [name: string, operator: MatcherOperator, value: string];
93
94export type Route = {
95  receiver?: string;
96  group_by?: string[];
97  continue?: boolean;
98  object_matchers?: ObjectMatcher[];
99  matchers?: string[];
100  /** @deprecated use `object_matchers` */
101  match?: Record<string, string>;
102  /** @deprecated use `object_matchers` */
103  match_re?: Record<string, string>;
104  group_wait?: string;
105  group_interval?: string;
106  repeat_interval?: string;
107  routes?: Route[];
108};
109
110export type InhibitRule = {
111  target_match: Record<string, string>;
112  target_match_re: Record<string, string>;
113  source_match: Record<string, string>;
114  source_match_re: Record<string, string>;
115  equal?: string[];
116};
117
118export type AlertmanagerConfig = {
119  global?: {
120    smtp_from?: string;
121    smtp_smarthost?: string;
122    smtp_hello?: string;
123    smtp_auth_username?: string;
124    smtp_auth_password?: string;
125    smtp_auth_identity?: string;
126    smtp_auth_secret?: string;
127    smtp_require_tls?: boolean;
128    slack_api_url?: string;
129    victorops_api_key?: string;
130    victorops_api_url?: string;
131    pagerduty_url?: string;
132    opsgenie_api_key?: string;
133    opsgenie_api_url?: string;
134    wechat_api_url?: string;
135    wechat_api_secret?: string;
136    wechat_api_corp_id?: string;
137    http_config?: HTTPConfig;
138    resolve_timeout?: string;
139  };
140  templates?: string[];
141  route?: Route;
142  inhibit_rules?: InhibitRule[];
143  receivers?: Receiver[];
144};
145
146export type Matcher = {
147  name: string;
148  value: string;
149  isRegex: boolean;
150  isEqual: boolean;
151};
152
153export enum SilenceState {
154  Active = 'active',
155  Expired = 'expired',
156  Pending = 'pending',
157}
158
159export enum AlertState {
160  Unprocessed = 'unprocessed',
161  Active = 'active',
162  Suppressed = 'suppressed',
163}
164
165export enum MatcherOperator {
166  equal = '=',
167  notEqual = '!=',
168  regex = '=~',
169  notRegex = '!~',
170}
171
172export type Silence = {
173  id: string;
174  matchers?: Matcher[];
175  startsAt: string;
176  endsAt: string;
177  updatedAt: string;
178  createdBy: string;
179  comment: string;
180  status: {
181    state: SilenceState;
182  };
183};
184
185export type SilenceCreatePayload = {
186  id?: string;
187  matchers?: Matcher[];
188  startsAt: string;
189  endsAt: string;
190  createdBy: string;
191  comment: string;
192};
193
194export type AlertmanagerAlert = {
195  startsAt: string;
196  updatedAt: string;
197  endsAt: string;
198  generatorURL?: string;
199  labels: { [key: string]: string };
200  annotations: { [key: string]: string };
201  receivers: [
202    {
203      name: string;
204    }
205  ];
206  fingerprint: string;
207  status: {
208    state: AlertState;
209    silencedBy: string[];
210    inhibitedBy: string[];
211  };
212};
213
214export type AlertmanagerGroup = {
215  labels: { [key: string]: string };
216  receiver: { name: string };
217  alerts: AlertmanagerAlert[];
218};
219
220export interface AlertmanagerStatus {
221  cluster: {
222    peers: unknown;
223    status: string;
224  };
225  config: AlertmanagerConfig;
226  uptime: string;
227  versionInfo: {
228    branch: string;
229    buildDate: string;
230    buildUser: string;
231    goVersion: string;
232    revision: string;
233    version: string;
234  };
235}
236
237export type TestReceiversAlert = Pick<AlertmanagerAlert, 'annotations' | 'labels'>;
238
239export interface TestReceiversPayload {
240  receivers?: Receiver[];
241  alert?: TestReceiversAlert;
242}
243
244interface TestReceiversResultGrafanaReceiverConfig {
245  name: string;
246  uid?: string;
247  error?: string;
248  status: 'ok' | 'failed';
249}
250
251interface TestReceiversResultReceiver {
252  name: string;
253  grafana_managed_receiver_configs: TestReceiversResultGrafanaReceiverConfig[];
254}
255export interface TestReceiversResult {
256  notified_at: string;
257  receivers: TestReceiversResultReceiver[];
258}
259
260export interface ExternalAlertmanagers {
261  activeAlertManagers: AlertmanagerUrl[];
262  droppedAlertManagers: AlertmanagerUrl[];
263}
264
265export interface AlertmanagerUrl {
266  url: string;
267}
268
269export interface ExternalAlertmanagersResponse {
270  data: ExternalAlertmanagers;
271  status: 'string';
272}
273export enum AlertManagerImplementation {
274  cortex = 'cortex',
275  prometheus = 'prometheus',
276}
277
278export type AlertManagerDataSourceJsonData = DataSourceJsonData & { implementation?: AlertManagerImplementation };
279