1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { I18n } from '@ngx-translate/i18n-polyfill';
3 import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
4 import { Icons } from '../../../../shared/enum/icons.enum';
5 import { CdTableAction } from '../../../../shared/models/cd-table-action';
6 import { CdTableColumn } from '../../../../shared/models/cd-table-column';
7 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
8 import { Permission } from '../../../../shared/models/permissions';
9 import { CdDatePipe } from '../../../../shared/pipes/cd-date.pipe';
10 import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
11 import { PrometheusAlertService } from '../../../../shared/services/prometheus-alert.service';
12 import { URLBuilderService } from '../../../../shared/services/url-builder.service';
14 const BASE_URL = 'silence'; // as only silence actions can be used
17 selector: 'cd-active-alert-list',
18 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
19 templateUrl: './active-alert-list.component.html',
20 styleUrls: ['./active-alert-list.component.scss']
22 export class ActiveAlertListComponent implements OnInit {
23 @ViewChild('externalLinkTpl', { static: true })
24 externalLinkTpl: TemplateRef<any>;
25 columns: CdTableColumn[];
26 tableActions: CdTableAction[];
27 permission: Permission;
28 selection = new CdTableSelection();
31 'badge badge-danger': 'active',
32 'badge badge-warning': 'unprocessed',
33 'badge badge-info': 'suppressed'
37 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
38 private authStorageService: AuthStorageService,
39 public prometheusAlertService: PrometheusAlertService,
40 private urlBuilder: URLBuilderService,
42 private cdDatePipe: CdDatePipe
44 this.permission = this.authStorageService.getPermissions().prometheus;
48 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
49 disable: (selection: CdTableSelection) =>
50 !selection.hasSingleSelection || selection.first().cdExecuting,
53 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
54 name: this.i18n('Create Silence')
62 name: this.i18n('Name'),
63 prop: 'labels.alertname',
67 name: this.i18n('Job'),
72 name: this.i18n('Severity'),
73 prop: 'labels.severity'
76 name: this.i18n('State'),
78 cellTransformation: CellTemplate.classAdding
81 name: this.i18n('Started'),
86 name: this.i18n('URL'),
89 cellTemplate: this.externalLinkTpl
94 updateSelection(selection: CdTableSelection) {
95 this.selection = selection;