]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
bcd1f006aa0b61358c7a0914ce07e79cafe0241d
[ceph-ci.git] /
1 import { Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4
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';
19
20 const BASE_URL = 'silences'; // as only silence actions can be used
21
22 @Component({
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']
27 })
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();
35   icons = Icons;
36   customCss = {
37     'badge badge-danger': 'active',
38     'badge badge-warning': 'unprocessed',
39     'badge badge-info': 'suppressed'
40   };
41
42   constructor(
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,
47     private i18n: I18n,
48     private cdDatePipe: CdDatePipe,
49     @Inject(PrometheusService) prometheusService: PrometheusService,
50     @Inject(SummaryService) summaryService: SummaryService,
51     @Inject(CephReleaseNamePipe) cephReleaseNamePipe: CephReleaseNamePipe
52   ) {
53     super(prometheusService, summaryService, cephReleaseNamePipe);
54     this.permission = this.authStorageService.getPermissions().prometheus;
55     this.tableActions = [
56       {
57         permission: 'create',
58         canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
59         disable: (selection: CdTableSelection) =>
60           !selection.hasSingleSelection || selection.first().cdExecuting,
61         icon: Icons.add,
62         routerLink: () =>
63           '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
64         name: this.i18n('Create Silence')
65       }
66     ];
67   }
68
69   ngOnInit() {
70     super.ngOnInit();
71     this.columns = [
72       {
73         name: this.i18n('Name'),
74         prop: 'labels.alertname',
75         flexGrow: 2
76       },
77       {
78         name: this.i18n('Job'),
79         prop: 'labels.job',
80         flexGrow: 2
81       },
82       {
83         name: this.i18n('Severity'),
84         prop: 'labels.severity'
85       },
86       {
87         name: this.i18n('State'),
88         prop: 'status.state',
89         cellTransformation: CellTemplate.classAdding
90       },
91       {
92         name: this.i18n('Started'),
93         prop: 'startsAt',
94         pipe: this.cdDatePipe
95       },
96       {
97         name: this.i18n('URL'),
98         prop: 'generatorURL',
99         sortable: false,
100         cellTemplate: this.externalLinkTpl
101       }
102     ];
103   }
104
105   updateSelection(selection: CdTableSelection) {
106     this.selection = selection;
107   }
108 }