Status von Events abfragen

Hi,
wie kann man den Status von Events abfragen? Bei Scripten geht es mit GetScript und bei Instanzen mit GetInstanz aber GetEvent scheint da keine Information zu liefern. Per Zufall habe ich heute entdeckt das bei mir ein Event defekt war und das möchte ich gerne automatisieren.

Ralf

Hallo,

was war denn kaputt an diesem Event? Ich prüfen nur, ob ein verknüpfte Variable existiert

demel

Ich verwende dieses Script, um IPS auf Konsistenz zu prüfen

<?php

declare(strict_types=1);

// Variable A: Typ String, Profil ~HTML-Box
// Variable B: Typ  Integer
// Variable C: Typ  Integer, Profil ~UnixTimestamp

$startTime = IPS_GetKernelStartTime();

$errorText = '';
$errorTotal = 0;

// Transactions
$now = time();
$sdata = IPS_GetSnapshot();
$udata = utf8_encode($sdata);
$snapshot = json_decode($udata, true);
$tps = floor($snapshot['timestamp'] / ($now - $startTime) * 10) / 10;

// Threads
$threadList = IPS_GetScriptThreadList();
$threadCount = 0;
foreach ($threadList as $t => $i) {
    $thread = IPS_GetScriptThread($i);
    $ScriptID = $thread['ScriptID'];
    if ($ScriptID != 0) {
        $threadCount++;
    }
}

// Timer
$timerCount = 0;
$timer1MinCount = 0;
$timer5MinCount = 0;
$timerList = IPS_GetTimerList();
foreach ($timerList as $t) {
    $timer = IPS_GetTimer($t);
    $next_run = $timer['NextRun'];
    if ($next_run == 0) {
        continue;
    }
    $timerCount++;
    $delay = $next_run - $now;
    if ($delay < 60) {
        $timer1MinCount++;
    } elseif ($delay < 300) {
        $timer5MinCount++;
    }
}

$instanceStatusCodes = [
    101 => 'Instanz wird erstellt',
    102 => 'Instanz ist aktiv',
    103 => 'Instanz wird gelöscht',
    104 => 'Instanz ist inaktiv',
    105 => 'Instanz wurde nicht erzeugt',
];

// Instanzen
$instanceList = IPS_GetInstanceList();
$instanceCount = count($instanceList);
$instanceError = 0;
$instanceError = 0;
foreach ($instanceList as $id) {
    $instance = IPS_GetInstance($id);
    if ($instance['InstanceStatus'] <= 105) {
        continue;
    }
    if ($instanceError == 0) {
        $errorText .= '<b>Defekte Instanzen:</b><br>' . PHP_EOL;
    }
    $instanceError++;
    $instanceStatus = $instance['InstanceStatus'];
    if (isset($instanceStatusCodes[$instanceStatus])) {
        $err = $instanceStatusCodes[$instanceStatus];
    } else {
        $err = 'Status ' . $instanceStatus;
    }
    $col = $instanceStatus >= 200 ? 'red' : 'grey';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ': ' . $err . '</span><br>' . PHP_EOL;
}

if ($instanceError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $instanceError;
}

// Scripte
$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    if (!$script['ScriptIsBroken']) {
        continue;
    }
    if ($scriptError == 0) {
        $errorText .= '<b>Defekte Skripte:</b><br>' . PHP_EOL;
    }
    $scriptError++;
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
}

if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $scriptError;
}

// Links
$linkList = IPS_GetLinkList();
$linkCount = count($linkList);
$linkError = 0;
foreach ($linkList as $id) {
    $link = IPS_GetLink($id);
    if (IPS_ObjectExists($link['TargetID'])) {
        continue;
    }
    if ($linkError == 0) {
        $errorText .= '<b>Defekte Links:</b><br>' . PHP_EOL;
    }
    $linkError++;
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
}

if ($linkError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $linkError;
}

// Objekte
$objectList = IPS_GetObjectList();
$objectCount = count($objectList);
$objectError = 0;
foreach ($objectList as $id) {
    $obj = IPS_GetObject($id);
    $ok = true;
    $pid = $obj['ParentID'];
    if ($pid != 0 && !IPS_ObjectExists($pid)) {
        $ok = false;
    }
    $cids = $obj['ChildrenIDs'];
    foreach ($cids as $cid) {
        if (!IPS_ObjectExists($cid)) {
            $ok = false;
        }
    }
    if ($ok) {
        continue;
    }
    if ($objectError == 0) {
        $errorText .= '<b>Defekte Objekte:</b><br>' . PHP_EOL;
    }
    $objectError++;
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
}

if ($objectError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $objectError;
}

// Events
$eventList = IPS_GetEventList();
$eventCount = count($eventList);
$eventActive = 0;
$eventError = 0;
foreach ($eventList as $id) {
    $event = IPS_GetEvent($id);
    $active = $event['EventActive'];
    if ($active) {
        $eventActive++;
    }
    $err = 0;
    $varID = $event['TriggerVariableID'];
    if ($varID != 0 && IPS_ObjectExists($varID) == false) {
        $err++;
    }
    $eventConditions = $event['EventConditions'];
    foreach ($eventConditions as $eventCondition) {
        $variableRules = $eventCondition['VariableRules'];
        foreach ($variableRules as $variableRule) {
            $varID = $variableRule['VariableID'];
            if ($varID != 0 && IPS_ObjectExists($varID) == false) {
                $err++;
            }
        }
    }
    if ($err == 0) {
        continue;
    }
    if ($eventError == 0) {
        $errorText .= '<b>Defekte Ereignisse:</b><br>' . PHP_EOL;
    }
    $eventError++;
    $col = $active ? 'red' : 'grey';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
}

if ($eventError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $eventError;
}

// Module
$moduleList = IPS_GetModuleList();
$moduleCount = count($moduleList);

// Variablen
$varList = IPS_GetVariableList();
$varCount = count($varList);

$html = '';
$html .= '<head>' . PHP_EOL;
$html .= '<style>' . PHP_EOL;
$html .= 'body { margin: 1; padding: 0; font-family: "Open Sans", sans-serif; font-size: 20px; }' . PHP_EOL;
$html .= 'table { border-collapse: collapse; border: 0px solid; margin: 0.5em;}' . PHP_EOL;
$html .= 'th, td { padding: 1; }' . PHP_EOL;
$html .= 'thead, tdata { text-align: left; }' . PHP_EOL;
$html .= '#spalte_title { width: 160px; }' . PHP_EOL;
$html .= '#spalte_value { }' . PHP_EOL;
$html .= '</style>' . PHP_EOL;
$html .= '</head>' . PHP_EOL;
$html .= '<body>' . PHP_EOL;
$html .= '<table>' . PHP_EOL;
$html .= '<colgroup><col id="spalte_title"></colgroup>' . PHP_EOL;
$html .= '<colgroup><col id="spalte_value"></colgroup>' . PHP_EOL;
$html .= '<tr><td>Instanzen</td><td>' . $instanceCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Scripte</td><td>' . $scriptCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Links</td><td>' . $linkCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Objekte</td><td>' . $objectCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Ereignisse</td><td>' . $eventCount . ' (aktiv=' . $eventActive . ')</td></tr>' . PHP_EOL;
$html .= '<tr><td>Module</td><td>' . $moduleCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Variablen</td><td>' . $varCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Threads</td><td>' . $threadCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Timer</td><td>' . $timerCount . ' (1m=' . $timer1MinCount . ', 5m=' . $timer5MinCount . ')</td></tr>' . PHP_EOL;
$html .= '<tr><td>Änderungen/s</td><td>' . $tps . '</td></tr>' . PHP_EOL;
$html .= '</table>' . PHP_EOL;

if ($errorTotal > 0) {
    $html .= $errorText;
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL;
}
$html .= '</body>' . PHP_EOL;

SetValueString(<A>, $html);
SetValueInteger(<B>, $errorTotal);
SetValueInteger(<C>, $startTime);

Das Script wird zyklische aufgerufen und füllt die 3 Variablen, eine mit einer HTML-Ausgabe und eine mit Anzahl der Fehler.

demel

Danke demel,
Du hattest mich auf die richtige Spur geleitet. Ich habe so ein ähnliches Script einmal am Tag laufen:

<?php
error_reporting(E_ERROR | E_PARSE | E_NOTICE);

$ignore = array( 48618, 
                 16529
               );

$count = 0;
$mailInhalt = 'Script Check'. PHP_EOL. PHP_EOL;

$mailInhalt = 'Defekte Instanzen:' . PHP_EOL;

$ids = IPS_GetInstanceList();
foreach ($ids as $id){
    $key = array_search($id, $ignore);
    if ( is_bool($key)){
        $instance = IPS_GetInstance($id);
        if ($instance['InstanceStatus'] > 104) {
            $mailInhalt .= '#'.$id.': '.IPS_GetLocation($id).': '.$instance['InstanceStatus']. PHP_EOL;
            $count++;
        }
    }
}


// Defekte Events
$mailInhalt .= PHP_EOL . 'Defekte Events:' . PHP_EOL;
$ids = IPS_GetEventList();
foreach ($ids as $id){
    $event = IPS_GetEvent($id);
    if ($event['EventType'] == 0) {
        $variable = IPS_GetVariable($event['TriggerVariableID']);
        if ($variable == false){
            $mailInhalt .= '#'.$id.': '.IPS_GetLocation($id). PHP_EOL;
            $count++;
        }
    }
}

// Defekte Scripte
$mailInhalt .= PHP_EOL . 'Defekte Skripte:' . PHP_EOL;
$ids = IPS_GetScriptList();
foreach ($ids as $id){
    $script = IPS_GetScript($id);
    if ($script['ScriptIsBroken']){
        $count++;
        $mailInhalt .= '#'.$id.': '.IPS_GetLocation($id). PHP_EOL;
    }
}

$pfad = IPS_GetKernelDir()."scripts";
$handle=opendir ($pfad);    
while ($datei = readdir ($handle)) {
    if(strpos($datei,".ips.php")!==false) {
        $datei =explode(".",$datei);
        $files[]=$datei[0];  
    }
}
closedir($handle);

// überlüssige Scripte
$mailInhalt .= PHP_EOL . 'überflüssige  Skripte:' . PHP_EOL;
$mailInhalt .= "Anzahl der Files mit *.ips.php  : ". count($files). PHP_EOL;
$mailInhalt .= "Anzahl der Scripte in IPSymcon      : ". count($ids) . PHP_EOL;

foreach($files as $file){
    if ( is_numeric($file) ){
        $key = array_search($file, $ids);
        if ( $key === false ){
            $count++;
            $mailInhalt .= $file.".ips.php Fehler". PHP_EOL;
        }
    }
}

if ($count > 0){
    $mailBetreff =  "IPS Scripte"; //Betreff der E-Mail
    SMTP_SendMail(33517, $mailBetreff, $mailInhalt);
//    echo $mailInhalt;
}
?>

ich lasse mir aber eine Mail schicken damit ich schnell Bescheid weiß.

Ich lasse dein Script auch mal laufen muss es aber leicht ändern da „$snapshot = json_decode($udata, true);“ folgenden Fehler lieferte:„Allowed memory size of 33554432 bytes exhausted“. Ich habe auch meine IgnoreList hinzugefügt da ich Geräte habe die aktuell nicht im Betrieb sind und immer Fehler liefern würden.

Ralf

Ich bekome da eine Fehlermeldung
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4096 bytes) in /mnt/data/symcon/scripts/43920.ips.php

Irgendeine Idee ob und wie man diesen Fehler umgehen kann?
Anscheinend ist bei mir die Ausgabe von

$sdata = IPS_GetSnapshot();
$udata = utf8_encode($sdata);

zu groß.

Ich glaube nicht, das es eine Möglichkeit gibt, das grundsätzlich zu reduzieren. Der Snapshot ist die Menge der Änderungen.

Was man machen könnte wäre

  1. sich den Timestamp der letzten Änderung einer der Variablen zu ermitteln
  2. IPS_GetSnapshot() dann diesen Wert übergeben, dann umfasst der Snapshot nur die Änderungen seit diesem Zeitpunkt. Damit beziehen sich die Änderungen nur auf den Zeitraum seit der letzen Aklualisierung.

demel

Hi,
Änderungen von was? Ich finde gar keine Doku zu PS_GetSnapshot() .

Eine ähnliche Frage kam schon mal auf und es wurde IPS_GetOptionList empfohlen war damals aber undokumentiert.

Ralf

Hallo,

IPS_GetSnapshit() ist eine interne Funktion. daher wir sie nicht dokumentiert.
Wenn du dir den Output im Detail anschauen willst, kannst Du https://github.com/demel42/IPSymconSyslog.git an.
Das ist eigentlich die komplette interne Kommunikation von IPS.

demel

Du musst php mehr Speicher zuordnen. Das geht in der php.ini (danach Symcon neustarten) oder je nach Konfiguration auch für das eine Script mit ini_set(…). Genaueres in der PHP Doku.

Die Funktion heißt IPS_GetSnapshot(), nicht mit i :wink:

1 „Gefällt mir“

hier wird auch alles entdeckt :wink: :smiley:

Hi,
aus gegebenen Anlasss (fehlende Profile) habe ich dein Script mal erweitert um einen Check ob alle benutzten Profile auch da sind:

error_reporting(E_ERROR | E_PARSE | E_NOTICE);
// Variablen
$varList = IPS_GetVariableList();
$varCount = count($varList);
$varError = 0;
foreach ($varList as $id) {
    $err = 0;
    $variable = IPS_GetVariable($id);
    $Varprofile = $variable['VariableProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err++;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err++;
        }
    }
    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Profile:</b><br>' . PHP_EOL;
    }
    $varError++;
    $col = $active ? 'red' : 'grey';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' entweder "' . $variable['VariableProfile'] . '" oder "' . $variable['VariableCustomProfile'] . '" fehlen ' . '</span><br>' . PHP_EOL;
}

if ($varError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $varError;
}


Ralf

Hi demel,
ich habe dein Script noch weiter erweitert. Jetzt prüfe ich auch ob alle Aktion-Scripte vorhanden sind, ob es überflüssige Scripte gibt und ob es fehlende Scripte gibt. Neben HTML erzeuge ich jetzt auch einen einfachen Text um ihn mir per Mail zu svhicken.

So sieht der umfangreichere Script jetzt aus:

<?php
declare(strict_types=1);
error_reporting(E_ERROR | E_PARSE | E_NOTICE);

// Array mit IDs von Instanzen füllen die ignoriert werden sollen, z.B. weil die Batterie entfernt wurde.
$ignore = array( 0 ) ;

//$ignore = array( 48618, 
//                 16529,
//                 57977
//               );

// Variable A: Typ String, Profil ~HTML-Box
// Variable B: Typ  Integer
// Variable C: Typ  Integer, Profil ~UnixTimestamp

$startTime = IPS_GetKernelStartTime();

$errorText = '';
$mailText = '';
$errorTotal = 0;

// Transactions
$now = time();

// Threads
$threadList = IPS_GetScriptThreadList();
$threadCount = 0;
foreach ($threadList as $t => $i) {
    $thread = IPS_GetScriptThread($i);
    $ScriptID = $thread['ScriptID'];
    if ($ScriptID != 0) {
        $threadCount++;
    }
}

// Timer
$timerCount = 0;
$timer1MinCount = 0;
$timer5MinCount = 0;
$timerList = IPS_GetTimerList();
foreach ($timerList as $t) {
    $timer = IPS_GetTimer($t);
    $next_run = $timer['NextRun'];
    if ($next_run == 0) {
        continue;
    }
    $timerCount++;
    $delay = $next_run - $now;
    if ($delay < 60) {
        $timer1MinCount++;
    } elseif ($delay < 300) {
        $timer5MinCount++;
    }
}

$instanceStatusCodes = [
    101 => 'Instanz wird erstellt',
    102 => 'Instanz ist aktiv',
    103 => 'Instanz wird gelöscht',
    104 => 'Instanz ist inaktiv',
    105 => 'Instanz wurde nicht erzeugt',
];

// Instanzen
$instanceList = IPS_GetInstanceList();
$instanceCount = count($instanceList);
$instanceError = 0;
$instanceError = 0;
foreach ($instanceList as $id) {
    $key = array_search($id, $ignore);
    if (is_bool($key)){
        $instance = IPS_GetInstance($id);
        if ($instance['InstanceStatus'] <= 104) {
            continue;
        }
        if ($instanceError == 0) {
            $errorText .= '<b>Defekte Instanzen:</b><br>' . PHP_EOL;
            $mailText .= 'Defekte Instanzen:' . PHP_EOL;
        }
        $instanceError++;
        $instanceStatus = $instance['InstanceStatus'];
        if (isset($instanceStatusCodes[$instanceStatus])) {
            $err = $instanceStatusCodes[$instanceStatus];

        } else {
            $err = 'Status ' . $instanceStatus;
        }
        $col = $instanceStatus >= 200 ? 'red' : 'grey';
        $loc = IPS_GetLocation($id);
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ': ' . $err . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . ': ' . $err . PHP_EOL;
    }
}

if ($instanceError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $instanceError;
}

$pfad = IPS_GetKernelDir()."scripts";
$handle=opendir ($pfad);    
while ($datei = readdir ($handle)) {
    if(strpos($datei,".ips.php")!==false) {
        $datei =explode(".",$datei);
        $files[]=$datei[0];  
    }
}
closedir($handle);

// Scripte
$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    if (!$script['ScriptIsBroken']) {
        continue;
    }
    if ($scriptError == 0) {
        $errorText .= '<b>Defekte Skripte:</b><br>' . PHP_EOL;
        $mailText .= 'Defekte Skripte:' . PHP_EOL;
    }
    $scriptError++;
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . PHP_EOL;
}

if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $scriptError;
}

// überlüssige Scripte
$scriptError = 0;
foreach($files as $file){
    if ( is_numeric($file) ){
        $key = array_search($file, $scriptList);
        if ( $key === false ){
            if ($scriptError == 0) {
                $errorText .= '<b>überflüssige Skripte:</b><br>' . PHP_EOL;
                $mailText .= 'überflüssige Skripte:' . PHP_EOL;
            }
            $scriptError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $file.'.ips.php wird nicht gebraucht</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $file.'.ips.php wird nicht gebraucht' . PHP_EOL;
        }
    }
}
if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $scriptError;
}

// fehlende Scripte
$scriptError = 0;
foreach($scriptList as $id){
    $key = array_search($id, $files);
    if ( $key === false ){
            if ($scriptError == 0) {
                $errorText .= '<b>fehlende Skripte:</b><br>' . PHP_EOL;
                $mailText .= 'fehlende Skripte:' . PHP_EOL;
            }
            $scriptError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id.'.ips.php fehlt</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $id.'.ips.php fehlt' . PHP_EOL;
    }
}
if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $scriptError;
}

// Links
$linkList = IPS_GetLinkList();
$linkCount = count($linkList);
$linkError = 0;
foreach ($linkList as $id) {
    $link = IPS_GetLink($id);
    if (IPS_ObjectExists($link['TargetID'])) {
        continue;
    }
    if ($linkError == 0) {
        $errorText .= '<b>Defekte Links:</b><br>' . PHP_EOL;
        $mailText .= 'Defekte Links:' . PHP_EOL;
    }
    $linkError++;
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $loc . PHP_EOL;
}

if ($linkError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $linkError;
}

// Objekte
$objectList = IPS_GetObjectList();
$objectCount = count($objectList);
$objectError = 0;
foreach ($objectList as $id) {
    $obj = IPS_GetObject($id);
    $ok = true;
    $pid = $obj['ParentID'];
    if ($pid != 0 && !IPS_ObjectExists($pid)) {
        $ok = false;
    }
    $cids = $obj['ChildrenIDs'];
    foreach ($cids as $cid) {
        if (!IPS_ObjectExists($cid)) {
            $ok = false;
        }
    }
    if ($ok) {
        continue;
    }
    if ($objectError == 0) {
        $errorText .= '<b>Defekte Objekte:</b><br>' . PHP_EOL;
        $mailText .= 'Defekte Objekte:' . PHP_EOL;
    }
    $objectError++;
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $loc . PHP_EOL;
}

if ($objectError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $objectError;
}

// Events
$eventList = IPS_GetEventList();
$eventCount = count($eventList);
$eventActive = 0;
$eventError = 0;
foreach ($eventList as $id) {
    $event = IPS_GetEvent($id);
    $active = $event['EventActive'];
    if ($active) {
        $eventActive++;
    }
    $err = 0;
    $varID = $event['TriggerVariableID'];
    if ($varID != 0 && IPS_ObjectExists($varID) == false) {
        $err++;
    }
    $eventConditions = $event['EventConditions'];
    foreach ($eventConditions as $eventCondition) {
        $variableRules = $eventCondition['VariableRules'];
        foreach ($variableRules as $variableRule) {
            $varID = $variableRule['VariableID'];
            if ($varID != 0 && IPS_ObjectExists($varID) == false) {
                $err++;
            }
        }
    }
    if ($err == 0) {
        continue;
    }
    if ($eventError == 0) {
        $errorText .= '<b>Defekte Ereignisse:</b><br>' . PHP_EOL;
        $mailText .= 'Defekte Ereignisse:' . PHP_EOL;
    }
    $eventError++;
    $col = $active ? 'red' : 'grey';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $loc .PHP_EOL;
}

if ($eventError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $eventError;
}

// Module
$moduleList = IPS_GetModuleList();
$moduleCount = count($moduleList);

// Variablen
$varList = IPS_GetVariableList();
$varCount = count($varList);
$varError = 0;
foreach ($varList as $id) {
    $err = 0;
    $variable = IPS_GetVariable($id);
    $Varprofile = $variable['VariableProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err++;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err++;
        }
    }
    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Profile:</b><br>' . PHP_EOL;
        $mailText .= 'Fehlende Profile:' . PHP_EOL;
    }
    $varError++;
    $col = $active ? 'red' : 'grey';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' entweder "' . $variable['VariableProfile'] . '" oder "' . $variable['VariableCustomProfile'] . '" fehlen ' . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $loc . ' entweder "' . $variable['VariableProfile'] . '" oder "' . $variable['VariableCustomProfile'] . '" fehlen ' . PHP_EOL;
}

if ($varError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $varError;
}

// VariableAction
$varError = 0;
foreach ($varList as $id) {
    $err = 0;
    $variable = IPS_GetVariable($id);
    $VarAction = $variable['VariableAction'];
    if ($VarAction > 1){
        $script = IPS_GetScript($VarAction);
        $instanz = IPS_GetInstance($VarAction);
//    var_dump($VarAction);
//    var_dump($script);
//    var_dump($instanz);
        if (($script == false) && ($instanz == false)){
            $err++;
        }
    }
    
    $VarAction = $variable['VariableCustomAction'];
    if ($VarAction > 1){
        $script = IPS_GetScript($VarAction);
        $instanz = IPS_GetInstance($VarAction);
        if (($script == false) && ($instanz == false)){
            $err++;
        }
    }

    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Aktions-Scripte:</b><br>' . PHP_EOL;
        $mailText .= 'Fehlende Aktions-Scripte:' . PHP_EOL;
    }
    $varError++;
    $col = $active ? 'red' : 'grey';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' entweder "' . $variable['VariableAction'] . '" oder "' . $variable['VariableCustomAction'] . '" fehlen ' . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $loc . ' entweder "' . $variable['VariableAction'] . '" oder "' . $variable['VariableCustomAction'] . '" fehlen ' . PHP_EOL;
}

if ($varError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $varError;
}

$html = '';
$html .= '<head>' . PHP_EOL;
$html .= '<style>' . PHP_EOL;
$html .= 'body { margin: 1; padding: 0; font-family: "Open Sans", sans-serif; font-size: 20px; }' . PHP_EOL;
$html .= 'table { border-collapse: collapse; border: 0px solid; margin: 0.5em;}' . PHP_EOL;
$html .= 'th, td { padding: 1; }' . PHP_EOL;
$html .= 'thead, tdata { text-align: left; }' . PHP_EOL;
$html .= '#spalte_title { width: 160px; }' . PHP_EOL;
$html .= '#spalte_value { }' . PHP_EOL;
$html .= '</style>' . PHP_EOL;
$html .= '</head>' . PHP_EOL;
$html .= '<body>' . PHP_EOL;
$html .= '<table>' . PHP_EOL;
$html .= '<colgroup><col id="spalte_title"></colgroup>' . PHP_EOL;
$html .= '<colgroup><col id="spalte_value"></colgroup>' . PHP_EOL;
$html .= '<tr><td>Instanzen</td><td>' . $instanceCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Scripte</td><td>' . $scriptCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Links</td><td>' . $linkCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Objekte</td><td>' . $objectCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Ereignisse</td><td>' . $eventCount . ' (aktiv=' . $eventActive . ')</td></tr>' . PHP_EOL;
$html .= '<tr><td>Module</td><td>' . $moduleCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Variablen</td><td>' . $varCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Threads</td><td>' . $threadCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Timer</td><td>' . $timerCount . ' (1m=' . $timer1MinCount . ', 5m=' . $timer5MinCount . ')</td></tr>' . PHP_EOL;
$html .= '</table>' . PHP_EOL;

if ($errorTotal > 0) {
    $html .= $errorText. '</body>' . PHP_EOL;
// vereinfachten Fehlertext als Mail verschiecken
    $mailBetreff =  "IPS Check"; //Betreff der E-Mail
    SMTP_SendMail(33517, $mailBetreff, $mailText);
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL . '</body>' . PHP_EOL;
}

SetValueString(29692, $html);
SetValueInteger(11096, $errorTotal);
SetValueInteger(15191, $startTime);
?>

Gibt es noch etwas was man checken könnte?

Ralf

hi,

bin leider erst jetzt dazu gekommen, deinen post zu lesen

prima, werde ich auch bei mir integrieren.

Eventuell Mediendaten?

demel

Hi,
et voila:-)

$pfad = IPS_GetKernelDir()."media";
$handle=opendir ($pfad);    
while ($datei = readdir ($handle)) {
    $MediaFiles[] = "media/".$datei;  
}
closedir($handle);

// Medien
$mediaList = IPS_GetMediaList();
$mediaCount = count($mediaList);
$mediaError = 0;
foreach ($mediaList as $id) {
    $Media = IPS_GetMedia($id);
    if ($Media['MediaType'] == 3){
        continue;
    }
    $key = array_search($Media['MediaFile'], $MediaFiles);
    if ($key == true) {
        continue;
    }
    if ($mediaError == 0) {
        $errorText .= '<b>Defekte Mediendatei:</b><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
    }
    $mediaError++;
    $col = 'red';
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
}

if ($mediaError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $mediaError;
}

Stream habe ich ausgeklammert weil es das Objekt vielleicht nur gibt wenn der Stream aktiv ist. Meine 4 Kameras hatten auf jeden Fall einen Fehler geliefert.

Ralf

Anmerkung zu den Media Files.
Wenn der MediaCache aktiv ist, von einem Media Objekt, gibt es auch keine Datei auf dem Dateisystem.
Erst nach einem Beenden des Dienstes wird die Datei erzeugt.
Außerdem kann es auch Media Objekte geben, wo die Datei nicht im Media Unterverzeichnis liegt.
Eventuell wäre hier eine direkte Prüfung ob die Datei existiert sinnvoller.
Michael

Moin Michael,

wie meinen?

Ich habe ein neues Media-File mit mit der Web-Console erzeugt und die Datei war sofort im Verzeichnis. Sie wurde wohl automatisch auch gecached denn ich hatte zuerst ’ MediaIsAvailable’ benutzt bin da aber eben über den Cache gestolpert. Ich hatte ein Bild das ich vorher als Media erstellt hatte im Verzeichnis gelöscht und ‚MediaIsAvailable‘ lieferte immer noch true.

Jetzt prüfe ich doch mit

$key = array_search($Media['MediaFile'], $MediaFiles);

ob es die Datei gibt.

Ralf

Und wenn es aber per Script passiert?
Hier liegt dann erstmal keine Datei:

            $CoverID = IPS_CreateMedia(1);
            IPS_SetParent($CoverID, $this->InstanceID);
            IPS_SetIdent($CoverID, 'CoverIMG');
            IPS_SetName($CoverID, 'Cover');
            IPS_SetPosition($CoverID, 27);
            IPS_SetMediaCached($CoverID, true);
            $filename = 'media' . DIRECTORY_SEPARATOR . 'Cover_test.png';
            IPS_SetMediaFile($CoverID, $filename, false);

Und wer sagt das die Datei unter Media liegen muss?
Die Doku nimmt hier als Beispiel

C:\Bilder\Alarmsymbol.png
IPS_SetMediaFile — IP-Symcon :: Automatisierungssoftware

Darum mein Vorschlag für jedes Media-Objekt einzeln mit file_exists zu prüfen ob die Datei vorhanden ist.
Michael

Hi Michael,

nu hab ich verstanden. Medien-Dateien waren ein wenig neu für mich. Ich habe sie zwar benutzt aber nicht so intensiv.

Ich habe es jetzt mal korrigiert. Mediendateien überprüfen:

// Medien
$pfad = IPS_GetKernelDir();
$mediaList = IPS_GetMediaList();
$mediaCount = count($mediaList);
$mediaError = 0;
foreach ($mediaList as $id) {
    $Media = IPS_GetMedia($id);
    if ($Media['MediaType'] == 3){
        continue;
    }

    if (file_exists($pfad.$Media['MediaFile'])){
        continue;
    }
    if ($mediaError == 0) {
        $errorText .= '<b>Defekte Mediendatei:</b><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
    }
    $mediaError++;
    $col = 'red';
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . '</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
}

if ($mediaError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $mediaError;
}

Ralf

Ich bekomme ein Bild angezeigt:

Defekte Mediendatei:
#24448: media/24448.jpg

allerdings existiert die Datei und ich kann sie in der ProKonsole mit DOppelklick öffen.
Sie ist Teil des BildArchiv Moduls, die anderen 4 Bilder werden korrekt erkannt und ich sehe nicht auffälliges.