]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
95071f88c50973a3480ccfaa0b0b4ce228b25cd8
[ceph-ci.git] /
1 import { Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { PrometheusService } from '~/app/shared/api/prometheus.service';
4 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
5 import { Icons } from '~/app/shared/enum/icons.enum';
6 import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
7 import { CdTableAction } from '~/app/shared/models/cd-table-action';
8 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
9 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
10 import { Permission } from '~/app/shared/models/permissions';
11 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
12 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
13 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
14
15 const BASE_URL = 'silences'; // 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 PrometheusListHelper 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   multilineTextKeys = ['description', 'impact', 'fix'];
32
33   constructor(
34     // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
35     private authStorageService: AuthStorageService,
36     public prometheusAlertService: PrometheusAlertService,
37     private urlBuilder: URLBuilderService,
38     @Inject(PrometheusService) prometheusService: PrometheusService
39   ) {
40     super(prometheusService);
41     this.permission = this.authStorageService.getPermissions().prometheus;
42     this.tableActions = [
43       {
44         permission: 'create',
45         canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
46         disable: (selection: CdTableSelection) =>
47           !selection.hasSingleSelection || selection.first().cdExecuting,
48         icon: Icons.add,
49         routerLink: () =>
50           '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
51         name: $localize`Create Silence`
52       }
53     ];
54   }
55
56   ngOnInit() {
57     super.ngOnInit();
58     this.columns = [
59       {
60         name: $localize`Name`,
61         prop: 'labels.alertname',
62         cellClass: 'fw-bold',
63         flexGrow: 2
64       },
65       {
66         name: $localize`Summary`,
67         prop: 'annotations.summary',
68         flexGrow: 3
69       },
70       {
71         name: $localize`Severity`,
72         prop: 'labels.severity',
73         flexGrow: 1,
74         cellTransformation: CellTemplate.badge,
75         customTemplateConfig: {
76           map: {
77             critical: { class: 'badge-danger' },
78             warning: { class: 'badge-warning' }
79           }
80         }
81       },
82       {
83         name: $localize`State`,
84         prop: 'status.state',
85         flexGrow: 1,
86         cellTransformation: CellTemplate.badge,
87         customTemplateConfig: {
88           map: {
89             active: { class: 'badge-info' },
90             unprocessed: { class: 'badge-warning' },
91             suppressed: { class: 'badge-dark' }
92           }
93         }
94       },
95       {
96         name: $localize`Started`,
97         prop: 'startsAt',
98         cellTransformation: CellTemplate.timeAgo,
99         flexGrow: 1
100       },
101       {
102         name: $localize`URL`,
103         prop: 'generatorURL',
104         flexGrow: 1,
105         sortable: false,
106         cellTemplate: this.externalLinkTpl
107       }
108     ];
109     this.prometheusAlertService.getAlerts(true);
110   }
111
112   updateSelection(selection: CdTableSelection) {
113     this.selection = selection;
114   }
115 }