]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / prometheus.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import { Observable } from 'rxjs';
5
6 import { AlertmanagerSilence } from '../models/alertmanager-silence';
7 import {
8 AlertmanagerAlert,
9 AlertmanagerNotification,
10 PrometheusRule
11 } from '../models/prometheus-alerts';
12 import { ApiModule } from './api.module';
13 import { SettingsService } from './settings.service';
14
15 @Injectable({
16 providedIn: ApiModule
17 })
18 export class PrometheusService {
19 private baseURL = 'api/prometheus';
20 private settingsKey = {
21 alertmanager: 'api/settings/alertmanager-api-host',
22 prometheus: 'api/settings/prometheus-api-host'
23 };
24
25 constructor(private http: HttpClient, private settingsService: SettingsService) {}
26
27 ifAlertmanagerConfigured(fn, elseFn?): void {
28 this.settingsService.ifSettingConfigured(this.settingsKey.alertmanager, fn, elseFn);
29 }
30
31 disableAlertmanagerConfig(): void {
32 this.settingsService.disableSetting(this.settingsKey.alertmanager);
33 }
34
35 ifPrometheusConfigured(fn, elseFn?): void {
36 this.settingsService.ifSettingConfigured(this.settingsKey.prometheus, fn, elseFn);
37 }
38
39 disablePrometheusConfig(): void {
40 this.settingsService.disableSetting(this.settingsKey.prometheus);
41 }
42
43 getAlerts(params = {}): Observable<AlertmanagerAlert[]> {
44 return this.http.get<AlertmanagerAlert[]>(this.baseURL, { params });
45 }
46
47 getSilences(params = {}): Observable<AlertmanagerSilence[]> {
48 return this.http.get<AlertmanagerSilence[]>(`${this.baseURL}/silences`, { params });
49 }
50
51 getRules(params = {}): Observable<PrometheusRule[]> {
52 return this.http.get<PrometheusRule[]>(`${this.baseURL}/rules`, { params });
53 }
54
55 setSilence(silence: AlertmanagerSilence) {
56 return this.http.post(`${this.baseURL}/silence`, silence, { observe: 'response' });
57 }
58
59 expireSilence(silenceId: string) {
60 return this.http.delete(`${this.baseURL}/silence/${silenceId}`, { observe: 'response' });
61 }
62
63 getNotifications(
64 notification?: AlertmanagerNotification
65 ): Observable<AlertmanagerNotification[]> {
66 const url = `${this.baseURL}/notifications?from=${
67 notification && notification.id ? notification.id : 'last'
68 }`;
69 return this.http.get<AlertmanagerNotification[]>(url);
70 }
71 }