/********************************************************* * IOBROKER INSTANZSTATUS PER HTML E-MAIL * * ROT * - deaktiviert * - gestoppt * * GELB * - info.connection = false * * GRUEN * - alles OK * * GRAU * - ungeprueft (ausgeschlossen) * *********************************************************/ /********************************************************* * KONFIGURATION *********************************************************/ // Empfaenger const EMAIL_TO = 'email@email.de'; // Betreff const EMAIL_SUBJECT = 'ioBroker Instanzstatus'; // Wartezeit nach Scriptstart const START_DELAY_MINUTES = 5; // Adapter von der Pruefung ausschliessen const EXCLUDED_ADAPTERS = [ 'ical.', 'openweathermap.' ]; /********************************************************* * AB HIER NICHTS MEHR AENDERN *********************************************************/ const START_DELAY_MS = START_DELAY_MINUTES * 60 * 1000; /********************************************************* * HILFSFUNKTION *********************************************************/ function isExcluded(instanceId) { return EXCLUDED_ADAPTERS.some(adapter => instanceId.startsWith(adapter) ); } /********************************************************* * PRUEFUNG *********************************************************/ function checkInstances() { const critical = []; const warning = []; const ok = []; const unchecked = []; const warningAdapters = new Set(); // ---------------------------------------------------- // GELBE ADAPTER ERMITTELN // ---------------------------------------------------- const allStates = $('state'); allStates.each(function(id) { try { if (!id.endsWith('.info.connection')) { return; } const state = getState(id); if (state && state.val === false) { const parts = id.split('.'); if (parts.length >= 2) { warningAdapters.add(parts[0] + '.' + parts[1]); } } } catch (e) { // ignorieren } }); // ---------------------------------------------------- // INSTANZEN PRUEFEN // ---------------------------------------------------- const allAliveStates = $('state[id=system.adapter.*.alive]'); allAliveStates.each(function(id) { try { const aliveState = getState(id); if (!aliveState) { return; } const alive = aliveState.val; const instanceId = id .replace('system.adapter.', '') .replace('.alive', ''); const obj = getObject('system.adapter.' + instanceId); if (!obj || !obj.common) { return; } // AUSGESCHLOSSEN if (isExcluded(instanceId)) { unchecked.push({ instance: instanceId, status: 'UNGEPRUEFT' }); return; } const enabled = obj.common.enabled; // ROT if (!enabled) { critical.push({ instance: instanceId, status: 'DEAKTIVIERT' }); return; } if (!alive) { critical.push({ instance: instanceId, status: 'GESTOPPT' }); return; } // GELB if (warningAdapters.has(instanceId)) { warning.push({ instance: instanceId, status: 'VERBINDUNGSPROBLEM' }); return; } // GRUEN ok.push({ instance: instanceId, status: 'OK' }); } catch (e) { // ignorieren } }); // ---------------------------------------------------- // SORTIEREN // ---------------------------------------------------- critical.sort((a, b) => a.instance.localeCompare(b.instance)); warning.sort((a, b) => a.instance.localeCompare(b.instance)); ok.sort((a, b) => a.instance.localeCompare(b.instance)); unchecked.sort((a, b) => a.instance.localeCompare(b.instance)); // ---------------------------------------------------- // HTML // ---------------------------------------------------- let html = ''; html += ''; html += ''; html += '

ioBroker Instanzstatus

'; html += '

'; html += 'Kritisch: ' + critical.length + '
'; html += 'Warnung: ' + warning.length + '
'; html += 'OK: ' + ok.length + '
'; html += 'Ungeprueft: ' + unchecked.length; html += '

'; html += ''; html += ''; html += ''; html += ''; html += ''; critical.forEach(item => { html += ''; html += ''; html += ''; html += ''; }); warning.forEach(item => { html += ''; html += ''; html += ''; html += ''; }); ok.forEach(item => { html += ''; html += ''; html += ''; html += ''; }); unchecked.forEach(item => { html += ''; html += ''; html += ''; html += ''; }); html += '
InstanzStatus
' + item.instance + '' + item.status + '
' + item.instance + '' + item.status + '
' + item.instance + '' + item.status + '
' + item.instance + '' + item.status + '
'; html += '
'; html += 'Erstellt: ' + formatDate(new Date(), 'DD.MM.YYYY hh:mm:ss') + ''; html += ''; html += ''; // ---------------------------------------------------- // LOG + MAIL // ---------------------------------------------------- log( 'Instanzstatus: ' + critical.length + ' kritisch, ' + warning.length + ' Warnungen, ' + ok.length + ' OK, ' + unchecked.length + ' ungeprueft' ); sendTo('email.0', { to: EMAIL_TO, subject: EMAIL_SUBJECT, html: html }); log('Instanzstatus per E-Mail versendet an: ' + EMAIL_TO); } /********************************************************* * START *********************************************************/ log('Instanzstatus-Pruefung startet in ' + START_DELAY_MINUTES + ' Minuten'); setTimeout(function () { checkInstances(); }, START_DELAY_MS);