mirror of
https://github.com/gethomepage/homepage.git
synced 2025-07-31 14:33:48 -04:00
Enhancement: support for new grafana alerting api (#5476)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
f5ecd6d787
commit
dba3a1f893
@ -5,11 +5,18 @@ description: Grafana Widget Configuration
|
|||||||
|
|
||||||
Learn more about [Grafana](https://github.com/grafana/grafana).
|
Learn more about [Grafana](https://github.com/grafana/grafana).
|
||||||
|
|
||||||
|
| Grafana Version | Homepage Widget Version |
|
||||||
|
| --------------- | ----------------------- |
|
||||||
|
| <= v10.4 | 1 (default) |
|
||||||
|
| > v10.4 | 2 |
|
||||||
|
|
||||||
Allowed fields: `["dashboards", "datasources", "totalalerts", "alertstriggered"]`.
|
Allowed fields: `["dashboards", "datasources", "totalalerts", "alertstriggered"]`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
widget:
|
widget:
|
||||||
type: grafana
|
type: grafana
|
||||||
|
version: 2 # optional, default is 1
|
||||||
|
alerts: alertmanager # optional, default is grafana
|
||||||
url: http://grafana.host.or.ip:port
|
url: http://grafana.host.or.ip:port
|
||||||
username: username
|
username: username
|
||||||
password: password
|
password: password
|
||||||
|
@ -407,6 +407,9 @@ export function cleanServiceGroups(groups) {
|
|||||||
|
|
||||||
// spoolman
|
// spoolman
|
||||||
spoolIds,
|
spoolIds,
|
||||||
|
|
||||||
|
// grafana
|
||||||
|
alerts,
|
||||||
} = widgetData;
|
} = widgetData;
|
||||||
|
|
||||||
let fieldsList = fields;
|
let fieldsList = fields;
|
||||||
@ -514,7 +517,18 @@ export function cleanServiceGroups(groups) {
|
|||||||
if (snapshotPath) widget.snapshotPath = snapshotPath;
|
if (snapshotPath) widget.snapshotPath = snapshotPath;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
["beszel", "glances", "immich", "komga", "mealie", "pfsense", "pihole", "speedtest", "wgeasy"].includes(type)
|
[
|
||||||
|
"beszel",
|
||||||
|
"glances",
|
||||||
|
"immich",
|
||||||
|
"komga",
|
||||||
|
"mealie",
|
||||||
|
"pfsense",
|
||||||
|
"pihole",
|
||||||
|
"speedtest",
|
||||||
|
"wgeasy",
|
||||||
|
"grafana",
|
||||||
|
].includes(type)
|
||||||
) {
|
) {
|
||||||
if (version) widget.version = parseInt(version, 10);
|
if (version) widget.version = parseInt(version, 10);
|
||||||
}
|
}
|
||||||
@ -593,6 +607,9 @@ export function cleanServiceGroups(groups) {
|
|||||||
if (type === "jellystat") {
|
if (type === "jellystat") {
|
||||||
if (days !== undefined) widget.days = parseInt(days, 10);
|
if (days !== undefined) widget.days = parseInt(days, 10);
|
||||||
}
|
}
|
||||||
|
if (type === "grafana") {
|
||||||
|
if (alerts) widget.alerts = alerts;
|
||||||
|
}
|
||||||
return widget;
|
return widget;
|
||||||
});
|
});
|
||||||
return cleanedService;
|
return cleanedService;
|
||||||
|
@ -6,27 +6,51 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
|
|||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
|
const { version = 1, alerts = "grafana" } = widget;
|
||||||
|
|
||||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
|
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
|
||||||
const { data: alertsData, error: alertsError } = useWidgetAPI(widget, "alerts");
|
|
||||||
const { data: alertmanagerData, error: alertmanagerError } = useWidgetAPI(widget, "alertmanager");
|
|
||||||
|
|
||||||
let alertsInt = 0;
|
let primaryAlertsEndpoint = "alerts";
|
||||||
|
let secondaryAlertsEndpoint = "grafana";
|
||||||
if (alertsError || !alertsData || alertsData.length === 0) {
|
if (version === 2) {
|
||||||
if (alertmanagerData) {
|
primaryAlertsEndpoint = alerts;
|
||||||
alertsInt = alertmanagerData.length;
|
secondaryAlertsEndpoint = "";
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alertsInt = alertsData.filter((a) => a.state === "alerting").length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statsError || (alertsError && alertmanagerError)) {
|
const { data: primaryAlertsData, error: primaryAlertsError } = useWidgetAPI(widget, primaryAlertsEndpoint);
|
||||||
|
const { data: secondaryAlertsData, error: secondaryAlertsError } = useWidgetAPI(widget, secondaryAlertsEndpoint);
|
||||||
|
|
||||||
|
let alertsInt = 0;
|
||||||
|
let alertsError = null;
|
||||||
|
if (version === 1) {
|
||||||
|
if (primaryAlertsError || !primaryAlertsData || primaryAlertsData.length === 0) {
|
||||||
|
if (secondaryAlertsData) {
|
||||||
|
alertsInt = secondaryAlertsData.length;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alertsInt = primaryAlertsData.filter((a) => a.state === "alerting").length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (primaryAlertsError && secondaryAlertsError) {
|
||||||
|
alertsError = primaryAlertsError ?? secondaryAlertsError;
|
||||||
|
}
|
||||||
|
} else if (version === 2) {
|
||||||
|
if (primaryAlertsData) {
|
||||||
|
alertsInt = primaryAlertsData.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (primaryAlertsError) {
|
||||||
|
alertsError = primaryAlertsError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statsError || alertsError) {
|
||||||
return <Container service={service} error={statsError ?? alertsError} />;
|
return <Container service={service} error={statsError ?? alertsError} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!statsData || (!alertsData && !alertmanagerData)) {
|
if (!statsData) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="grafana.dashboards" />
|
<Block label="grafana.dashboards" />
|
||||||
|
@ -9,6 +9,9 @@ const widget = {
|
|||||||
endpoint: "alerts",
|
endpoint: "alerts",
|
||||||
},
|
},
|
||||||
alertmanager: {
|
alertmanager: {
|
||||||
|
endpoint: "alertmanager/alertmanager/api/v2/alerts",
|
||||||
|
},
|
||||||
|
grafana: {
|
||||||
endpoint: "alertmanager/grafana/api/v2/alerts",
|
endpoint: "alertmanager/grafana/api/v2/alerts",
|
||||||
},
|
},
|
||||||
stats: {
|
stats: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user