Status von Events abfragen

Des weitern kann es auch ips.php Dateien geben welche nur per include / require eingebunden werden und gar nicht als Objekt in IPS angelegt sind.
Ich glaube da einen Abgleich in beide Richtungen zu machen hat noch einige Herausforderungen.
Michael

Hi Heiko,
stimmt. Bisher nie gesehen/angeschaut.

@Michael,
oder IPS_RunScript(12345) in einem Script wobei 12345 fehlt. Das passiert mir öfter und weil es keinen Fehler bzw. defekt im Script hervorruft merke ich es nicht immer.

PS: Script in #31 aktualisiert.

Ralf

Hi,
ich überwache und zähle in meinem Script jetzt auch Alexa Kommandos, Variablen, Scripte. Anbei aktuelle Version:

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

$SMTP = 33517;          // SMTP Instanz falls Mail erwünscht
$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

// 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;
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 . ' : ' . $script["ScriptFile"].'</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){
    $key1 = array_search($id, $files);
    $script = IPS_GetScript($id);
    $datei = $script["ScriptFile"];
    if(strpos($datei,".ips.php")!==false) {
        $datei =explode(".",$datei);
    }
    $key2 = array_search($datei[0], $files);
    if (( $key1 === false ) && ( $key2 === 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 . ' : ' . $script["ScriptFile"].' fehlt</span><br>' . PHP_EOL;
            $mailText .= '#' . $id . ' : ' . $script["ScriptFile"].' 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 += 1;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err += 2;
        }
    }
    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);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] . '" fehlt ' . 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);
        if (($script == false) && ($instanz == false)){
            $err += 1;
        }
    }
    
    $VarAction = $variable['VariableCustomAction'];
    if ($VarAction > 1){
        $script = IPS_GetScript($VarAction);
        $instanz = IPS_GetInstance($VarAction);
        if (($script == false) && ($instanz == false)){
            $err += 2;
        }
    }

    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);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableAction'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableAction'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomAction'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomAction'] . '" fehlt ' . PHP_EOL;
    }
}

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

$id_alexa = 0;
$ids = IPS_GetInstanceListByModuleID('{CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}');
if (count($ids) > 0) {
    $id_alexa = $ids[0];
    $alexalist = [];
    $properties = json_decode(IPS_GetConfiguration($id_alexa), true);
    foreach($properties as $name => $value) {
        if (substr($name, 0, 6) == "Device") {
            $devices = json_decode($value, true);
            foreach($devices as $device) {
                switch ($name){
                    case 'DeviceSimpleScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerSimpleID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceDeactivatableScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerDeactivatableActivateID"],
                            "ID2" => $device["SceneControllerDeactivatableDeactivateID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightDimmer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["BrightnessControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightExpert':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["BrightnessOnlyControllerID"],
                            "ID3" => $device["ColorOnlyControllerID"],
                            "ID4" => $device["ColorTemperatureOnlyControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLock':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["LockControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceShutter':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["RangeControllerShutterID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeaker':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTemperatureSensor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["TemperatureSensorID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSlider':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PercentageControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightColor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ColorControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceMediaPlayer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["SpeakerMuteableVolumeID"],
                            "ID3" => $device["SpeakerMuteableMuteID"],
                            "ID4" => $device["PlaybackControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeakerMuteable':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerMuteableVolumeID"],
                            "ID2" => $device["SpeakerMuteableMuteID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTelevision':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["ChannelControllerID"],
                            "ID3" => $device["SpeakerMuteableVolumeID"],
                            "ID4" => $device["SpeakerMuteableMuteID"],
                            "ID5" => $device["InputControllerID"]
                        ];
                        break;
                    case 'DeviceThermostat':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ThermostatControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                default:
                            var_dump($name);
                            var_dump($device);
                        break;
                }
            }
        }
    }
    $alexaCount = count($alexalist);
    $alexaError = 0;
    foreach($alexalist as $item) {
        $errorIDs = 0;
        if (($item['ID1'] > 0) && (IPS_ObjectExists($item['ID1']) == false)){
            $errorIDs |= 1;
        }
        if (($item['ID2'] > 0) && (IPS_ObjectExists($item['ID2']) == false)){
            $errorIDs |= 2;
        }
        if (($item['ID3'] > 0) && (IPS_ObjectExists($item['ID3']) == false)){
            $errorIDs |= 4;
        }
        if (($item['ID4'] > 0) && (IPS_ObjectExists($item['ID4']) == false)){
            $errorIDs |= 8;
        }
        if (($item['ID5'] > 0) && (IPS_ObjectExists($item['ID5']) == false)){
            $errorIDs |= 16;
        }
        if (($errorIDs > 0) && ($alexaError == 0)) {
            $errorText .= '<b>Alexa IDs nicht vorhanden:</b><br>' . PHP_EOL;
            $col = 'red';
            $mailText .= 'Fehlende Alexa IDs:' . PHP_EOL;
        }
        if ($errorIDs & 1){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID1'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID1'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 2){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID2'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID2'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 4){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID3'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID3'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 8){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID4'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID4'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 16){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID5'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID5'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}

// 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>Mediendatei:</b><br>' . PHP_EOL;
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">nicht vorhanden / </span>' . PHP_EOL;
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">gecached nicht gespeichert</span><br><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
    }
    $mediaError++;
    if (($Media['MediaIsCached']) && ($Media['MediaIsAvailable'])){
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' noch nicht gespeichert</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
    else{
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' nicht vorhanden</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
}

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

$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>Mediendatei:</b><br>' . PHP_EOL;
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">nicht vorhanden / </span>' . PHP_EOL;
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">gecached nicht gespeichert</span><br><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
    }
    $mediaError++;
    if (($Media['MediaIsCached']) && ($Media['MediaIsAvailable'])){
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' noch nicht gespeichert</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
    else{
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' nicht vorhanden</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
}


$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: 220px; }' . 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>Medien</td><td>' . $mediaCount . '</td></tr>' . PHP_EOL;
if ($id_alexa > 0){
    $html .= '<tr><td>Alexa Kommandos</td><td>' . $alexaCount . '</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($SMTP, $mailBetreff, $mailText);
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL . '</body>' . PHP_EOL;
}

$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

SetValueString($htmlString, $html);
SetValueInteger($checkErrorCount, $errorTotal);
SetValueInteger($kernelStart, $startTime);
?>

Ralf

Hallo,

whow, das Script wird ja immer umfangreicher …

Nur kleiner Idee: ist es nicht besser, die Alexa-Instanz anhand der GUID (Alexa = {CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}) zu suchen?

        $ids = IPS_GetInstanceListByModuleID('{CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}');
        if (count($ids) > 0) {
           $id_alexa = $ids[0];
....

ich glaube das war, weil (theoretisch) sich der Name ändern könnte …

gruß
demel

Moin,
ich bin halt ein kleiner Kontrollfreak:-)

Ich wollte auch erst nach der GUID suchen hatte aber keine Lust zu suchen.

p.s. ich ändere es oben.

Edit: Was mir jetzt noch fehlen würde wäre eine Möglichkeit die Scripte zu durchsuchen ob es ein SetValue, GetValue, RunScript usw. mit eine undefinierten Objekt gibt. Da Geduld nicht zu meinen Stärken gehört benutze ich auch schon mal das unsichere löschen, was natürlich (m)ein Fehler ist.

Ralf

<?php

declare(strict_types=1);

// Scripte
$fileListIPS = [];
$fileListSYS = [];

$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $fileListIPS[] = $script['ScriptFile'];
}

$path = IPS_GetKernelDir() . 'scripts';
$handle = opendir($path);
while ($file = readdir($handle)) {
    if (!is_file($file)) {
        continue;
    }
    if (!preg_match('/^.*\.php$/', $file)) {
        continue;
    }
    if (preg_match('/^.*\.inc\.php$/', $file)) {
        continue;
    }
    $fileListSYS[] = $file;
}
closedir($handle);

// fehlende Scripte
foreach ($fileListIPS as $file) {
    if (in_array($file, $fileListSYS)) {
        continue;
    }
    echo 'fehlend: ' . $file . PHP_EOL;
}

// überflüssige Scripte
foreach ($fileListSYS as $file) {
    if (in_array($file, $fileListIPS)) {
        continue;
    }
    echo 'überflüssig: ' . $file . PHP_EOL;
}

$objIDs = IPS_GetObjectList ();
foreach ($fileListSYS as $file) {
    if (!in_array($file, $fileListIPS)) {
        continue;
    }
    $text = file_get_contents($file);
    $lines = explode("\r\n", $text);
    foreach ($lines as $line) {
        if (preg_match('/=[\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                echo $file . ': ' . print_r($r, true) . PHP_EOL;
            }
        }
        if (preg_match('/\([\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                echo $file . ': ' . print_r($r, true) . PHP_EOL;
            }
        }
    }
}

das schaut in allen scripten nach, ob da 5-stellige Zahlen sind, die es nicht als ID’s gibt.
die regulären Ausdrücke sind sicher noch optimierungswürdig.

  1. Ausdruck: ein =, dann beliebig Blank/TAB, dann eine 5 Ziffern und dann etwas, was keine Ziffer ist
  2. Ausdruck: das gleiche, aber statt = eine öffnenden Klammer (

demel

ps: die Suche nach den Skripten umfasst auch Script, die nicht dem nativen IPS-Namensschema (nnnn.ips.php) gehorchen (ich habe zB in …/scripts „HomeMatic_EasyInstall.php“ stehen und das wurde als „überflüssig“ gemeldet).

Hi,
super genau sowas braucht ich noch danke. Ich habe in diesem Jahr bei FritzBox, Logitech Harmony und Neeo einiges gemacht und so gab es 100 Stellen die durch dein Script aufgedeckt worden sind.

Ich habe den Teil gleich mal in das große Script integriert.

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

$SMTP = 33517;          // SMTP Instanz falls Mail erwünscht
$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

// 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;
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 . ' : ' . $script["ScriptFile"].'</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){
    $key1 = array_search($id, $files);
    $script = IPS_GetScript($id);
    $datei = $script["ScriptFile"];
    if(strpos($datei,".ips.php")!==false) {
        $datei =explode(".",$datei);
    }
    $key2 = array_search($datei[0], $files);
    if (( $key1 === false ) && ( $key2 === 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 . ' : ' . $script["ScriptFile"].' fehlt</span><br>' . PHP_EOL;
            $mailText .= '#' . $id . ' : ' . $script["ScriptFile"].' 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 += 1;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err += 2;
        }
    }
    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);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] . '" fehlt ' . 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);
        if (($script == false) && ($instanz == false)){
            $err += 1;
        }
    }
    
    $VarAction = $variable['VariableCustomAction'];
    if ($VarAction > 1){
        $script = IPS_GetScript($VarAction);
        $instanz = IPS_GetInstance($VarAction);
        if (($script == false) && ($instanz == false)){
            $err += 2;
        }
    }

    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);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableAction'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableAction'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomAction'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomAction'] . '" fehlt ' . PHP_EOL;
    }
}

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

$id_alexa = 0;
$ids = IPS_GetInstanceListByModuleID('{CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}');
if (count($ids) > 0) {
    $id_alexa = $ids[0];
    $alexalist = [];
    $properties = json_decode(IPS_GetConfiguration($id_alexa), true);
    foreach($properties as $name => $value) {
        if (substr($name, 0, 6) == "Device") {
            $devices = json_decode($value, true);
            foreach($devices as $device) {
                switch ($name){
                    case 'DeviceSimpleScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerSimpleID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceDeactivatableScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerDeactivatableActivateID"],
                            "ID2" => $device["SceneControllerDeactivatableDeactivateID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightDimmer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["BrightnessControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightExpert':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["BrightnessOnlyControllerID"],
                            "ID3" => $device["ColorOnlyControllerID"],
                            "ID4" => $device["ColorTemperatureOnlyControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLock':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["LockControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceShutter':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["RangeControllerShutterID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeaker':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTemperatureSensor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["TemperatureSensorID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSlider':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PercentageControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightColor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ColorControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceMediaPlayer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["SpeakerMuteableVolumeID"],
                            "ID3" => $device["SpeakerMuteableMuteID"],
                            "ID4" => $device["PlaybackControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeakerMuteable':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerMuteableVolumeID"],
                            "ID2" => $device["SpeakerMuteableMuteID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTelevision':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["ChannelControllerID"],
                            "ID3" => $device["SpeakerMuteableVolumeID"],
                            "ID4" => $device["SpeakerMuteableMuteID"],
                            "ID5" => $device["InputControllerID"]
                        ];
                        break;
                    case 'DeviceThermostat':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ThermostatControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                default:
                            var_dump($name);
                            var_dump($device);
                        break;
                }
            }
        }
    }
    $alexaCount = count($alexalist);
    $alexaError = 0;
    foreach($alexalist as $item) {
        $errorIDs = 0;
        if (($item['ID1'] > 0) && (IPS_ObjectExists($item['ID1']) == false)){
            $errorIDs |= 1;
        }
        if (($item['ID2'] > 0) && (IPS_ObjectExists($item['ID2']) == false)){
            $errorIDs |= 2;
        }
        if (($item['ID3'] > 0) && (IPS_ObjectExists($item['ID3']) == false)){
            $errorIDs |= 4;
        }
        if (($item['ID4'] > 0) && (IPS_ObjectExists($item['ID4']) == false)){
            $errorIDs |= 8;
        }
        if (($item['ID5'] > 0) && (IPS_ObjectExists($item['ID5']) == false)){
            $errorIDs |= 16;
        }
        if (($errorIDs > 0) && ($alexaError == 0)) {
            $errorText .= '<b>Alexa IDs nicht vorhanden:</b><br>' . PHP_EOL;
            $col = 'red';
            $mailText .= 'Fehlende Alexa IDs:' . PHP_EOL;
        }
        if ($errorIDs & 1){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID1'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID1'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 2){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID2'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID2'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 4){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID3'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID3'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 8){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID4'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID4'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 16){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID5'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID5'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}

// 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>Mediendatei:</b><br>' . PHP_EOL;
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">nicht vorhanden / </span>' . PHP_EOL;
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">gecached nicht gespeichert</span><br><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
    }
    $mediaError++;
    if (($Media['MediaIsCached']) && ($Media['MediaIsAvailable'])){
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' noch nicht gespeichert</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
    else{
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' nicht vorhanden</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
}

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

// Scripte
$scriptCount = 0;
$scriptError = 0;
$fileListIPS = [];
$fileListSYS = [];
$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $fileListIPS[] = $script['ScriptFile'];
}

$path = IPS_GetKernelDir() . 'scripts';
$handle = opendir($path);
while ($file = readdir($handle)) {
    if (!is_file($file)) {
        continue;
    }
    if (!preg_match('/^.*\.php$/', $file)) {
        continue;
    }
    if (preg_match('/^.*\.inc\.php$/', $file)) {
        continue;
    }
    $fileListSYS[] = $file;
}
closedir($handle);

$objIDs = IPS_GetObjectList ();
foreach ($fileListSYS as $file) {
    if (!in_array($file, $fileListIPS)) {
        continue;
    }
    $text = file_get_contents($file);
    $lines = explode("\r\n", $text);
    foreach ($lines as $line) {
        if (preg_match('/=[\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
                }
                $scriptError++;
                $col = 'red';
                $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
                $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
        if (preg_match('/\([\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
                }
                $scriptError++;
                $col = 'red';
                $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
                $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
    }
}
if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $scriptError;
}

$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: 220px; }' . 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>Medien</td><td>' . $mediaCount . '</td></tr>' . PHP_EOL;
if ($id_alexa > 0){
    $html .= '<tr><td>Alexa Kommandos</td><td>' . $alexaCount . '</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($SMTP, $mailBetreff, $mailText);
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL . '</body>' . PHP_EOL;
}

$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

SetValueString($htmlString, $html);
SetValueInteger($checkErrorCount, $errorTotal);
SetValueInteger($kernelStart, $startTime);
?>

Deinen Teil mit fehlenden/überflüssigen Scripten habe ich noch nicht ganz verstanden und es erstmal bei meiner einfachen Methode belasse.

Nächste Frage: Wie bekomme ich eine Liste der WebHooks?

Ralf

Hi,
vergesst die Frage nach WebHooks. Ist genauso einfach wie Alexa:-)

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

$SMTP = 33517;          // SMTP Instanz falls Mail erwünscht
$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

// 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;
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 . ' : ' . $script["ScriptFile"].'</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){
    $key1 = array_search($id, $files);
    $script = IPS_GetScript($id);
    $datei = $script["ScriptFile"];
    if(strpos($datei,".ips.php")!==false) {
        $datei =explode(".",$datei);
    }
    $key2 = array_search($datei[0], $files);
    if (( $key1 === false ) && ( $key2 === 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 . ' : ' . $script["ScriptFile"].' fehlt</span><br>' . PHP_EOL;
            $mailText .= '#' . $id . ' : ' . $script["ScriptFile"].' 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 += 1;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err += 2;
        }
    }
    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);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] . '" fehlt ' . 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);
        if (($script == false) && ($instanz == false)){
            $err += 1;
        }
    }
    
    $VarAction = $variable['VariableCustomAction'];
    if ($VarAction > 1){
        $script = IPS_GetScript($VarAction);
        $instanz = IPS_GetInstance($VarAction);
        if (($script == false) && ($instanz == false)){
            $err += 2;
        }
    }

    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);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableAction'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableAction'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomAction'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomAction'] . '" fehlt ' . PHP_EOL;
    }
}

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

// Alexa
$id_alexa = 0;
$ids = IPS_GetInstanceListByModuleID('{CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}');
if (count($ids) > 0) {
    $id_alexa = $ids[0];
    $alexalist = [];
    $properties = json_decode(IPS_GetConfiguration($id_alexa), true);
//    var_dump($properties);

    foreach($properties as $name => $value) {
        if (substr($name, 0, 6) == "Device") {
            $devices = json_decode($value, true);
            foreach($devices as $device) {
                switch ($name){
                    case 'DeviceSimpleScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerSimpleID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceDeactivatableScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerDeactivatableActivateID"],
                            "ID2" => $device["SceneControllerDeactivatableDeactivateID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightDimmer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["BrightnessControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightExpert':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["BrightnessOnlyControllerID"],
                            "ID3" => $device["ColorOnlyControllerID"],
                            "ID4" => $device["ColorTemperatureOnlyControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLock':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["LockControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceShutter':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["RangeControllerShutterID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeaker':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTemperatureSensor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["TemperatureSensorID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSlider':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PercentageControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightColor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ColorControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceMediaPlayer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["SpeakerMuteableVolumeID"],
                            "ID3" => $device["SpeakerMuteableMuteID"],
                            "ID4" => $device["PlaybackControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeakerMuteable':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerMuteableVolumeID"],
                            "ID2" => $device["SpeakerMuteableMuteID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTelevision':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["ChannelControllerID"],
                            "ID3" => $device["SpeakerMuteableVolumeID"],
                            "ID4" => $device["SpeakerMuteableMuteID"],
                            "ID5" => $device["InputControllerID"]
                        ];
                        break;
                    case 'DeviceThermostat':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ThermostatControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                default:
                            var_dump($name);
                            var_dump($device);
                        break;
                }
            }
        }
    }
    $alexaCount = count($alexalist);
    $alexaError = 0;
    foreach($alexalist as $item) {
        $errorIDs = 0;
        if (($item['ID1'] > 0) && (IPS_ObjectExists($item['ID1']) == false)){
            $errorIDs |= 1;
        }
        if (($item['ID2'] > 0) && (IPS_ObjectExists($item['ID2']) == false)){
            $errorIDs |= 2;
        }
        if (($item['ID3'] > 0) && (IPS_ObjectExists($item['ID3']) == false)){
            $errorIDs |= 4;
        }
        if (($item['ID4'] > 0) && (IPS_ObjectExists($item['ID4']) == false)){
            $errorIDs |= 8;
        }
        if (($item['ID5'] > 0) && (IPS_ObjectExists($item['ID5']) == false)){
            $errorIDs |= 16;
        }
        if (($errorIDs > 0) && ($alexaError == 0)) {
            $errorText .= '<b>Alexa IDs nicht vorhanden:</b><br>' . PHP_EOL;
            $col = 'red';
            $mailText .= 'Fehlende Alexa IDs:' . PHP_EOL;
        }
        if ($errorIDs & 1){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID1'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID1'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 2){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID2'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID2'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 4){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID3'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID3'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 8){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID4'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID4'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 16){
            $alexaError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID5'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID5'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}

// Hooks
$ids = IPS_GetInstanceListByModuleID('{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}');
if (count($ids) > 0) {
    $id_webhook = $ids[0];
    $webhooklist = [];
    $properties = json_decode(IPS_GetConfiguration($id_webhook), true);
    foreach($properties as $name => $value) {
        $devices = json_decode($value, true);
        foreach($devices as $device) {
            $webhooklist[] = [
                "Name" => $device["Hook"],
                "ID" => $device["TargetID"]
            ];
        }
    }
    $hookCount = count($webhooklist);
    $hookError = 0;
    foreach($webhooklist as $item) {
        if (IPS_ObjectExists($item['ID']) == false){
            if ($hookError == 0){
                $errorText .= '<b>Hook IDs nicht vorhanden:</b><br>' . PHP_EOL;
                $mailText .= 'Fehlende Hook IDs:' . PHP_EOL;
            }
            $hookError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Hook:' . $item['Name'] . '  mit ID:' . $item['ID']   . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'Hook:' . $item['Name'] . '  mit ID:' . $item['ID'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}
if ($hookError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $hookError;
}

// 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>Mediendatei:</b><br>' . PHP_EOL;
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">nicht vorhanden / </span>' . PHP_EOL;
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">gecached nicht gespeichert</span><br><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
    }
    $mediaError++;
    if (($Media['MediaIsCached']) && ($Media['MediaIsAvailable'])){
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' noch nicht gespeichert</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
    else{
        $col = 'red';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' nicht vorhanden</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
}

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

// Scripte
$scriptCount = 0;
$scriptError = 0;
$fileListIPS = [];
$fileListSYS = [];
$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $fileListIPS[] = $script['ScriptFile'];
}

$path = IPS_GetKernelDir() . 'scripts';
$handle = opendir($path);
while ($file = readdir($handle)) {
    if (!is_file($file)) {
        continue;
    }
    if (!preg_match('/^.*\.php$/', $file)) {
        continue;
    }
    if (preg_match('/^.*\.inc\.php$/', $file)) {
        continue;
    }
    $fileListSYS[] = $file;
}
closedir($handle);

$objIDs = IPS_GetObjectList ();
foreach ($fileListSYS as $file) {
    if (!in_array($file, $fileListIPS)) {
        continue;
    }
    $text = file_get_contents($file);
    $lines = explode("\r\n", $text);
    foreach ($lines as $line) {
        if (preg_match('/=[\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
            }
            $scriptError++;
            $col = 'red';
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
        if (preg_match('/\([\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
                }
                $scriptError++;
                $col = 'red';
                $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
                $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
    }
}
if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $scriptError;
}

$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: 220px; }' . 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>Hooks</td><td>' . $hookCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Medien</td><td>' . $mediaCount . '</td></tr>' . PHP_EOL;
if ($id_alexa > 0){
    $html .= '<tr><td>Alexa Kommandos</td><td>' . $alexaCount . '</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($SMTP, $mailBetreff, $mailText);
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL . '</body>' . PHP_EOL;
}

$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

SetValueString($htmlString, $html);
SetValueInteger($checkErrorCount, $errorTotal);
SetValueInteger($kernelStart, $startTime);
?>

Ach ja WebHook hinzugefügt.

Ralf

Ich meinte damit, das deine Überprüfung auf fehlende bzw. überflüssige Scripte nur funktioniert, wenn der Scriptname nicht geändert ist, also der Dateiname das Format #####.ips.php hat. Mit meiner Implementierung funktioniert es in jedem Fall.
Das einzige, was nicht funktioniert ist eine Behandlung vom per require/include innerhalb von Scripten verwendeten Hilfs-Scripten.

demel

apropros

VariableAction ist lt Doku immer eine Instanz, VariableCustomAction immer ein Script. Von daher wäre ein IPS_ObjectExists() aus meiner Sicht besser

Hi,
das mit den Actions ist mir auch schon aufgefallen. Hab Nachsicht ich bin immer noch in der Lernphase und hoffe auf Welpenschutz:-)

Ralf

Optimierung für die Webhooks:
Es gibt nur das property Hooks, somit kann ein foreach entfallen.

Michael

Hi Michael,
kann Post leider nicht mehr editieren deswegen hier wieder das komplette Script. Action, Files und Hooks angepasst sowie überflüssige $col= entfernt.

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

$SMTP = 33517;          // SMTP Instanz falls Mail erwünscht
$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

// 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;
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);

$col = 'red';

// 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++;
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ' : ' . $script["ScriptFile"].'</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . 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++;
    $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++;
    $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++;
    $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 += 1;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err += 2;
        }
    }
    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Profile:</b><br>' . PHP_EOL;
        $mailText .= 'Fehlende Profile:' . PHP_EOL;
    }
    $varError++;
    $loc = IPS_GetLocation($id);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] . '" fehlt ' . 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){
        if (IPS_ObjectExists($VarAction) == false) {
            $err += 1;
        }
    }
    
    $VarAction = $variable['VariableCustomAction'];
    if ($VarAction > 1){
        if (IPS_ObjectExists($VarAction) == false) {
            $err += 2;
        }
    }

    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Aktions-Scripte:</b><br>' . PHP_EOL;
        $mailText .= 'Fehlende Aktions-Scripte:' . PHP_EOL;
    }
    $varError++;
    $loc = IPS_GetLocation($id);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' #' . $variable['VariableAction'] .' fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableAction'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' #' . $variable['VariableCustomAction'] .' fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . ' #' . $variable['VariableCustomAction'] . ' fehlt ' . PHP_EOL;
    }
}

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

// Alexa
$id_alexa = 0;
$ids = IPS_GetInstanceListByModuleID('{CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}');
if (count($ids) > 0) {
    $id_alexa = $ids[0];
    $alexalist = [];
    $properties = json_decode(IPS_GetConfiguration($id_alexa), true);
//    var_dump($properties);

    foreach($properties as $name => $value) {
        if (substr($name, 0, 6) == "Device") {
            $devices = json_decode($value, true);
            foreach($devices as $device) {
                switch ($name){
                    case 'DeviceSimpleScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerSimpleID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceDeactivatableScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerDeactivatableActivateID"],
                            "ID2" => $device["SceneControllerDeactivatableDeactivateID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightDimmer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["BrightnessControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightExpert':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["BrightnessOnlyControllerID"],
                            "ID3" => $device["ColorOnlyControllerID"],
                            "ID4" => $device["ColorTemperatureOnlyControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLock':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["LockControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceShutter':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["RangeControllerShutterID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeaker':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTemperatureSensor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["TemperatureSensorID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSlider':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PercentageControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightColor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ColorControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceMediaPlayer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["SpeakerMuteableVolumeID"],
                            "ID3" => $device["SpeakerMuteableMuteID"],
                            "ID4" => $device["PlaybackControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeakerMuteable':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerMuteableVolumeID"],
                            "ID2" => $device["SpeakerMuteableMuteID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTelevision':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["ChannelControllerID"],
                            "ID3" => $device["SpeakerMuteableVolumeID"],
                            "ID4" => $device["SpeakerMuteableMuteID"],
                            "ID5" => $device["InputControllerID"]
                        ];
                        break;
                    case 'DeviceThermostat':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ThermostatControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                default:
                            var_dump($name);
                            var_dump($device);
                        break;
                }
            }
        }
    }
    $alexaCount = count($alexalist);
    $alexaError = 0;
    foreach($alexalist as $item) {
        $errorIDs = 0;
        if (($item['ID1'] > 0) && (IPS_ObjectExists($item['ID1']) == false)){
            $errorIDs |= 1;
        }
        if (($item['ID2'] > 0) && (IPS_ObjectExists($item['ID2']) == false)){
            $errorIDs |= 2;
        }
        if (($item['ID3'] > 0) && (IPS_ObjectExists($item['ID3']) == false)){
            $errorIDs |= 4;
        }
        if (($item['ID4'] > 0) && (IPS_ObjectExists($item['ID4']) == false)){
            $errorIDs |= 8;
        }
        if (($item['ID5'] > 0) && (IPS_ObjectExists($item['ID5']) == false)){
            $errorIDs |= 16;
        }
        if (($errorIDs > 0) && ($alexaError == 0)) {
            $errorText .= '<b>Alexa IDs nicht vorhanden:</b><br>' . PHP_EOL;
            $mailText .= 'Fehlende Alexa IDs:' . PHP_EOL;
        }
        if ($errorIDs & 1){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID1'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID1'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 2){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID2'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID2'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 4){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID3'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID3'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 8){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID4'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID4'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 16){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID5'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID5'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}

// Hooks
$ids = IPS_GetInstanceListByModuleID('{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}');
if (count($ids) > 0) {
    $id_webhook = $ids[0];
    $webhooklist = [];
    $properties = json_decode(IPS_GetConfiguration($id_webhook), true);
    $webhooklist = json_decode(IPS_GetProperty($id_webhook, 'Hooks'), true);
    $hookCount = count($webhooklist);
    $hookError = 0;
    foreach($webhooklist as $item) {
        if (IPS_ObjectExists($item['TargetID']) == false){
            if ($hookError == 0){
                $errorText .= '<b>Hook IDs nicht vorhanden:</b><br>' . PHP_EOL;
                $mailText .= 'Fehlende Hook IDs:' . PHP_EOL;
            }
            $hookError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Hook:' . $item['Hook'] . '  mit ID:' . $item['TargetID']   . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'Hook:' . $item['Hook'] . '  mit ID:' . $item['TargetID'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}
if ($hookError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $hookError;
}

// 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>Mediendatei:</b><br>' . PHP_EOL;
        $errorText .= '<span style="color: ' . $col . ';">nicht vorhanden / </span>' . PHP_EOL;
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">gecached nicht gespeichert</span><br><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
        $col = 'red';
    }
    $mediaError++;
    if (($Media['MediaIsCached']) && ($Media['MediaIsAvailable'])){
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' noch nicht gespeichert</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
        $col = 'red';
    }
    else{
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' nicht vorhanden</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
}

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

// Scripte
$scriptCount = 0;
$scriptError = 0;
$fileListIPS = [];
$fileListSYS = [];
$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $fileListIPS[] = $script['ScriptFile'];
}

$path = IPS_GetKernelDir() . 'scripts';
$handle = opendir($path);
while ($file = readdir($handle)) {
    if (!is_file($file)) {
        continue;
    }
    if (!preg_match('/^.*\.php$/', $file)) {
        continue;
    }
    if (preg_match('/^.*\.inc\.php$/', $file)) {
        continue;
    }
    $fileListSYS[] = $file;
}
closedir($handle);

// fehlende Scripte
$scriptError = 0;
foreach ($fileListIPS as $file) {
    if (in_array($file, $fileListSYS)) {
        continue;
    }
    $script = IPS_GetScript($file);
    if ($scriptError == 0) {
        $errorText .= '<b>fehlende Skripte:</b><br>' . PHP_EOL;
        $mailText .= 'fehlende Skripte:' . PHP_EOL;
    }
    $scriptError++;
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $file . ' : ' . $script["ScriptFile"].' fehlt</span><br>' . PHP_EOL;
    $mailText .= '#' . $file . ' : ' . $script["ScriptFile"].' fehlt' . PHP_EOL;
}

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

// überflüssige Scripte
$scriptError = 0;
foreach ($fileListSYS as $file) {
    if (in_array($file, $fileListIPS)) {
        continue;
    }
    $script = IPS_GetScript($file);
    if ($scriptError == 0) {
        $errorText .= '<b>überflüssige Skripte:</b><br>' . PHP_EOL;
        $mailText .= 'überflüssige Skripte:' . PHP_EOL;
    }
    $scriptError++;
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;' . $file .' scheint überflüssig</span><br>' . PHP_EOL;
    $mailText .= $file .' scheint überflüssig' . PHP_EOL;
}

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

$scriptError = 0;
$objIDs = IPS_GetObjectList ();
foreach ($fileListSYS as $file) {
    if (!in_array($file, $fileListIPS)) {
        continue;
    }
    $text = file_get_contents($file);
    $lines = explode("\r\n", $text);
    foreach ($lines as $line) {
        if (preg_match('/=[\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
            }
            $scriptError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
        if (preg_match('/\([\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
                }
                $scriptError++;
                $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
                $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
    }
}
if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $scriptError;
}

$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: 220px; }' . 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>Hooks</td><td>' . $hookCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Medien</td><td>' . $mediaCount . '</td></tr>' . PHP_EOL;
if ($id_alexa > 0){
    $html .= '<tr><td>Alexa Kommandos</td><td>' . $alexaCount . '</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($SMTP, $mailBetreff, $mailText);
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL . '</body>' . PHP_EOL;
}

$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

SetValueString($htmlString, $html);
SetValueInteger($checkErrorCount, $errorTotal);
SetValueInteger($kernelStart, $startTime);
?>

Ich glaube/hoffe das jetzt fast alles überprüft wird was man überprüfen kann:-)

Ralf

1 „Gefällt mir“

Hallo,

die Referenzen von Instanzen kann man so prüfen:

$instanceList = IPS_GetInstanceList();
$instanceCount = count($instanceList);
$instanceError = 0;
foreach ($instanceList as $id) {
    $refIDs = IPS_GetReferenceList($id);
    $badIDs = [];
    foreach ($refIDs as $refID) {
        if (!IPS_ObjectExists($refID))
            $badIDs[] = $refID;
    }
    if ($badIDs == false) continue;
    if ($instanceError == 0) {
        $errorText .= '<b>Instanzen mit defekten Referenzen:</b><br>' . PHP_EOL;
    }
    $instanceError++;
    $s = implode(',', $badIDs);
    $col = 'red';
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ': ' . $s . '</span><br>' . PHP_EOL;
}

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

das beinhaltet auch den WebHook.

ggfs. gibt es einen falschen Fehler bei WebFront-Visulaisierungen, siehe

Gruß
demel

ps: hast du auch gesehen, was ich zu den Scriptnamen geschrieben habe?

kleine Korrektur (Ausgabe der Objekt-ID bei fehlendem Script)

// fehlende Scripte
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $file = $script['ScriptFile'];
    if (in_array($file, $fileListSYS)) {
        continue;
    }
    if ($scriptError == 0) {
        $errorText .= '<b>fehlende Skripte:</b><br>' . PHP_EOL;
    }
    $scriptError++;
    $col = 'red';
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ' : ' . $file . ' fehlt</span><br>' . PHP_EOL;
}
if ($scriptError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $errorTotal += $scriptError;
}

Moin,
das mit den Referenzen hat mir auch wieder geholfen und ein Event gefunden das es nicht mehr gibt. Bei WebFront gibt es anscheinend wirklich ein Problem. Ich habe ein Test-Webfront eingerichtet und da scheint es zwei Referenzen zu geben die es nicht (mehr) gibt.

Was meinst Du mit Filenamen. Ich habe es gelesen, übernommen und auch getestet. Allerdings nur mit ID getestet.

So mit Test.PHP statt 59993.ips.php getestet und wie Du vermutlich erwartet hast knallte es.

Referenzen sind jetzt auch drin und mit Namen statt IDs sollte es jetzt auch gehen.

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

$SMTP = 33517;          // SMTP Instanz falls Mail erwünscht
$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

// 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;
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);

$col = 'red';

// 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++;
    $loc = IPS_GetLocation($id);
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ' : ' . $script["ScriptFile"].'</span><br>' . PHP_EOL;
    $mailText .= 'ID:' . $id . 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++;
    $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++;
    $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++;
    $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 += 1;
        }
    }
    $Varprofile = $variable['VariableCustomProfile'];
    if ($Varprofile != ''){
        $profile = IPS_GetVariableProfile($Varprofile);
        if ($profile == false){
            $err += 2;
        }
    }
    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Profile:</b><br>' . PHP_EOL;
        $mailText .= 'Fehlende Profile:' . PHP_EOL;
    }
    $varError++;
    $loc = IPS_GetLocation($id);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] .'" fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableProfile'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] .'" fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableCustomProfile'] . '" fehlt ' . 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){
        if (IPS_ObjectExists($VarAction) == false) {
            $err += 1;
        }
    }
    
    $VarAction = $variable['VariableCustomAction'];
    if ($VarAction > 1){
        if (IPS_ObjectExists($VarAction) == false) {
            $err += 2;
        }
    }

    if ($err == 0) {
        continue;
    }
    if ($varError == 0) {
        $errorText .= '<b>Fehlende Aktions-Scripte:</b><br>' . PHP_EOL;
        $mailText .= 'Fehlende Aktions-Scripte:' . PHP_EOL;
    }
    $varError++;
    $loc = IPS_GetLocation($id);
    if ($err & 1){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' #' . $variable['VariableAction'] .' fehlt (Standard)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . '"' . $variable['VariableAction'] . '" fehlt ' . PHP_EOL;
    }
    if ($err & 2){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ' #' . $variable['VariableCustomAction'] .' fehlt (Custom)' . '</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $loc . ' #' . $variable['VariableCustomAction'] . ' fehlt ' . PHP_EOL;
    }
}

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

// Alexa
$id_alexa = 0;
$ids = IPS_GetInstanceListByModuleID('{CC759EB6-7821-4AA5-9267-EF08C6A6A5B3}');
if (count($ids) > 0) {
    $id_alexa = $ids[0];
    $alexalist = [];
    $properties = json_decode(IPS_GetConfiguration($id_alexa), true);
//    var_dump($properties);

    foreach($properties as $name => $value) {
        if (substr($name, 0, 6) == "Device") {
            $devices = json_decode($value, true);
            foreach($devices as $device) {
                switch ($name){
                    case 'DeviceSimpleScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerSimpleID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceDeactivatableScene':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SceneControllerDeactivatableActivateID"],
                            "ID2" => $device["SceneControllerDeactivatableDeactivateID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightSwitch':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightDimmer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["BrightnessControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightExpert':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["BrightnessOnlyControllerID"],
                            "ID3" => $device["ColorOnlyControllerID"],
                            "ID4" => $device["ColorTemperatureOnlyControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLock':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["LockControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceShutter':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["RangeControllerShutterID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeaker':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTemperatureSensor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["TemperatureSensorID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceGenericSlider':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PercentageControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceLightColor':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ColorControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceMediaPlayer':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["SpeakerMuteableVolumeID"],
                            "ID3" => $device["SpeakerMuteableMuteID"],
                            "ID4" => $device["PlaybackControllerID"],
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceSpeakerMuteable':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["SpeakerMuteableVolumeID"],
                            "ID2" => $device["SpeakerMuteableMuteID"],
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                    case 'DeviceTelevision':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["PowerControllerID"],
                            "ID2" => $device["ChannelControllerID"],
                            "ID3" => $device["SpeakerMuteableVolumeID"],
                            "ID4" => $device["SpeakerMuteableMuteID"],
                            "ID5" => $device["InputControllerID"]
                        ];
                        break;
                    case 'DeviceThermostat':
                        $alexalist[] = [
                            "Name" => $device["Name"],
                            "Type" => substr($name, 6),
                            "ID1" => $device["ThermostatControllerID"],
                            "ID2" => 0,
                            "ID3" => 0,
                            "ID4" => 0,
                            "ID5" => 0
                        ];
                        break;
                default:
                            var_dump($name);
                            var_dump($device);
                        break;
                }
            }
        }
    }
    $alexaCount = count($alexalist);
    $alexaError = 0;
    foreach($alexalist as $item) {
        $errorIDs = 0;
        if (($item['ID1'] > 0) && (IPS_ObjectExists($item['ID1']) == false)){
            $errorIDs |= 1;
        }
        if (($item['ID2'] > 0) && (IPS_ObjectExists($item['ID2']) == false)){
            $errorIDs |= 2;
        }
        if (($item['ID3'] > 0) && (IPS_ObjectExists($item['ID3']) == false)){
            $errorIDs |= 4;
        }
        if (($item['ID4'] > 0) && (IPS_ObjectExists($item['ID4']) == false)){
            $errorIDs |= 8;
        }
        if (($item['ID5'] > 0) && (IPS_ObjectExists($item['ID5']) == false)){
            $errorIDs |= 16;
        }
        if (($errorIDs > 0) && ($alexaError == 0)) {
            $errorText .= '<b>Alexa IDs nicht vorhanden:</b><br>' . PHP_EOL;
            $mailText .= 'Fehlende Alexa IDs:' . PHP_EOL;
        }
        if ($errorIDs & 1){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID1'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID1'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 2){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID2'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID2'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 4){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID3'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID3'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 8){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID4'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID4'] . ' nicht vorhanden' . PHP_EOL;
        }
        if ($errorIDs & 16){
            $alexaError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $item['ID5'] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'ID:' . $item['ID5'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}

// Hooks
$ids = IPS_GetInstanceListByModuleID('{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}');
if (count($ids) > 0) {
    $id_webhook = $ids[0];
    $webhooklist = [];
    $properties = json_decode(IPS_GetConfiguration($id_webhook), true);
    $webhooklist = json_decode(IPS_GetProperty($id_webhook, 'Hooks'), true);
    $hookCount = count($webhooklist);
    $hookError = 0;
    foreach($webhooklist as $item) {
        if (IPS_ObjectExists($item['TargetID']) == false){
            if ($hookError == 0){
                $errorText .= '<b>Hook IDs nicht vorhanden:</b><br>' . PHP_EOL;
                $mailText .= 'Fehlende Hook IDs:' . PHP_EOL;
            }
            $hookError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Hook:' . $item['Hook'] . '  mit ID:' . $item['TargetID']   . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'Hook:' . $item['Hook'] . '  mit ID:' . $item['TargetID'] . ' nicht vorhanden' . PHP_EOL;
        }
    }
}
if ($hookError > 0) {
    $errorText .= '<br>' . PHP_EOL;
    $mailText .= PHP_EOL;
    $errorTotal += $hookError;
}

// 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>Mediendatei:</b><br>' . PHP_EOL;
        $errorText .= '<span style="color: ' . $col . ';">nicht vorhanden / </span>' . PHP_EOL;
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">gecached nicht gespeichert</span><br><br>' . PHP_EOL;
        $mailText .= 'Defekte Mediendatei:' . PHP_EOL;
        $col = 'red';
    }
    $mediaError++;
    if (($Media['MediaIsCached']) && ($Media['MediaIsAvailable'])){
        $col = 'yellow';
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' noch nicht gespeichert</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
        $col = 'red';
    }
    else{
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $Media['MediaFile'] . ' nicht vorhanden</span><br>' . PHP_EOL;
        $mailText .= 'ID:' . $id . ': ' . $Media['MediaFile'] . PHP_EOL;
    }
}

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

// Scripte
$scriptCount = 0;
$scriptError = 0;
$fileListIPS = [];
$fileListSYS = [];
$scriptList = IPS_GetScriptList();
$scriptCount = count($scriptList);
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $fileListIPS[] = $script['ScriptFile'];
}

$path = IPS_GetKernelDir() . 'scripts';
$handle = opendir($path);
while ($file = readdir($handle)) {
    if (!is_file($file)) {
        continue;
    }
    if (!preg_match('/^.*\.php$/', $file)) {
        continue;
    }
    if (preg_match('/^.*\.inc\.php$/', $file)) {
        continue;
    }
    $fileListSYS[] = $file;
}
closedir($handle);

// fehlende Scripte
$scriptError = 0;
foreach ($fileListIPS as $file) {
    if (in_array($file, $fileListSYS)) {
        continue;
    }
    $script = IPS_GetScript($file);
    if ($scriptError == 0) {
        $errorText .= '<b>fehlende Skripte:</b><br>' . PHP_EOL;
        $mailText .= 'fehlende Skripte:' . PHP_EOL;
    }
    $scriptError++;
    if ($script){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $file . ' : ' . $script["ScriptFile"].' fehlt</span><br>' . PHP_EOL;
        $mailText .= '#' . $file . ' : ' . $script["ScriptFile"].' fehlt' . PHP_EOL;
    }
    else{
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $file . ' fehlt</span><br>' . PHP_EOL;
        $mailText .= '#' . $file . ' fehlt' . PHP_EOL;
    }
}

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

// überflüssige Scripte
$scriptError = 0;
foreach ($fileListSYS as $file) {
    if (in_array($file, $fileListIPS)) {
        continue;
    }
    if ($scriptError == 0) {
        $errorText .= '<b>überflüssige Skripte:</b><br>' . PHP_EOL;
        $mailText .= 'überflüssige Skripte:' . PHP_EOL;
    }
    $scriptError++;
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;' . $file .' scheint überflüssig</span><br>' . PHP_EOL;
    $mailText .= $file .' scheint überflüssig' . PHP_EOL;
}

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

$scriptError = 0;
$objIDs = IPS_GetObjectList ();
foreach ($fileListSYS as $file) {
    if (!in_array($file, $fileListIPS)) {
        continue;
    }
    $text = file_get_contents($file);
    $lines = explode("\r\n", $text);
    foreach ($lines as $line) {
        if (preg_match('/=[\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
            }
            $scriptError++;
            $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
            $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
        if (preg_match('/\([\t ]*([0-9][0-9][0-9][0-9][0-9])[^0-9]/', $line, $r)) {
            if (!in_array($r[1], $objIDs)) {
                if ($scriptError == 0) {
                    $errorText .= '<b>Fehlende Objekte in Script:</b><br>' . PHP_EOL;
                    $mailText .= 'Fehlende Objekte in Script:' . PHP_EOL;
                }
                $scriptError++;
                $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;# Script:' . $file . '  Objekt:' . $r[1] . ' nicht vorhanden</span><br>' . PHP_EOL;
                $mailText .= 'Script:' . $file . '  Objekt:' . $r[1] . PHP_EOL;
            }
        }
    }
}

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

$instanceList = IPS_GetInstanceList();
$instanceCount = count($instanceList);
$instanceError = 0;
foreach ($instanceList as $id) {
    $refIDs = IPS_GetReferenceList($id);
    $badIDs = [];
    foreach ($refIDs as $refID) {
        if (!IPS_ObjectExists($refID))
            $badIDs[] = $refID;
    }
    if ($badIDs == false) continue;
    $instance = IPS_GetInstance($id);
    if ($instance['ModuleInfo']['ModuleType'] != 6){
        if ($instanceError == 0) {
            $errorText .= '<b>Instanzen mit defekten Referenzen:</b><br>' . PHP_EOL;
            $mailText .= 'Instanzen mit defekten Referenzen:' . PHP_EOL;

        }
        $instanceError++;
        $s = implode(',', $badIDs);
        $loc = IPS_GetLocation($id);
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ': ' . $loc . ': ' . $s . '</span><br>' . PHP_EOL;
        $mailText .= $id . ':' . $loc . ':' . $s . PHP_EOL;
    }
}

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

$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: 220px; }' . 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>Hooks</td><td>' . $hookCount . '</td></tr>' . PHP_EOL;
$html .= '<tr><td>Medien</td><td>' . $mediaCount . '</td></tr>' . PHP_EOL;
if ($id_alexa > 0){
    $html .= '<tr><td>Alexa Kommandos</td><td>' . $alexaCount . '</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($SMTP, $mailBetreff, $mailText);
} else {
    $html .= '<br>keine Fehler<br>' . PHP_EOL . '</body>' . PHP_EOL;
}

$htmlString = 29692; // ID einer Stringvariablen mit HTML-Box Profil
$checkErrorCount = 11096; // ID einer Integervariablen für Fehleranzahl
$kernelStart = 15191; // ID einer Intergervariablen mit ~UnixTimeStamp als Profil

SetValueString($htmlString, $html);
SetValueInteger($checkErrorCount, $errorTotal);
SetValueInteger($kernelStart, $startTime);
?>

Referenzen überprüfe ich in Web-Fronts nicht.

Wird langsam ein richtiges Monster:-)

Ralf

das ist aber nicht das Problem, was ich im o.g. Thread auch hatte (die Objekt-ID 65535)?

ja, ist soweit alles drin, nur ab Zeile 105 ff ist überflüssiger Code (das Aufbauen von files)
Und eine kleine Korrektur

statt

// fehlende Scripte
$scriptError = 0;
foreach ($fileListIPS as $file) {
    if (in_array($file, $fileListSYS)) {
        continue;
    }
    $script = IPS_GetScript($file);
    if ($scriptError == 0) {
        $errorText .= '<b>fehlende Skripte:</b><br>' . PHP_EOL;
        $mailText .= 'fehlende Skripte:' . PHP_EOL;
    }
    $scriptError++;
    if ($script){
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $file . ' : ' . $script["ScriptFile"].' fehlt</span><br>' . PHP_EOL;
        $mailText .= '#' . $file . ' : ' . $script["ScriptFile"].' fehlt' . PHP_EOL;
    }
    else{
        $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $file . ' fehlt</span><br>' . PHP_EOL;
        $mailText .= '#' . $file . ' fehlt' . PHP_EOL;
    }
}

würde ich das schreiben

// fehlende Scripte
$scriptError = 0;
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $file = $script['ScriptFile'];
    if (in_array($file, $fileListSYS)) {
        continue;
    }
    if ($scriptError == 0) {
        $errorText .= '<b>fehlende Skripte:</b><br>' . PHP_EOL;
    }
    $scriptError++;
    $col = 'red';
    $errorText .= '<span style="color: ' . $col . ';">&nbsp;&nbsp;&nbsp;#' . $id . ' : Datei ' . $file . ' fehlt</span><br>' . PHP_EOL;
    $mailText .= '#' . $id . ': Datei ' . $file . ' fehlt' . PHP_EOL;
}

Das $script = IPS_GetScript($file); kann nicht funktionieren, da IPS_GetScript() eine ObjektID übergeben werden muss.

so isses. Ich bin schon am grübeln, ob man daraus nicht ein Modul machen sollte, dann wäre das besser wart- und erweiterbar. Es kommen ja in 6.0 die Ablaufpläne hinzu (was vermutlich intern auch eine etwas andere Struktur sein könnte mit zusätzlichen Feldern …).
So eine integrierte Konsistenzprüfung ist ja nicht falsch … aber vielleicht plant @paresy diesbezüglich auch etwas für die Zukunft.
demel

Nicht nur für euch, auch für die Nutzer :smiley: .

Hi Demel,
an Modul hatte ich noch nicht gedacht und es übersteigt (noch) MEINE Fähigkeiten. Wenn man sich auch um fremde Systeme kümmert/kümmern muss wäre es bestimmt auch eine Hilfe. Mit einer Mail-Option würde man gleich eine Mail bekommen wenn ein anderer Benutzer wieder mal Mist gebaut hat:-)

Ich benutze es um mein System ein wenig aufzuräumen. Mich würde mal interessieren ob es bei anderen Benutzern auch Fehler gefunden hat. Vielleicht sogar bei Profis die schon 10 Jahre mit IPS arbeiten.

Bei deinem Vorschlag mit

$file = $script['ScriptFile'];

bin ich skeptisch. Michael hatte mich drauf hingewiesen das es bei Scripten mit Namen Probleme geben kann und $script kann false sein.

Mir ist noch eingefallen das man analog zu Alexa noch was für Google bräuchte was ich aber nicht in IPS benutze.

Ralf

das könnte ich schon machen, kein Problem. Ich muss noch etwas überlegen, aber
a) die Darstellung sollte man beeinflussen können (auch wegen Mail etc)
b) es sollten zusätzliche Custom-Tests (wie Alex, Google etc) eingehängt werden können

Ich benutze es um mein System ein wenig aufzuräumen. Mich würde mal interessieren ob es bei anderen Benutzern auch Fehler gefunden hat. Vielleicht sogar bei Profis die schon 10 Jahre mit IPS arbeiten.

hmm, kann ich so nicht nachvollziehen, bei mir steht das immer etwas drin. Kannst Du das mal bei dir Aufrufen?

<?php

declare(strict_types=1);

$scriptList = IPS_GetScriptList();
foreach ($scriptList as $id) {
    $script = IPS_GetScript($id);
    $file = $script['ScriptFile'];
    echo 'id=' . $id . ', file=' . $file . PHP_EOL;
}

bei mir steht da immer was drin,

Um ganz sicher zu gehen könnte man das so absichern

    $file = $script['ScriptFile'];
    if ($file == false) {
        $file = $id . '.ips.php';
    }

Und das $scriptfalse sein kann … ich gehe davon aus, das alle ID’s aus IPS_GetScriptList() auch gültig sind.

Ich werde mal schauen, ob ich das mit require/require_once/include/include_once auch geregelt bekomme.

gruß
demel

Moin,
aktuell konnte ich es nicht mehr nachstellen aber Gestern hatte ich mal den Fall das $script false war. Ich würde sagen sicher ist sicher.

das wäre ein weiterer Schritt auf dem Weg zur Vollkommenheit:-) Google-Freunde vor.

Ralf