Files

41 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 [];
}
},
};