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() {
|
2021-03-08 18:12:59 +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,
|
|
|
|
})
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((resp) => mapAlert(resp.data));
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
readAlert(alertPath) {
|
2021-03-08 18:12:59 +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 })
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((resp) => mapAlert(resp.data));
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
deleteAlert(alertPath) {
|
2021-03-08 18:12:59 +05:30
|
|
|
return axios.delete(alertPath).then((resp) => resp.data);
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
}
|