]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
215e8ece48c6fffbfc53cf1c8a91dcd8c0598dea
[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 { AlertState } from '~/app/shared/models/prometheus-alerts';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
14 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
15
16 const BASE_URL = 'silences'; // as only silence actions can be used
17
18 @Component({
19   selector: 'cd-active-alert-list',
20   providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }],
21   templateUrl: './active-alert-list.component.html',
22   styleUrls: ['./active-alert-list.component.scss']
23 })
24 export class ActiveAlertListComponent extends PrometheusListHelper implements OnInit {
25   @ViewChild('externalLinkTpl', { static: true })
26   externalLinkTpl: TemplateRef<any>;
27   columns: CdTableColumn[];
28   innerColumns: CdTableColumn[];
29   tableActions: CdTableAction[];
30   permission: Permission;
31   selection = new CdTableSelection();
32   icons = Icons;
33   expandedInnerRow: any;
34   multilineTextKeys = ['description', 'impact', 'fix'];
35
36   filters: CdTableColumn[] = [
37     {
38       name: $localize`State`,
39       prop: 'status.state',
40       filterOptions: [$localize`All`, $localize`Active`, $localize`Suppressed`],
41       filterInitValue: $localize`Active`,
42       filterPredicate: (row, value) => {
43         if (value === 'Active') return row.status?.state === AlertState.ACTIVE;
44         else if (value === 'Suppressed') return row.status?.state === AlertState.SUPPRESSED;
45         if (value === 'All') return true;
46         return false;
47       }
48     }
49   ];
50
51   constructor(
52     // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
53     private authStorageService: AuthStorageService,
54     public prometheusAlertService: PrometheusAlertService,
55     private urlBuilder: URLBuilderService,
56     @Inject(PrometheusService) prometheusService: PrometheusService
57   ) {
58     super(prometheusService);
59     this.permission = this.authStorageService.getPermissions().prometheus;
60     this.tableActions = [
61       {
62         permission: 'create',
63         canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
64         disable: (selection: CdTableSelection) =>
65           !selection.hasSingleSelection || selection.first().cdExecuting,
66         icon: Icons.add,
67         routerLink: () =>
68           '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
69         name: $localize`Create Silence`
70       }
71     ];
72   }
73
74   ngOnInit() {
75     super.ngOnInit();
76     this.innerColumns = [
77       {
78         name: $localize`Description`,
79         prop: 'annotations.description',
80         flexGrow: 3
81       },
82       {
83         name: $localize`Severity`,
84         prop: 'labels.severity',
85         flexGrow: 1,
86         cellTransformation: CellTemplate.badge,
87         customTemplateConfig: {
88           map: {
89             critical: { class: 'badge-danger' },
90             warning: { class: 'badge-warning' }
91           }
92         }
93       },
94       {
95         name: $localize`State`,
96         prop: 'status.state',
97         flexGrow: 1,
98         cellTransformation: CellTemplate.badge,
99         customTemplateConfig: {
100           map: {
101             active: { class: 'badge-info' },
102             unprocessed: { class: 'badge-warning' },
103             suppressed: { class: 'badge-dark' }
104           }
105         }
106       },
107       {
108         name: $localize`Started`,
109         prop: 'startsAt',
110         cellTransformation: CellTemplate.timeAgo,
111         flexGrow: 1
112       }
113     ];
114     this.columns = [
115       {
116         name: $localize`Name`,
117         prop: 'labels.alertname',
118         cellClass: 'fw-bold',
119         flexGrow: 2
120       },
121       {
122         name: $localize`Summary`,
123         prop: 'annotations.summary',
124         flexGrow: 3
125       },
126       ...this.innerColumns.slice(1),
127       {
128         name: $localize`Occurrence`,
129         prop: 'alert_count',
130         flexGrow: 1
131       },
132       {
133         name: $localize`URL`,
134         prop: 'generatorURL',
135         flexGrow: 1,
136         sortable: false,
137         cellTemplate: this.externalLinkTpl
138       }
139     ];
140     this.prometheusAlertService.getGroupedAlerts(true);
141   }
142
143   setExpandedInnerRow(row: any) {
144     this.expandedInnerRow = row;
145   }
146
147   updateSelection(selection: CdTableSelection) {
148     this.selection = selection;
149   }
150 }