]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / prometheus / active-alert-list / active-alert-list.component.ts
1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { I18n } from '@ngx-translate/i18n-polyfill';
3 import { ListWithDetails } from '../../../../shared/classes/list-with-details.class';
4 import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
5 import { Icons } from '../../../../shared/enum/icons.enum';
6 import { CdTableAction } from '../../../../shared/models/cd-table-action';
7 import { CdTableColumn } from '../../../../shared/models/cd-table-column';
8 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
9 import { Permission } from '../../../../shared/models/permissions';
10 import { CdDatePipe } from '../../../../shared/pipes/cd-date.pipe';
11 import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
12 import { PrometheusAlertService } from '../../../../shared/services/prometheus-alert.service';
13 import { URLBuilderService } from '../../../../shared/services/url-builder.service';
14
15 const BASE_URL = 'silence'; // as only silence actions can be used
16
17 @Component({
18 selector: 'cd-active-alert-list',
19 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
20 templateUrl: './active-alert-list.component.html',
21 styleUrls: ['./active-alert-list.component.scss']
22 })
23 export class ActiveAlertListComponent extends ListWithDetails implements OnInit {
24 @ViewChild('externalLinkTpl', { static: true })
25 externalLinkTpl: TemplateRef<any>;
26 columns: CdTableColumn[];
27 tableActions: CdTableAction[];
28 permission: Permission;
29 selection = new CdTableSelection();
30 icons = Icons;
31 customCss = {
32 'badge badge-danger': 'active',
33 'badge badge-warning': 'unprocessed',
34 'badge badge-info': 'suppressed'
35 };
36
37 constructor(
38 // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
39 private authStorageService: AuthStorageService,
40 public prometheusAlertService: PrometheusAlertService,
41 private urlBuilder: URLBuilderService,
42 private i18n: I18n,
43 private cdDatePipe: CdDatePipe
44 ) {
45 super();
46 this.permission = this.authStorageService.getPermissions().prometheus;
47 this.tableActions = [
48 {
49 permission: 'create',
50 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
51 disable: (selection: CdTableSelection) =>
52 !selection.hasSingleSelection || selection.first().cdExecuting,
53 icon: Icons.add,
54 routerLink: () =>
55 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
56 name: this.i18n('Create Silence')
57 }
58 ];
59 }
60
61 ngOnInit() {
62 this.columns = [
63 {
64 name: this.i18n('Name'),
65 prop: 'labels.alertname',
66 flexGrow: 2
67 },
68 {
69 name: this.i18n('Job'),
70 prop: 'labels.job',
71 flexGrow: 2
72 },
73 {
74 name: this.i18n('Severity'),
75 prop: 'labels.severity'
76 },
77 {
78 name: this.i18n('State'),
79 prop: 'status.state',
80 cellTransformation: CellTemplate.classAdding
81 },
82 {
83 name: this.i18n('Started'),
84 prop: 'startsAt',
85 pipe: this.cdDatePipe
86 },
87 {
88 name: this.i18n('URL'),
89 prop: 'generatorURL',
90 sortable: false,
91 cellTemplate: this.externalLinkTpl
92 }
93 ];
94 }
95
96 updateSelection(selection: CdTableSelection) {
97 this.selection = selection;
98 }
99 }