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 { AuthStorageService } from '~/app/shared/services/auth-storage.service';
12 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
13 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
15 const BASE_URL = 'silences'; // as only silence actions can be used
18 selector: 'cd-active-alert-list',
19 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
20 templateUrl: './active-alert-list.component.html',
21 styleUrls: ['./active-alert-list.component.scss']
23 export class ActiveAlertListComponent extends PrometheusListHelper implements OnInit {
24 @ViewChild('externalLinkTpl', { static: true })
25 externalLinkTpl: TemplateRef<any>;
26 columns: CdTableColumn[];
27 tableActions: CdTableAction[];
28 permission: Permission;
29 selection = new CdTableSelection();
31 multilineTextKeys = ['description', 'impact', 'fix'];
34 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
35 private authStorageService: AuthStorageService,
36 public prometheusAlertService: PrometheusAlertService,
37 private urlBuilder: URLBuilderService,
38 @Inject(PrometheusService) prometheusService: PrometheusService
40 super(prometheusService);
41 this.permission = this.authStorageService.getPermissions().prometheus;
45 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
46 disable: (selection: CdTableSelection) =>
47 !selection.hasSingleSelection || selection.first().cdExecuting,
50 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
51 name: $localize`Create Silence`
60 name: $localize`Name`,
61 prop: 'labels.alertname',
66 name: $localize`Summary`,
67 prop: 'annotations.summary',
71 name: $localize`Severity`,
72 prop: 'labels.severity',
74 cellTransformation: CellTemplate.badge,
75 customTemplateConfig: {
77 critical: { class: 'badge-danger' },
78 warning: { class: 'badge-warning' }
83 name: $localize`State`,
86 cellTransformation: CellTemplate.badge,
87 customTemplateConfig: {
89 active: { class: 'badge-info' },
90 unprocessed: { class: 'badge-warning' },
91 suppressed: { class: 'badge-dark' }
96 name: $localize`Started`,
98 cellTransformation: CellTemplate.timeAgo,
102 name: $localize`URL`,
103 prop: 'generatorURL',
106 cellTemplate: this.externalLinkTpl
109 this.prometheusAlertService.getAlerts(true);
112 updateSelection(selection: CdTableSelection) {
113 this.selection = selection;