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 { CdTableAction } from '~/app/shared/models/cd-table-action';
7 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
9 import { Permission } from '~/app/shared/models/permissions';
10 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
11 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
12 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
13 import { PrometheusListHelper } from '../prometheus-list-helper';
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();
33 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
34 private authStorageService: AuthStorageService,
35 public prometheusAlertService: PrometheusAlertService,
36 private urlBuilder: URLBuilderService,
37 @Inject(PrometheusService) prometheusService: PrometheusService
39 super(prometheusService);
40 this.permission = this.authStorageService.getPermissions().prometheus;
44 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
45 disable: (selection: CdTableSelection) =>
46 !selection.hasSingleSelection || selection.first().cdExecuting,
49 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
50 name: $localize`Create Silence`
59 name: $localize`Name`,
60 prop: 'labels.alertname',
61 cellClass: 'font-weight-bold',
65 name: $localize`Summary`,
66 prop: 'annotations.summary',
70 name: $localize`Severity`,
71 prop: 'labels.severity',
73 cellTransformation: CellTemplate.badge,
74 customTemplateConfig: {
76 critical: { class: 'badge-danger' },
77 warning: { class: 'badge-warning' }
82 name: $localize`State`,
85 cellTransformation: CellTemplate.badge,
86 customTemplateConfig: {
88 active: { class: 'badge-info' },
89 unprocessed: { class: 'badge-warning' },
90 suppressed: { class: 'badge-dark' }
95 name: $localize`Started`,
97 cellTransformation: CellTemplate.timeAgo,
101 name: $localize`URL`,
102 prop: 'generatorURL',
105 cellTemplate: this.externalLinkTpl
110 updateSelection(selection: CdTableSelection) {
111 this.selection = selection;