1 import { Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
5 import { PrometheusService } from '../../../../shared/api/prometheus.service';
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 { CephReleaseNamePipe } from '../../../../shared/pipes/ceph-release-name.pipe';
14 import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
15 import { PrometheusAlertService } from '../../../../shared/services/prometheus-alert.service';
16 import { SummaryService } from '../../../../shared/services/summary.service';
17 import { URLBuilderService } from '../../../../shared/services/url-builder.service';
18 import { PrometheusListHelper } from '../prometheus-list-helper';
20 const BASE_URL = 'silences'; // as only silence actions can be used
23 selector: 'cd-active-alert-list',
24 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
25 templateUrl: './active-alert-list.component.html',
26 styleUrls: ['./active-alert-list.component.scss']
28 export class ActiveAlertListComponent extends PrometheusListHelper implements OnInit {
29 @ViewChild('externalLinkTpl', { static: true })
30 externalLinkTpl: TemplateRef<any>;
31 columns: CdTableColumn[];
32 tableActions: CdTableAction[];
33 permission: Permission;
34 selection = new CdTableSelection();
37 'badge badge-danger': 'active',
38 'badge badge-warning': 'unprocessed',
39 'badge badge-info': 'suppressed'
43 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
44 private authStorageService: AuthStorageService,
45 public prometheusAlertService: PrometheusAlertService,
46 private urlBuilder: URLBuilderService,
48 private cdDatePipe: CdDatePipe,
49 @Inject(PrometheusService) prometheusService: PrometheusService,
50 @Inject(SummaryService) summaryService: SummaryService,
51 @Inject(CephReleaseNamePipe) cephReleaseNamePipe: CephReleaseNamePipe
53 super(prometheusService, summaryService, cephReleaseNamePipe);
54 this.permission = this.authStorageService.getPermissions().prometheus;
58 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
59 disable: (selection: CdTableSelection) =>
60 !selection.hasSingleSelection || selection.first().cdExecuting,
63 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
64 name: this.i18n('Create Silence')
73 name: this.i18n('Name'),
74 prop: 'labels.alertname',
78 name: this.i18n('Job'),
83 name: this.i18n('Severity'),
84 prop: 'labels.severity'
87 name: this.i18n('State'),
89 cellTransformation: CellTemplate.classAdding
92 name: this.i18n('Started'),
97 name: this.i18n('URL'),
100 cellTemplate: this.externalLinkTpl
105 updateSelection(selection: CdTableSelection) {
106 this.selection = selection;