]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
51a4b6fc8ce6d085211712f9d5ae45846cc35329
[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   innerColumns: CdTableColumn[];
28   tableActions: CdTableAction[];
29   permission: Permission;
30   selection = new CdTableSelection();
31   icons = Icons;
32   multilineTextKeys = ['description', 'impact', 'fix'];
33   expandedInnerRow: any;
34
35   constructor(
36     // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
37     private authStorageService: AuthStorageService,
38     public prometheusAlertService: PrometheusAlertService,
39     private urlBuilder: URLBuilderService,
40     @Inject(PrometheusService) prometheusService: PrometheusService
41   ) {
42     super(prometheusService);
43     this.permission = this.authStorageService.getPermissions().prometheus;
44     this.tableActions = [
45       {
46         permission: 'create',
47         canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
48         disable: (selection: CdTableSelection) =>
49           !selection.hasSingleSelection || selection.first().cdExecuting,
50         icon: Icons.add,
51         routerLink: () =>
52           '/monitoring' + this.urlBuilder.getCreateFrom(this.selection.first().fingerprint),
53         name: $localize`Create Silence`
54       }
55     ];
56   }
57
58   ngOnInit() {
59     super.ngOnInit();
60     this.innerColumns = [
61       {
62         name: $localize`Description`,
63         prop: 'annotations.description',
64         flexGrow: 3
65       },
66       {
67         name: $localize`Severity`,
68         prop: 'labels.severity',
69         flexGrow: 1,
70         cellTransformation: CellTemplate.badge,
71         customTemplateConfig: {
72           map: {
73             critical: { class: 'badge-danger' },
74             warning: { class: 'badge-warning' }
75           }
76         }
77       },
78       {
79         name: $localize`State`,
80         prop: 'status.state',
81         flexGrow: 1,
82         cellTransformation: CellTemplate.badge,
83         customTemplateConfig: {
84           map: {
85             active: { class: 'badge-info' },
86             unprocessed: { class: 'badge-warning' },
87             suppressed: { class: 'badge-dark' }
88           }
89         }
90       },
91       {
92         name: $localize`Started`,
93         prop: 'startsAt',
94         cellTransformation: CellTemplate.timeAgo,
95         flexGrow: 1
96       }
97     ];
98     this.columns = [
99       {
100         name: $localize`Name`,
101         prop: 'labels.alertname',
102         cellClass: 'fw-bold',
103         flexGrow: 2
104       },
105       {
106         name: $localize`Summary`,
107         prop: 'annotations.summary',
108         flexGrow: 3
109       },
110       ...this.innerColumns.slice(1),
111       {
112         name: $localize`Occurrence`,
113         prop: 'alert_count',
114         flexGrow: 1
115       },
116       {
117         name: $localize`URL`,
118         prop: 'generatorURL',
119         flexGrow: 1,
120         sortable: false,
121         cellTemplate: this.externalLinkTpl
122       }
123     ];
124     this.prometheusAlertService.getGroupedAlerts(true);
125   }
126
127   setExpandedInnerRow(row: any) {
128     this.expandedInnerRow = row;
129   }
130
131   updateSelection(selection: CdTableSelection) {
132     this.selection = selection;
133   }
134 }