Merge pull request #999 from benphelps/add-grafana-widget

Add grafana widget
pull/1008/head
shamoon 2 years ago committed by GitHub
commit 2c6b2a1474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -483,5 +483,11 @@
"processing": "Processing",
"processed": "Processed",
"time": "Time"
},
"grafana": {
"dashboards": "Dashboards",
"datasources": "Data Sources",
"totalalerts": "Total Alerts",
"alertstriggered": "Alerts Triggered"
}
}

@ -18,6 +18,7 @@ const components = {
flood: dynamic(() => import("./flood/component")),
gluetun: dynamic(() => import("./gluetun/component")),
gotify: dynamic(() => import("./gotify/component")),
grafana: dynamic(() => import("./grafana/component")),
hdhomerun: dynamic(() => import("./hdhomerun/component")),
homebridge: dynamic(() => import("./homebridge/component")),
jackett: dynamic(() => import("./jackett/component")),

@ -0,0 +1,37 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
const { data: alertsData, error: alertsError } = useWidgetAPI(widget, "alerts");
if (statsError || alertsError) {
return <Container error={statsError ?? alertsError} />;
}
if (!statsData || !alertsData) {
return (
<Container service={service}>
<Block label="grafana.dashboards" />
<Block label="grafana.datasources" />
<Block label="grafana.totalalerts" />
<Block label="grafana.alertstriggered" />
</Container>
);
}
return (
<Container service={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 })} />
</Container>
);
}

@ -0,0 +1,20 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}/api/{endpoint}",
proxyHandler: genericProxyHandler,
mappings: {
alerts: {
endpoint: "alerts",
},
stats: {
endpoint: "admin/stats",
validate: [
"dashboards"
]
},
},
};
export default widget;

@ -13,6 +13,7 @@ import fileflows from "./fileflows/widget";
import flood from "./flood/widget";
import gluetun from "./gluetun/widget";
import gotify from "./gotify/widget";
import grafana from "./grafana/widget";
import hdhomerun from "./hdhomerun/widget";
import homebridge from "./homebridge/widget";
import jackett from "./jackett/widget";
@ -80,6 +81,7 @@ const widgets = {
flood,
gluetun,
gotify,
grafana,
hdhomerun,
homebridge,
jackett,

Loading…
Cancel
Save