mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-18 02:29:49 +00:00
Feature: Zabbix service widget (#3905)
Co-Authored-By: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
4c6150a545
commit
44f8e9d4da
10 changed files with 136 additions and 6 deletions
|
@ -8,14 +8,18 @@ import widgets from "widgets/widgets";
|
|||
|
||||
const logger = createLogger("jsonrpcProxyHandler");
|
||||
|
||||
export async function sendJsonRpcRequest(url, method, params, username, password) {
|
||||
export async function sendJsonRpcRequest(url, method, params, widget) {
|
||||
const headers = {
|
||||
"content-type": "application/json",
|
||||
accept: "application/json",
|
||||
};
|
||||
|
||||
if (username && password) {
|
||||
headers.authorization = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
||||
if (widget.username && widget.password) {
|
||||
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
|
||||
}
|
||||
|
||||
if (widget.key) {
|
||||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
}
|
||||
|
||||
const client = new JSONRPCClient(async (rpcRequest) => {
|
||||
|
@ -67,6 +71,9 @@ export default async function jsonrpcProxyHandler(req, res) {
|
|||
const widget = await getServiceWidget(group, service);
|
||||
const api = widgets?.[widget.type]?.api;
|
||||
|
||||
const [, mapping] = Object.entries(widgets?.[widget.type]?.mappings).find(([, value]) => value.endpoint === method);
|
||||
const params = mapping?.params ?? null;
|
||||
|
||||
if (!api) {
|
||||
return res.status(403).json({ error: "Service does not support API calls" });
|
||||
}
|
||||
|
@ -74,8 +81,7 @@ export default async function jsonrpcProxyHandler(req, res) {
|
|||
if (widget) {
|
||||
const url = formatApiCall(api, { ...widget });
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [status, contentType, data] = await sendJsonRpcRequest(url, method, null, widget.username, widget.password);
|
||||
const [status, , data] = await sendJsonRpcRequest(url, method, params, widget);
|
||||
return res.status(status).end(data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue