import { Card, Group, Table, Text, Accordion, Badge, Tooltip, Box, Switch, } from "@mantine/core"; import { useSuspenseAPIQuery } from "../api/api"; import { AlertingRulesMap } from "../api/responseTypes/rules"; import badgeClasses from "../Badge.module.css"; import RuleDefinition from "../RuleDefinition"; import { formatRelative, now } from "../lib/formatTime"; import { Fragment, useState } from "react"; export default function AlertsPage() { const { data } = useSuspenseAPIQuery(`/rules`, { type: "alert", }); const [showAnnotations, setShowAnnotations] = useState(false); const ruleStatsCount = { inactive: 0, pending: 0, firing: 0, }; data.data.groups.forEach((el) => el.rules.forEach((r) => ruleStatsCount[r.state]++) ); return ( <> setShowAnnotations(event.currentTarget.checked)} mb="md" /> {data.data.groups.map((g, i) => ( {g.name} {g.file} {g.rules.map((r, j) => { const numFiring = r.alerts.filter( (a) => a.state === "firing" ).length; const numPending = r.alerts.filter( (a) => a.state === "pending" ).length; return ( 0 ? "5px solid var(--mantine-color-red-4)" : numPending > 0 ? "5px solid var(--mantine-color-orange-5)" : "5px solid var(--mantine-color-green-4)", }} > {r.name} {numFiring > 0 && ( firing ({numFiring}) )} {numPending > 0 && ( pending ({numPending}) )} {/* {numFiring === 0 && numPending === 0 && ( inactive )} */} {r.alerts.length > 0 && ( Alert labels State Active Since Value {r.type === "alerting" && r.alerts.map((a, k) => ( {Object.entries(a.labels).map( ([k, v]) => { return ( {/* TODO: Proper quote escaping */} {k}="{v}" ); } )} {a.state} {formatRelative(a.activeAt, now(), "")} {a.value} {showAnnotations && (
{Object.entries(a.annotations).map( ([k, v]) => ( {k} {v} ) )}
)} ))} )}
); })}
))} ); }