]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / prometheus.service.ts
index bdcd7fd35f526e109c9741d20ccdee872ac54b41..7b56161d4cfbaf5c561e6d13d54f8693c95f65e7 100644 (file)
@@ -2,12 +2,13 @@ import { HttpClient } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 
 import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
 
 import { AlertmanagerSilence } from '../models/alertmanager-silence';
 import {
   AlertmanagerAlert,
   AlertmanagerNotification,
-  PrometheusRule
+  PrometheusRuleGroup
 } from '../models/prometheus-alerts';
 import { ApiModule } from './api.module';
 import { SettingsService } from './settings.service';
@@ -24,7 +25,7 @@ export class PrometheusService {
 
   constructor(private http: HttpClient, private settingsService: SettingsService) {}
 
-  ifAlertmanagerConfigured(fn, elseFn?): void {
+  ifAlertmanagerConfigured(fn: (value?: string) => void, elseFn?: () => void): void {
     this.settingsService.ifSettingConfigured(this.settingsKey.alertmanager, fn, elseFn);
   }
 
@@ -32,7 +33,7 @@ export class PrometheusService {
     this.settingsService.disableSetting(this.settingsKey.alertmanager);
   }
 
-  ifPrometheusConfigured(fn, elseFn?): void {
+  ifPrometheusConfigured(fn: (value?: string) => void, elseFn?: () => void): void {
     this.settingsService.ifSettingConfigured(this.settingsKey.prometheus, fn, elseFn);
   }
 
@@ -48,12 +49,23 @@ export class PrometheusService {
     return this.http.get<AlertmanagerSilence[]>(`${this.baseURL}/silences`, { params });
   }
 
-  getRules(params = {}): Observable<PrometheusRule[]> {
-    return this.http.get<PrometheusRule[]>(`${this.baseURL}/rules`, { params });
+  getRules(
+    type: 'all' | 'alerting' | 'rewrites' = 'all'
+  ): Observable<{ groups: PrometheusRuleGroup[] }> {
+    return this.http.get<{ groups: PrometheusRuleGroup[] }>(`${this.baseURL}/rules`).pipe(
+      map((rules) => {
+        if (['alerting', 'rewrites'].includes(type)) {
+          rules.groups.map((group) => {
+            group.rules = group.rules.filter((rule) => rule.type === type);
+          });
+        }
+        return rules;
+      })
+    );
   }
 
   setSilence(silence: AlertmanagerSilence) {
-    return this.http.post(`${this.baseURL}/silence`, silence, { observe: 'response' });
+    return this.http.post<object>(`${this.baseURL}/silence`, silence, { observe: 'response' });
   }
 
   expireSilence(silenceId: string) {