Added Option for Grafana Alertmanager (#2498)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/2528/head
myztillx 1 year ago committed by GitHub
parent 4d6754e4a7
commit 59ccc3a215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,12 +10,23 @@ export default function Component({ service }) {
const { widget } = service;
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
const { data: alertsData, error: alertsError } = useWidgetAPI(widget, "alerts");
const { data: alertmanagerData, error: alertmanagerError } = useWidgetAPI(widget, "alertmanager");
if (statsError || alertsError) {
let alertsInt = 0;
if (alertsError || !alertsData || alertsData.length === 0) {
if (alertmanagerData) {
alertsInt = alertmanagerData.length;
}
} else {
alertsInt = alertsData.filter((a) => a.state === "alerting").length;
}
if (statsError || (alertsError && alertmanagerError)) {
return <Container service={service} error={statsError ?? alertsError} />;
}
if (!statsData || !alertsData) {
if (!statsData || (!alertsData && !alertmanagerData)) {
return (
<Container service={service}>
<Block label="grafana.dashboards" />
@ -31,10 +42,7 @@ export default function Component({ service }) {
<Block label="grafana.dashboards" value={t("common.number", { value: statsData.dashboards })} />
<Block label="grafana.datasources" value={t("common.number", { value: statsData.datasources })} />
<Block label="grafana.totalalerts" value={t("common.number", { value: statsData.alerts })} />
<Block
label="grafana.alertstriggered"
value={t("common.number", { value: alertsData.filter((a) => a.state === "alerting").length })}
/>
<Block label="grafana.alertstriggered" value={t("common.number", { value: alertsInt })} />
</Container>
);
}

@ -8,6 +8,9 @@ const widget = {
alerts: {
endpoint: "alerts",
},
alertmanager: {
endpoint: "alertmanager/grafana/api/v2/alerts",
},
stats: {
endpoint: "admin/stats",
validate: ["dashboards"],

Loading…
Cancel
Save