diff --git a/src/components/alerts/alert-modal.tsx b/src/components/alerts/alert-modal.tsx index d27eac9..4982ba6 100644 --- a/src/components/alerts/alert-modal.tsx +++ b/src/components/alerts/alert-modal.tsx @@ -19,6 +19,7 @@ import { import { Alert } from "@/types/alertmanager" import { Check, ClipboardCopy, Square, SquareArrowOutUpRight } from "lucide-react" import { cn } from "@/lib/utils" +import { AlertSeverity } from "./alert-severity" function isURL(string: string): boolean { try { @@ -45,7 +46,10 @@ export function AlertModal(props: Props) {
- {alert?.labels.alertname} + + {alert && } + {alert?.labels.alertname} + {summary} diff --git a/src/components/alerts/alert-row.tsx b/src/components/alerts/alert-row.tsx index 2d160e9..3dab3c1 100644 --- a/src/components/alerts/alert-row.tsx +++ b/src/components/alerts/alert-row.tsx @@ -1,7 +1,7 @@ import { Alert } from "@/types/alertmanager" import { formatDate } from "@/lib/date" import { stringToColor } from "./utils" -import { cn } from "@/lib/utils" +import { AlertSeverity } from "./alert-severity" const importantLabels = [ 'host', @@ -25,7 +25,7 @@ export function AlertRow(props: Props) { const { alert } = props return ( -
+
@@ -36,42 +36,6 @@ export function AlertRow(props: Props) { ) } -function AlertSeverity({ alert }: { alert: Alert }) { - const { severity } = alert.labels - - let color = 'bg-black' - let text = '???' - - switch (severity) { - case 'critical': - color = 'bg-red-600' - text = 'CRIT' - break - case 'error': - color = 'bg-red-500' - text = 'ERR' - break - case 'warning': - color = 'bg-orange-300' - text = 'WARN' - break - case 'info': - color = 'bg-blue-400' - text = 'INFO' - break - case 'none': - color = 'bg-slate-500' - text = 'NONE' - break - } - - return ( -
- {text} -
- ) -} - function AlertTitle({ alert }: { alert: Alert }) { const { alertname } = alert.labels @@ -92,7 +56,6 @@ function AlertSummary({ alert }: { alert: Alert }) { ) } - function AlertLabels({ alert }: { alert: Alert }) { const labels = Object.entries(alert.labels).map(([key, value]) => { return { key: key, value: value } diff --git a/src/components/alerts/alert-severity.tsx b/src/components/alerts/alert-severity.tsx new file mode 100644 index 0000000..a1068f6 --- /dev/null +++ b/src/components/alerts/alert-severity.tsx @@ -0,0 +1,41 @@ +import { cn } from "@/lib/utils" +import { Alert } from "@/types/alertmanager" + +export function AlertSeverity({ alert }: { alert: Alert }) { + const { severity } = alert.labels + + let color = 'bg-black' + let text = '???' + + switch (severity) { + case 'critical': + color = 'bg-red-600' + text = 'CRIT' + break + case 'error': + color = 'bg-red-500' + text = 'ERR' + break + case 'warning': + color = 'bg-orange-300' + text = 'WARN' + break + case 'info': + color = 'bg-blue-400' + text = 'INFO' + break + case 'none': + color = 'bg-slate-500' + text = 'NONE' + break + } + + return ( +
+ {text} +
+ ) +} diff --git a/src/components/alerts/template.tsx b/src/components/alerts/template.tsx index c1f9cdb..999d9e6 100644 --- a/src/components/alerts/template.tsx +++ b/src/components/alerts/template.tsx @@ -66,7 +66,7 @@ export function AlertsTemplate(props: Props) {
/
- {viewName ?? view} + {viewName ? viewName : view}
{