Compare commits

...

3 Commits

Author SHA1 Message Date
shamoon
e4d42b5393 FIx: glances containers header position (#4496) 2024-12-26 14:51:11 -08:00
shamoon
f717e59085 Enhancement: support 'nice name' for beszel system ID (#4495) 2024-12-26 11:07:33 -08:00
shamoon
fd05ae377c Enhancement: Better handle some beszel errors (#4493) 2024-12-25 12:17:10 -08:00
4 changed files with 27 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ Learn more about [Beszel](https://github.com/henrygd/beszel)
The widget has two modes, a single system with detailed info if `systemId` is provided, or an overview of all systems if `systemId` is not provided.
The `systemID` in the `id` field on the collections page of Beszel.
The `systemID` is the `id` field on the collections page of Beszel under the PocketBase admin panel. You can also use the 'nice name' from the Beszel UI.
Allowed fields for 'overview' mode: `["systems", "up"]`
Allowed fields for a single system: `["name", "status", "updated", "cpu", "memory", "disk", "network"]`

View File

@@ -20,8 +20,20 @@ export default function Component({ service }) {
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
}
if (systemsError) {
return <Container service={service} error={systemsError} />;
let system = null;
let finalError = systemsError;
if (systems && !systems.items) {
finalError = { message: "No items returned from beszel API" };
} else if (systems && systems.items && systemId) {
system = systems.items.find((item) => item.id === systemId || item.name === systemId);
if (!system) {
finalError = { message: `System with id ${systemId} not found` };
}
}
if (finalError) {
return <Container service={service} error={finalError} />;
}
if (!systems) {
@@ -33,9 +45,7 @@ export default function Component({ service }) {
);
}
if (systemId) {
const system = systems.items.find((item) => item.id === systemId);
if (system) {
return (
<Container service={service}>
<Block label="beszel.name" value={system.name} />

View File

@@ -59,7 +59,7 @@ export default async function beszelProxyHandler(req, res) {
if (!token) {
[status, token] = await login(loginUrl, widget.username, widget.password, service);
if (status !== 200) {
logger.debug(`HTTP ${status} logging into Beszel: ${token}`);
logger.debug(`HTTP ${status} logging into Beszel: ${JSON.stringify(token)}`);
return res.status(status).send(token);
}
}
@@ -72,13 +72,13 @@ export default async function beszelProxyHandler(req, res) {
},
});
if (status === 403) {
if ([400, 403].includes(status)) {
logger.debug(`HTTP ${status} retrieving data from Beszel, logging in and trying again.`);
cache.del(`${tokenCacheKey}.${service}`);
[status, token] = await login(loginUrl, widget.username, widget.password, service);
if (status !== 200) {
logger.debug(`HTTP ${status} logging into Beszel: ${data}`);
logger.debug(`HTTP ${status} logging into Beszel: ${JSON.stringify(data)}`);
return res.status(status).send(data);
}

View File

@@ -38,10 +38,16 @@ export default function Component({ service }) {
}
data.splice(chart ? 5 : 1);
let headerYPosition = "top-4";
let listYPosition = "bottom-4";
if (chart) {
headerYPosition = "-top-6";
listYPosition = "-top-3";
}
return (
<Container chart={chart}>
<Block position="top-4 right-3 left-3">
<Block position={`${headerYPosition} right-3 left-3`}>
<div className="flex items-center text-xs">
<div className="grow" />
<div className="w-14 text-right italic">{t("resources.cpu")}</div>
@@ -49,7 +55,7 @@ export default function Component({ service }) {
</div>
</Block>
<Block position="bottom-4 right-3 left-3">
<Block position={`${listYPosition} right-3 left-3`}>
<div className="pointer-events-none text-theme-900 dark:text-theme-200">
{data.map((item) => (
<div key={item[idKey]} className="text-[0.75rem] h-[0.8rem]">