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