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-prometheus-list',
18 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
19 templateUrl: './alert-list.component.html',
20 styleUrls: ['./alert-list.component.scss']
22 export class AlertListComponent implements OnInit {
23 @ViewChild('externalLinkTpl')
24 externalLinkTpl: TemplateRef<any>;
25 columns: CdTableColumn[];
26 tableActions: CdTableAction[];
27 permission: Permission;
28 selection = new CdTableSelection();
31 'label label-danger': 'active',
32 'label label-warning': 'unprocessed',
33 'label label-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,
52 routerLink: () => this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
53 name: this.i18n('Create silence')
61 name: this.i18n('Name'),
62 prop: 'labels.alertname',
66 name: this.i18n('Job'),
71 name: this.i18n('Severity'),
72 prop: 'labels.severity'
75 name: this.i18n('State'),
77 cellTransformation: CellTemplate.classAdding
80 name: this.i18n('Started'),
85 name: this.i18n('URL'),
88 cellTemplate: this.externalLinkTpl
93 updateSelection(selection: CdTableSelection) {
94 this.selection = selection;