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