All files / app/assets/javascripts/monitoring/services alerts_service.js

0% Statements 0/13
100% Branches 0/0
0% Functions 0/12
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                                                       
import axios from '~/lib/utils/axios_utils';
 
const mapAlert = ({ runbook_url, ...alert }) => {
  return { runbookUrl: runbook_url, ...alert };
};
 
export default class AlertsService {
  constructor({ alertsEndpoint }) {
    this.alertsEndpoint = alertsEndpoint;
  }
 
  getAlerts() {
    return axios.get(this.alertsEndpoint).then((resp) => mapAlert(resp.data));
  }
 
  createAlert({ prometheus_metric_id, operator, threshold, runbookUrl }) {
    return axios
      .post(this.alertsEndpoint, {
        prometheus_metric_id,
        operator,
        threshold,
        runbook_url: runbookUrl,
      })
      .then((resp) => mapAlert(resp.data));
  }
 
  // eslint-disable-next-line class-methods-use-this
  readAlert(alertPath) {
    return axios.get(alertPath).then((resp) => mapAlert(resp.data));
  }
 
  // eslint-disable-next-line class-methods-use-this
  updateAlert(alertPath, { operator, threshold, runbookUrl }) {
    return axios
      .put(alertPath, { operator, threshold, runbook_url: runbookUrl })
      .then((resp) => mapAlert(resp.data));
  }
 
  // eslint-disable-next-line class-methods-use-this
  deleteAlert(alertPath) {
    return axios.delete(alertPath).then((resp) => resp.data);
  }
}