Add Grafana widget
This commit is contained in:
parent
8a6343dee7
commit
cd7d7ba729
4 changed files with 57 additions and 0 deletions
|
@ -18,6 +18,7 @@ const components = {
|
||||||
flood: dynamic(() => import("./flood/component")),
|
flood: dynamic(() => import("./flood/component")),
|
||||||
gluetun: dynamic(() => import("./gluetun/component")),
|
gluetun: dynamic(() => import("./gluetun/component")),
|
||||||
gotify: dynamic(() => import("./gotify/component")),
|
gotify: dynamic(() => import("./gotify/component")),
|
||||||
|
grafana: dynamic(() => import("./grafana/component")),
|
||||||
hdhomerun: dynamic(() => import("./hdhomerun/component")),
|
hdhomerun: dynamic(() => import("./hdhomerun/component")),
|
||||||
homebridge: dynamic(() => import("./homebridge/component")),
|
homebridge: dynamic(() => import("./homebridge/component")),
|
||||||
jackett: dynamic(() => import("./jackett/component")),
|
jackett: dynamic(() => import("./jackett/component")),
|
||||||
|
|
40
src/widgets/grafana/component.jsx
Executable file
40
src/widgets/grafana/component.jsx
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
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: alertsData, error: alertsError } = useWidgetAPI(widget, "alerts");
|
||||||
|
|
||||||
|
if (alertsError) {
|
||||||
|
return <Container error={alertsError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!alertsData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="grafana.totalalerts" />
|
||||||
|
<Block label="grafana.alertstriggered" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalAlerts = Object.keys(alertsData).length;
|
||||||
|
let alertsTriggered = 0;
|
||||||
|
Object.keys(alertsData).forEach((key) => {
|
||||||
|
if (alertsData[key].state === "alerting") {
|
||||||
|
alertsTriggered += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="total alerts" value={t("common.number", { value: totalAlerts })} />
|
||||||
|
<Block label="alerts triggered" value={t("common.number", { value: alertsTriggered })} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
14
src/widgets/grafana/widget.js
Executable file
14
src/widgets/grafana/widget.js
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/api/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
alerts: {
|
||||||
|
endpoint: "alerts",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
|
@ -13,6 +13,7 @@ import fileflows from "./fileflows/widget";
|
||||||
import flood from "./flood/widget";
|
import flood from "./flood/widget";
|
||||||
import gluetun from "./gluetun/widget";
|
import gluetun from "./gluetun/widget";
|
||||||
import gotify from "./gotify/widget";
|
import gotify from "./gotify/widget";
|
||||||
|
import grafana from "./grafana/widget";
|
||||||
import hdhomerun from "./hdhomerun/widget";
|
import hdhomerun from "./hdhomerun/widget";
|
||||||
import homebridge from "./homebridge/widget";
|
import homebridge from "./homebridge/widget";
|
||||||
import jackett from "./jackett/widget";
|
import jackett from "./jackett/widget";
|
||||||
|
@ -80,6 +81,7 @@ const widgets = {
|
||||||
flood,
|
flood,
|
||||||
gluetun,
|
gluetun,
|
||||||
gotify,
|
gotify,
|
||||||
|
grafana,
|
||||||
hdhomerun,
|
hdhomerun,
|
||||||
homebridge,
|
homebridge,
|
||||||
jackett,
|
jackett,
|
||||||
|
|
Loading…
Add table
Reference in a new issue