The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/alerting/state/actions.ts

60 lines
1.6 KiB

import { Dispatch } from 'redux';
import { getBackendSrv } from 'app/core/services/backend_srv';
7 years ago
import { AlertRuleApi, StoreState } from 'app/types';
export enum ActionTypes {
LoadAlertRules = 'LOAD_ALERT_RULES',
SetSearchQuery = 'SET_SEARCH_QUERY',
}
export interface LoadAlertRulesAction {
type: ActionTypes.LoadAlertRules;
7 years ago
payload: AlertRuleApi[];
}
export interface SetSearchQueryAction {
type: ActionTypes.SetSearchQuery;
payload: string;
}
7 years ago
export const loadAlertRules = (rules: AlertRuleApi[]): LoadAlertRulesAction => ({
type: ActionTypes.LoadAlertRules,
payload: rules,
});
export const setSearchQuery = (query: string): SetSearchQueryAction => ({
type: ActionTypes.SetSearchQuery,
payload: query,
});
export type Action = LoadAlertRulesAction | SetSearchQueryAction;
7 years ago
export const getAlertRulesAsync = (options: { state: string }) => async (
dispatch: Dispatch<Action>
7 years ago
): Promise<AlertRuleApi[]> => {
try {
7 years ago
const rules = await getBackendSrv().get('/api/alerts', options);
dispatch(loadAlertRules(rules));
return rules;
} catch (error) {
console.error(error);
throw error;
}
};
export const togglePauseAlertRule = (id: number, options: { paused: boolean }) => async (
// Maybe fix dispatch type?
dispatch: Dispatch<any>,
getState: () => StoreState
): Promise<boolean> => {
try {
await getBackendSrv().post(`/api/alerts/${id}/pause`, options);
const stateFilter = getState().location.query.state || 'all';
dispatch(getAlertRulesAsync({ state: stateFilter.toString() }));
return true;
} catch (error) {
console.log(error);
throw error;
}
};