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 { CdTableAction } from '~/app/shared/models/cd-table-action';
7 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
9 import { Permission } from '~/app/shared/models/permissions';
10 import { CdDatePipe } from '~/app/shared/pipes/cd-date.pipe';
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';
14 import { PrometheusListHelper } from '../prometheus-list-helper';
16 const BASE_URL = 'silences'; // as only silence actions can be used
19 selector: 'cd-active-alert-list',
20 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
21 templateUrl: './active-alert-list.component.html',
22 styleUrls: ['./active-alert-list.component.scss']
24 export class ActiveAlertListComponent extends PrometheusListHelper implements OnInit {
25 @ViewChild('externalLinkTpl', { static: true })
26 externalLinkTpl: TemplateRef<any>;
27 columns: CdTableColumn[];
28 tableActions: CdTableAction[];
29 permission: Permission;
30 selection = new CdTableSelection();
33 'badge badge-danger': 'active',
34 'badge badge-warning': 'unprocessed',
35 'badge badge-info': 'suppressed'
39 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
40 private authStorageService: AuthStorageService,
41 public prometheusAlertService: PrometheusAlertService,
42 private urlBuilder: URLBuilderService,
43 private cdDatePipe: CdDatePipe,
44 @Inject(PrometheusService) prometheusService: PrometheusService
46 super(prometheusService);
47 this.permission = this.authStorageService.getPermissions().prometheus;
51 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
52 disable: (selection: CdTableSelection) =>
53 !selection.hasSingleSelection || selection.first().cdExecuting,
56 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
57 name: $localize`Create Silence`
66 name: $localize`Name`,
67 prop: 'labels.alertname',
76 name: $localize`Severity`,
77 prop: 'labels.severity'
80 name: $localize`State`,
82 cellTransformation: CellTemplate.classAdding
85 name: $localize`Started`,
93 cellTemplate: this.externalLinkTpl
98 updateSelection(selection: CdTableSelection) {
99 this.selection = selection;