From 7f621ed5181d0aaface4f408e2b7eee4e6e4fb1b Mon Sep 17 00:00:00 2001 From: Mitchell <37925797+ping-localhost@users.noreply.github.com> Date: Thu, 18 Jan 2024 01:01:20 +0100 Subject: [PATCH] Feature: Netdata service widget (#2672) --- docs/widgets/services/netdata.md | 12 +++++++++++ mkdocs.yml | 1 + public/locales/en/common.json | 4 ++++ src/widgets/components.js | 1 + src/widgets/netdata/component.jsx | 33 +++++++++++++++++++++++++++++++ src/widgets/netdata/widget.js | 14 +++++++++++++ src/widgets/widgets.js | 2 ++ 7 files changed, 67 insertions(+) create mode 100644 docs/widgets/services/netdata.md create mode 100644 src/widgets/netdata/component.jsx create mode 100644 src/widgets/netdata/widget.js diff --git a/docs/widgets/services/netdata.md b/docs/widgets/services/netdata.md new file mode 100644 index 000000000..70acf490b --- /dev/null +++ b/docs/widgets/services/netdata.md @@ -0,0 +1,12 @@ +--- +title: Netdata +description: Netdata Widget Configuration +--- + +Allowed fields: `["warnings", "criticals"]`. + +```yaml +widget: + type: Netdata + url: http://netdata.host.or.ip +``` diff --git a/mkdocs.yml b/mkdocs.yml index 77f55dde7..0968da60d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -84,6 +84,7 @@ nav: - widgets/services/moonraker.md - widgets/services/mylar.md - widgets/services/navidrome.md + - widgets/services/netdata.md - widgets/services/nextcloud.md - widgets/services/nextdns.md - widgets/services/nginx-proxy-manager.md diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 1c43e5066..eaed3344c 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -795,5 +795,9 @@ "digitalRelease": "Digital release", "noEventsToday": "No events for today!", "noEventsFound": "No events found" + }, + "netdata": { + "warnings": "Warnings", + "criticals": "Criticals" } } diff --git a/src/widgets/components.js b/src/widgets/components.js index 4209b69a3..30e957405 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -58,6 +58,7 @@ const components = { moonraker: dynamic(() => import("./moonraker/component")), mylar: dynamic(() => import("./mylar/component")), navidrome: dynamic(() => import("./navidrome/component")), + netdata: dynamic(() => import("./netdata/component")), nextcloud: dynamic(() => import("./nextcloud/component")), nextdns: dynamic(() => import("./nextdns/component")), npm: dynamic(() => import("./npm/component")), diff --git a/src/widgets/netdata/component.jsx b/src/widgets/netdata/component.jsx new file mode 100644 index 000000000..9d7f2469b --- /dev/null +++ b/src/widgets/netdata/component.jsx @@ -0,0 +1,33 @@ +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: netdataData, error: netdataError } = useWidgetAPI(widget, "info"); + + if (netdataError) { + return ; + } + + if (!netdataData) { + return ( + + + + + ); + } + + return ( + + + + + ); +} diff --git a/src/widgets/netdata/widget.js b/src/widgets/netdata/widget.js new file mode 100644 index 000000000..9c7b2457c --- /dev/null +++ b/src/widgets/netdata/widget.js @@ -0,0 +1,14 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/v1/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + info: { + endpoint: "info", + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 904bd701f..b925bf74a 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -50,6 +50,7 @@ import mjpeg from "./mjpeg/widget"; import moonraker from "./moonraker/widget"; import mylar from "./mylar/widget"; import navidrome from "./navidrome/widget"; +import netdata from "./netdata/widget"; import nextcloud from "./nextcloud/widget"; import nextdns from "./nextdns/widget"; import npm from "./npm/widget"; @@ -155,6 +156,7 @@ const widgets = { moonraker, mylar, navidrome, + netdata, nextcloud, nextdns, npm,