Hi,
I'm trying to access the PBS api through a little script.
Script:
I get the following results (from the Chrome DevTool on the page where the script is running):
I'm trying to access the PBS api through a little script.
- If I access them from the browser, I can see all of the data form all of the three api nodes
- If I access them from the script, I have null responses from two of them (see next)
- I'm using a user/password on the browser, apitoken in the script (apitoken added to the same user)
- I gave Audit permissions, at root path, both at the user and at the apitoken.
- The apitoken works as I can scrape one of the api nodes, I should see the others or get authorization errors, not null data.
Script:
Code:
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: datastoreData, error: datastoreError } = useWidgetAPI(widget, "status/datastore-usage");
const { data: tasksData, error: tasksError } = useWidgetAPI(widget, "nodes/localhost/tasks");
const { data: hostData, error: hostError } = useWidgetAPI(widget, "nodes/localhost/status");
if (datastoreError || tasksError || hostError) {
const finalError = tasksError ?? datastoreError ?? hostError;
return <Container service={service} error={finalError} />;
}
if (!datastoreData || !tasksData || !hostData) {
return (
<Container service={service}>
<Block label="proxmoxbackupserver.datastore_usage" />
<Block label="proxmoxbackupserver.failed_tasks_24h" />
<Block label="proxmoxbackupserver.cpu_usage" />
<Block label="proxmoxbackupserver.memory_usage" />
</Container>
);
}
const datastoreUsage = datastoreData.data[0].used / datastoreData.data[0].total * 100;
const cpuUsage = hostData.data.cpu * 100;
const memoryUsage = hostData.data.memory.used / hostData.data.memory.total * 100;
const failedTasks = tasksData.total >= 100 ? "99+" : tasksData.total;
return (
<Container service={service}>
<Block label="proxmoxbackupserver.datastore_usage" value={t("common.percent", { value: datastoreUsage })} />
<Block label="proxmoxbackupserver.failed_tasks_24h" value={failedTasks} />
<Block label="proxmoxbackupserver.cpu_usage" value={t("common.percent", { value: cpuUsage })} />
<Block label="proxmoxbackupserver.memory_usage" value={t("common.percent", { value: memoryUsage })} />
</Container>
);
}
I get the following results (from the Chrome DevTool on the page where the script is running):
Code:
request:
type=proxmoxbackupserver&group=Management&service=Proxmox+Backup+Server&endpoint=status%2Fdatastore-usage
response:
{"data":[]}
Code:
request:
type=proxmoxbackupserver&group=Management&service=Proxmox+Backup+Server&endpoint=nodes%2Flocalhost%2Ftasks
response:
{"total":0,"data":[]}
Code:
request:
type=proxmoxbackupserver&group=Management&service=Proxmox+Backup+Server&endpoint=nodes%2Flocalhost%2Fstatus
response:
{
"data": {
"cpu": 0.0036681950812839093,
"cpuinfo": {
"cpus": 12,
"model": "Intel(R) Core(TM) i7-8700T CPU @ 2.40GHz",
"sockets": 1
},
"info": {
"fingerprint": "fingerprint"
},
"kversion": "Linux 6.2.16-10-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-10 (2023-08-18T11:42Z)",
"loadavg": [
0.07,
0.09,
0.02
],
"memory": {
"free": 23020175360,
"total": 25019404288,
"used": 1999228928
},
"root": {
"avail": 222679269376,
"total": 232441511936,
"used": 9762242560
},
"swap": {
"free": 0,
"total": 0,
"used": 0
},
"uptime": 109568,
"wait": 0.0
}
}