diff --git a/docs/widgets/services/grafana.md b/docs/widgets/services/grafana.md index 14897a6e..bfdebb2c 100644 --- a/docs/widgets/services/grafana.md +++ b/docs/widgets/services/grafana.md @@ -3,9 +3,7 @@ title: Grafana description: Grafana Widget Configuration --- -Allowed fields: `["dashboards", "datasources", "totalalerts", "alertstriggered", "alertmanager"]`. - -`alertmanager` is for the new grafana alerts api since the api used by `alertstriggered` has been deprecated. If `alertstriggered` does not work, try `alertmanager`. +Allowed fields: `["dashboards", "datasources", "totalalerts", "alertstriggered"]`. ```yaml widget: diff --git a/public/locales/en/common.json b/public/locales/en/common.json index d53e6279..aa4ef1e5 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -662,8 +662,7 @@ "dashboards": "Dashboards", "datasources": "Data Sources", "totalalerts": "Total Alerts", - "alertstriggered": "Alerts Triggered", - "alertmanager": "Alerts Triggered" + "alertstriggered": "Alerts Triggered" }, "nextcloud": { "cpuload": "Cpu Load", diff --git a/src/widgets/grafana/component.jsx b/src/widgets/grafana/component.jsx index 4bc71738..ace32f3d 100755 --- a/src/widgets/grafana/component.jsx +++ b/src/widgets/grafana/component.jsx @@ -12,18 +12,27 @@ export default function Component({ service }) { const { data: alertsData, error: alertsError } = useWidgetAPI(widget, "alerts"); const { data: alertmanagerData, error: alertmanagerError } = useWidgetAPI(widget, "alertmanager"); - if (statsError || alertsError || alertmanagerError) { + let alertsInt = 0; + + if ((alertsError && alertsError.message === "HTTP Error") || !alertsData || alertsData.length === 0) { + if (alertmanagerData) { + alertsInt = alertmanagerData.length; + } + } else { + alertsInt = alertsData.filter((a) => a.state === "alerting").length; + } + + if (statsError || (alertsError && alertmanagerError)) { return ; } - if (!statsData || !alertsData || !alertmanagerData) { + if (!statsData || (!alertsData && !alertmanagerData)) { return ( - ); } @@ -33,11 +42,7 @@ export default function Component({ service }) { - a.state === "alerting").length })} - /> - + ); }