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 innerColumns: CdTableColumn[];
28 tableActions: CdTableAction[];
29 permission: Permission;
30 selection = new CdTableSelection();
32 multilineTextKeys = ['description', 'impact', 'fix'];
33 expandedInnerRow: any;
36 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
37 private authStorageService: AuthStorageService,
38 public prometheusAlertService: PrometheusAlertService,
39 private urlBuilder: URLBuilderService,
40 @Inject(PrometheusService) prometheusService: PrometheusService
42 super(prometheusService);
43 this.permission = this.authStorageService.getPermissions().prometheus;
47 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
48 disable: (selection: CdTableSelection) =>
49 !selection.hasSingleSelection || selection.first().cdExecuting,
52 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
53 name: $localize`Create Silence`
62 name: $localize`Description`,
63 prop: 'annotations.description',
67 name: $localize`Severity`,
68 prop: 'labels.severity',
70 cellTransformation: CellTemplate.badge,
71 customTemplateConfig: {
73 critical: { class: 'badge-danger' },
74 warning: { class: 'badge-warning' }
79 name: $localize`State`,
82 cellTransformation: CellTemplate.badge,
83 customTemplateConfig: {
85 active: { class: 'badge-info' },
86 unprocessed: { class: 'badge-warning' },
87 suppressed: { class: 'badge-dark' }
92 name: $localize`Started`,
94 cellTransformation: CellTemplate.timeAgo,
100 name: $localize`Name`,
101 prop: 'labels.alertname',
102 cellClass: 'fw-bold',
106 name: $localize`Summary`,
107 prop: 'annotations.summary',
110 ...this.innerColumns.slice(1),
112 name: $localize`Occurrence`,
117 name: $localize`URL`,
118 prop: 'generatorURL',
121 cellTemplate: this.externalLinkTpl
124 this.prometheusAlertService.getGroupedAlerts(true);
127 setExpandedInnerRow(row: any) {
128 this.expandedInnerRow = row;
131 updateSelection(selection: CdTableSelection) {
132 this.selection = selection;