2019-12-09 14:42:59 -08:00
|
|
|
import React, { FC } from 'react';
|
|
|
|
import { RouteComponentProps } from '@reach/router';
|
2020-01-14 10:34:48 -08:00
|
|
|
import PathPrefixProps from '../../types/PathPrefixProps';
|
|
|
|
import { useFetch } from '../../hooks/useFetch';
|
|
|
|
import { withStatusIndicator } from '../../components/withStatusIndicator';
|
2019-12-09 14:42:59 -08:00
|
|
|
import AlertsContent, { RuleStatus, AlertsProps } from './AlertContents';
|
|
|
|
|
|
|
|
const AlertsWithStatusIndicator = withStatusIndicator(AlertsContent);
|
|
|
|
|
|
|
|
const Alerts: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix = '' }) => {
|
|
|
|
const { response, error, isLoading } = useFetch<AlertsProps>(`${pathPrefix}/api/v1/rules?type=alert`);
|
|
|
|
|
|
|
|
const ruleStatsCount: RuleStatus<number> = {
|
|
|
|
inactive: 0,
|
|
|
|
pending: 0,
|
|
|
|
firing: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (response.data && response.data.groups) {
|
|
|
|
response.data.groups.forEach(el => el.rules.forEach(r => ruleStatsCount[r.state]++));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AlertsWithStatusIndicator
|
|
|
|
statsCount={ruleStatsCount}
|
|
|
|
groups={response.data && response.data.groups}
|
|
|
|
error={error}
|
|
|
|
isLoading={isLoading}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Alerts;
|