1 import { Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core';
3 import { PrometheusService } from '~/app/shared/api/prometheus.service';
4 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
5 import { Icons } from '~/app/shared/enum/icons.enum';
6 import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
7 import { CdTableAction } from '~/app/shared/models/cd-table-action';
8 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
9 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
10 import { Permission } from '~/app/shared/models/permissions';
11 import { AlertState } from '~/app/shared/models/prometheus-alerts';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
14 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
16 const BASE_URL = 'silences'; // as only silence actions can be used
19 selector: 'cd-active-alert-list',
20 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
21 templateUrl: './active-alert-list.component.html',
22 styleUrls: ['./active-alert-list.component.scss']
24 export class ActiveAlertListComponent extends PrometheusListHelper implements OnInit {
25 @ViewChild('externalLinkTpl', { static: true })
26 externalLinkTpl: TemplateRef<any>;
27 columns: CdTableColumn[];
28 innerColumns: CdTableColumn[];
29 tableActions: CdTableAction[];
30 permission: Permission;
31 selection = new CdTableSelection();
33 expandedInnerRow: any;
34 multilineTextKeys = ['description', 'impact', 'fix'];
36 filters: CdTableColumn[] = [
38 name: $localize`State`,
40 filterOptions: [$localize`All`, $localize`Active`, $localize`Suppressed`],
41 filterInitValue: $localize`Active`,
42 filterPredicate: (row, value) => {
43 if (value === 'Active') return row.status?.state === AlertState.ACTIVE;
44 else if (value === 'Suppressed') return row.status?.state === AlertState.SUPPRESSED;
45 if (value === 'All') return true;
52 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
53 private authStorageService: AuthStorageService,
54 public prometheusAlertService: PrometheusAlertService,
55 private urlBuilder: URLBuilderService,
56 @Inject(PrometheusService) prometheusService: PrometheusService
58 super(prometheusService);
59 this.permission = this.authStorageService.getPermissions().prometheus;
63 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
64 disable: (selection: CdTableSelection) =>
65 !selection.hasSingleSelection || selection.first().cdExecuting,
68 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
69 name: $localize`Create Silence`
78 name: $localize`Description`,
79 prop: 'annotations.description',
83 name: $localize`Severity`,
84 prop: 'labels.severity',
86 cellTransformation: CellTemplate.badge,
87 customTemplateConfig: {
89 critical: { class: 'badge-danger' },
90 warning: { class: 'badge-warning' }
95 name: $localize`State`,
98 cellTransformation: CellTemplate.badge,
99 customTemplateConfig: {
101 active: { class: 'badge-info' },
102 unprocessed: { class: 'badge-warning' },
103 suppressed: { class: 'badge-dark' }
108 name: $localize`Started`,
110 cellTransformation: CellTemplate.timeAgo,
116 name: $localize`Name`,
117 prop: 'labels.alertname',
118 cellClass: 'fw-bold',
122 name: $localize`Summary`,
123 prop: 'annotations.summary',
126 ...this.innerColumns.slice(1),
128 name: $localize`Occurrence`,
133 name: $localize`URL`,
134 prop: 'generatorURL',
137 cellTemplate: this.externalLinkTpl
140 this.prometheusAlertService.getGroupedAlerts(true);
143 setExpandedInnerRow(row: any) {
144 this.expandedInnerRow = row;
147 updateSelection(selection: CdTableSelection) {
148 this.selection = selection;