1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
5 import { ListWithDetails } from '../../../../shared/classes/list-with-details.class';
6 import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
7 import { Icons } from '../../../../shared/enum/icons.enum';
8 import { CdTableAction } from '../../../../shared/models/cd-table-action';
9 import { CdTableColumn } from '../../../../shared/models/cd-table-column';
10 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
11 import { Permission } from '../../../../shared/models/permissions';
12 import { CdDatePipe } from '../../../../shared/pipes/cd-date.pipe';
13 import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
14 import { PrometheusAlertService } from '../../../../shared/services/prometheus-alert.service';
15 import { URLBuilderService } from '../../../../shared/services/url-builder.service';
17 const BASE_URL = 'silence'; // as only silence actions can be used
20 selector: 'cd-active-alert-list',
21 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
22 templateUrl: './active-alert-list.component.html',
23 styleUrls: ['./active-alert-list.component.scss']
25 export class ActiveAlertListComponent extends ListWithDetails implements OnInit {
26 @ViewChild('externalLinkTpl', { static: true })
27 externalLinkTpl: TemplateRef<any>;
28 columns: CdTableColumn[];
29 tableActions: CdTableAction[];
30 permission: Permission;
31 selection = new CdTableSelection();
34 'badge badge-danger': 'active',
35 'badge badge-warning': 'unprocessed',
36 'badge badge-info': 'suppressed'
40 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
41 private authStorageService: AuthStorageService,
42 public prometheusAlertService: PrometheusAlertService,
43 private urlBuilder: URLBuilderService,
45 private cdDatePipe: CdDatePipe
48 this.permission = this.authStorageService.getPermissions().prometheus;
52 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
53 disable: (selection: CdTableSelection) =>
54 !selection.hasSingleSelection || selection.first().cdExecuting,
57 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
58 name: this.i18n('Create Silence')
66 name: this.i18n('Name'),
67 prop: 'labels.alertname',
71 name: this.i18n('Job'),
76 name: this.i18n('Severity'),
77 prop: 'labels.severity'
80 name: this.i18n('State'),
82 cellTransformation: CellTemplate.classAdding
85 name: this.i18n('Started'),
90 name: this.i18n('URL'),
93 cellTemplate: this.externalLinkTpl
98 updateSelection(selection: CdTableSelection) {
99 this.selection = selection;