Enhancement: support pfsense v2 api (#3716)

pull/3719/head
shamoon 4 months ago committed by GitHub
parent b8af7ad95d
commit 9d16e280cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -26,5 +26,6 @@ widget:
headers: # optional, or username/password
Authorization: client_id client_token
wan: igb0
version: v2 # optional, defaults to v1
fields: ["load", "memory", "temp", "wanStatus"] # optional
```

@ -399,7 +399,7 @@ export function cleanServiceGroups(groups) {
expandOneStreamToTwoRows,
showEpisodeNumber,
// glances, pihole
// glances, pihole, pfsense
version,
// glances
@ -509,6 +509,9 @@ export function cleanServiceGroups(groups) {
if (type === "unifi") {
if (site) cleanedService.widget.site = site;
}
if (type === "pfsense") {
if (version) cleanedService.widget.version = version;
}
if (type === "proxmox") {
if (node) cleanedService.widget.node = node;
}

@ -9,8 +9,12 @@ export default function Component({ service }) {
const { widget } = service;
const { data: systemData, error: systemError } = useWidgetAPI(widget, "system");
const { data: interfaceData, error: interfaceError } = useWidgetAPI(widget, "interface");
const version = widget.version ?? 1;
const { data: systemData, error: systemError } = useWidgetAPI(widget, version === 1 ? "system" : "systemv2");
const { data: interfaceData, error: interfaceError } = useWidgetAPI(
widget,
version === 1 ? "interface" : "interfacev2",
);
const showWanIP = widget.fields?.filter((f) => f !== "wanIP").length <= 4 && widget.fields?.includes("wanIP");
const showDiskUsage = widget.fields?.filter((f) => f !== "disk").length <= 4 && widget.fields?.includes("disk");
@ -37,7 +41,10 @@ export default function Component({ service }) {
return (
<Container service={service}>
<Block label="pfsense.load" value={systemData.data.load_avg[0]} />
<Block
label="pfsense.load"
value={version === 1 ? systemData.data.load_avg[0] : systemData.data.cpu_load_avg[0]}
/>
<Block
label="pfsense.memory"
value={t("common.percent", { value: (systemData.data.mem_usage * 100).toFixed(2) })}

@ -1,16 +1,24 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}/api/v1/{endpoint}",
api: "{url}/api/{endpoint}",
proxyHandler: genericProxyHandler,
mappings: {
system: {
endpoint: "status/system",
endpoint: "v1/status/system",
validate: ["data"],
},
interface: {
endpoint: "status/interface",
endpoint: "v1/status/interface",
validate: ["data"],
},
systemv2: {
endpoint: "v2/status/system",
validate: ["data"],
},
interfacev2: {
endpoint: "v2/status/interfaces?limit=0&offset=0",
validate: ["data"],
},
},

Loading…
Cancel
Save