debian-mirror-gitlab/app/assets/javascripts/monitoring/services/alerts_service.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import axios from '~/lib/utils/axios_utils';
2020-10-24 23:57:45 +05:30
const mapAlert = ({ runbook_url, ...alert }) => {
return { runbookUrl: runbook_url, ...alert };
};
2020-05-24 23:13:21 +05:30
export default class AlertsService {
constructor({ alertsEndpoint }) {
this.alertsEndpoint = alertsEndpoint;
}
getAlerts() {
2020-10-24 23:57:45 +05:30
return axios.get(this.alertsEndpoint).then(resp => mapAlert(resp.data));
2020-05-24 23:13:21 +05:30
}
2020-10-24 23:57:45 +05:30
createAlert({ prometheus_metric_id, operator, threshold, runbookUrl }) {
2020-05-24 23:13:21 +05:30
return axios
2020-10-24 23:57:45 +05:30
.post(this.alertsEndpoint, {
prometheus_metric_id,
operator,
threshold,
runbook_url: runbookUrl,
})
.then(resp => mapAlert(resp.data));
2020-05-24 23:13:21 +05:30
}
// eslint-disable-next-line class-methods-use-this
readAlert(alertPath) {
2020-10-24 23:57:45 +05:30
return axios.get(alertPath).then(resp => mapAlert(resp.data));
2020-05-24 23:13:21 +05:30
}
// eslint-disable-next-line class-methods-use-this
2020-10-24 23:57:45 +05:30
updateAlert(alertPath, { operator, threshold, runbookUrl }) {
return axios
.put(alertPath, { operator, threshold, runbook_url: runbookUrl })
.then(resp => mapAlert(resp.data));
2020-05-24 23:13:21 +05:30
}
// eslint-disable-next-line class-methods-use-this
deleteAlert(alertPath) {
return axios.delete(alertPath).then(resp => resp.data);
}
}