Open quinti123 opened 1 year ago
I get the UptimeKuma-Statistics with the following Javascript using the /metrics subpage. It creates 4 states containing the number of checks per status. Maybe it will help you as long as there is no adapter for it.
Known restrictions (see also https://github.com/louislam/uptime-kuma/issues/3579):
/* =====================================================================
03.09.2023 R.Krüger --- Read UPTIMEKUMA STATS
===================================================================== */
const uptimekumaURL = 'https://<HERE URL UPTIMEKUMA>/metrics';
const uptimekumaAPIKey = '<HERE UPTIMEKUMA GENERATED APIKEY>';
const objH = '0_userdata.0.uptimekuma';
const axios = require('axios');
const uptimeREGEX = /^(.*){monitor_name="(.*)",monitor_type="(.*)",monitor_url="(.*)",monitor_hostname="(.*)",monitor_port="(.*)"}(.*)/;
Main();
schedule("* * * * *", GetUptimeKumaData); // Jede Minute ausführen
async function Main() {
// -------------------------------------------------------------------------------
await Init();
await GetUptimeKumaData();
// -------------------------------------------------------------------------------
}
async function Init() {
// ------------------------------------------------------------------------------------------
await createStateAsync(objH + '.Counter.Up', { name: 'Count Status AKTIV', role: 'state', type: 'number'});
await createStateAsync(objH + '.Counter.Down', { name: 'Count Status IMAKTIV', role: 'state', type: 'number'});
await createStateAsync(objH + '.Counter.Maintenance',{ name: 'Count Status WARTUNG', role: 'state', type: 'number'});
await createStateAsync(objH + '.Counter.Pending', { name: 'Count Status AUSSTEHEND', role: 'state', type: 'number'});
// ------------------------------------------------------------------------------------------
}
async function GetUptimeKumaData () {
// -------------------------------------------------------------------------------
const axiosParam = { method: 'get',
url: uptimekumaURL,
headers: { 'Authorization': 'Basic ' + uptimekumaAPIKey },
maxBodyLength: Infinity };
await axios(axiosParam)
.then((response) => {
var metrics = response.data.split('\n');
var counter = [];
for (let c = 0; c <= 3; c++) counter[c] = 0;
metrics.forEach(async function (item) {
let metricsLine = item.match(uptimeREGEX);
if (!metricsLine) return;
if (metricsLine[1] == "monitor_status") {
let c = Number(metricsLine[7]);
counter[c]++;
}
})
// # HELP monitor_status Monitor Status (1 = UP, 0= DOWN, 2=PENDING, 3= MAINTENANCE)
setState(objH + '.Counter.Down', counter[0]);
setState(objH + '.Counter.Up', counter[1]);
setState(objH + '.Counter.Pending', counter[2]);
setState(objH + '.Counter.Maintenance', counter[3]);
log(`UP:${counter[1]} DOWN:${counter[0]} PEND:${counter[2]} MAINT:${counter[3]}`);
})
.catch((error) => {
log('Lesen UptimeKuma fehlgeschlagen ('+error+')!', 'error');
});
// -------------------------------------------------------------------------------
}
@RK62 Das Skript wirft bei mir leider eine Fehlermeldung aus:
18:17:00.021 error javascript.0 (727) script.js.common.Miscellaneous.Uptime_Kuma: Lesen UptimeKuma fehlgeschlagen (Error: connect ECONNREFUSED 192.168.15.19:443)!
Ich denke es liegt am Port. Ich weiß jedoch nicht, wie ich das im Skript anpassen kann. Kannst du hier helfen?
@MC-1984
@RK62
Danke für die schnelle Rückmeldung.
Ja, key ist hinterlegt.
http hatte ich schon ausprobiert. Fehlermeldung ist die gleiche nur mit Port 80.
javascript.0 (727) script.js.common.Miscellaneous.Uptime_Kuma: Lesen UptimeKuma fehlgeschlagen (Error: connect ECONNREFUSED 192.168.15.19:80)!
http://192.168.15.19/metrics direkt aufzurufen funktioniert leider auch nicht. Bei mir wird das über Port 3001 aufgerufen (nutze einen fertigen LXC Container).
Dann sollte http://192.168.15.19:3001/metrics der richtige Aufruf sein. Vorab am Browser checken, dann ggf mit CURL aus dem ioBroker Container. Ggf schlägt dann auch Firewall zu.
@RK62 Ja das funktioniert. Es kommt ein Anmeldebildschirm. Ich schaffe es aber einfach nicht im Skript den Port zu ändern.
Ich habe hier über monitor_port bei const uptimeREGEX schon alles mögliche ausprobiert, es aber einfach nicht hinbekommen den Port auf 3001 einzustellen. Kannst du mir sagen, wo und wie ich den Port in deinem Skript einstellen kann?
const uptimekumaURL = 'http://192.168.15.19:3001/metrics'; Sonst kann ich Dir auch nicht weiterhelfen. Ausser URL und APIKey brauchst Du nichts anpassen.
@RK62 Besten Dank für deine Hilfe. Das hat leider auch nicht funktioniert. Dann muss ich doch auf den Adapter warten ;-) Trotzdem besten Dank!
What kind of device or service you would like to see an adapter for? Software uptime Kuma
Is the device connected to the internet or only in the local network available? mostly local Network
Is an official App or Website available? https://uptime.kuma.pet
Is an official API including documentation available? Are other libraries for an integration available? see github
Is this device already integrated in other Smart Home systems? no
Is this device already integrated in homebridge? Might the ham adapter together with the homebridge plugin be sufficient? no