generated from Dicken/dickendock
Commit 8: Plugin-System (Scanner erweitern, Geräte importieren, Icons)
This commit is contained in:
9
apps/backend/plugins/static-import/devices.example.json
Normal file
9
apps/backend/plugins/static-import/devices.example.json
Normal file
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"hostname": "nas",
|
||||
"ip": "192.168.1.20",
|
||||
"mac": "AA:BB:CC:DD:EE:FF",
|
||||
"manufacturer": "Synology",
|
||||
"model": "DS920+"
|
||||
}
|
||||
]
|
||||
1
apps/backend/plugins/static-import/devices.json
Normal file
1
apps/backend/plugins/static-import/devices.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
40
apps/backend/plugins/static-import/index.js
Normal file
40
apps/backend/plugins/static-import/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const currentDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
/**
|
||||
* Beispiel-Plugin: importiert Geräte aus einer lokalen devices.json neben
|
||||
* diesem Plugin. Zeigt das importDevices()-Pattern für eigene Datenquellen
|
||||
* (z. B. ein Inventar-Export oder eine externe API) – im Unterschied zu den
|
||||
* Netzwerk-Scannern rein datengetrieben, kein eigener Netzwerkzugriff nötig.
|
||||
*
|
||||
* Standardmäßig ist devices.json leer, damit beim ersten Start keine
|
||||
* Fantasiegeräte auftauchen. Zum Ausprobieren einfach Einträge ergänzen und
|
||||
* unter Admin -> Plugins auf "Jetzt importieren" klicken.
|
||||
*/
|
||||
export default {
|
||||
name: "static-import",
|
||||
version: "1.0.0",
|
||||
description: "Importiert Geräte aus plugins/static-import/devices.json.",
|
||||
|
||||
async importDevices() {
|
||||
try {
|
||||
const raw = readFileSync(join(currentDir, "devices.json"), "utf-8");
|
||||
const entries = JSON.parse(raw);
|
||||
|
||||
return entries.map((entry) => ({
|
||||
hostname: entry.hostname,
|
||||
ip: entry.ip,
|
||||
mac: entry.mac ?? undefined,
|
||||
manufacturer: entry.manufacturer ?? undefined,
|
||||
model: entry.model ?? undefined,
|
||||
online: false,
|
||||
source: "plugin",
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user