]> 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
2f09b1dcb945374afe43af0712466318697a3112
[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 { 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';
13
14 const BASE_URL = 'silence'; // as only silence actions can be used
15
16 @Component({
17 selector: 'cd-active-alert-list',
18 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
19 templateUrl: './active-alert-list.component.html',
20 styleUrls: ['./active-alert-list.component.scss']
21 })
22 export class ActiveAlertListComponent implements OnInit {
23 @ViewChild('externalLinkTpl', { static: true })
24 externalLinkTpl: TemplateRef<any>;
25 columns: CdTableColumn[];
26 tableActions: CdTableAction[];
27 permission: Permission;
28 selection = new CdTableSelection();
29 icons = Icons;
30 customCss = {
31 'badge badge-danger': 'active',
32 'badge badge-warning': 'unprocessed',
33 'badge badge-info': 'suppressed'
34 };
35
36 constructor(
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,
41 private i18n: I18n,
42 private cdDatePipe: CdDatePipe
43 ) {
44 this.permission = this.authStorageService.getPermissions().prometheus;
45 this.tableActions = [
46 {
47 permission: 'create',
48 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
49 disable: (selection: CdTableSelection) =>
50 !selection.hasSingleSelection || selection.first().cdExecuting,
51 icon: Icons.add,
52 routerLink: () =>
53 '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
54 name: this.i18n('Create Silence')
55 }
56 ];
57 }
58
59 ngOnInit() {
60 this.columns = [
61 {
62 name: this.i18n('Name'),
63 prop: 'labels.alertname',
64 flexGrow: 2
65 },
66 {
67 name: this.i18n('Job'),
68 prop: 'labels.job',
69 flexGrow: 2
70 },
71 {
72 name: this.i18n('Severity'),
73 prop: 'labels.severity'
74 },
75 {
76 name: this.i18n('State'),
77 prop: 'status.state',
78 cellTransformation: CellTemplate.classAdding
79 },
80 {
81 name: this.i18n('Started'),
82 prop: 'startsAt',
83 pipe: this.cdDatePipe
84 },
85 {
86 name: this.i18n('URL'),
87 prop: 'generatorURL',
88 sortable: false,
89 cellTemplate: this.externalLinkTpl
90 }
91 ];
92 }
93
94 updateSelection(selection: CdTableSelection) {
95 this.selection = selection;
96 }
97 }