IPS_CreateCategory(),2=>IPS_CreateVariable(3),3=>IPS_CreateScript(0)}; if(!is_int($id)||$id<=0)throw new RuntimeException('Cannot create observer object');$created[]=$id; if(!IPS_SetParent($id,$parent)||!IPS_SetIdent($id,$ident)||!IPS_SetName($id,$name)||!IPS_SetInfo($id,$marker))throw new RuntimeException('Cannot label observer object'); return $id; } function v4viewsScript(int $id,string $source,array $created): void { if(IPS_GetScriptContent($id)===$source)return; if(!in_array($id,$created,true))throw new RuntimeException('Existing observer script differs; not overwritten'); if(!IPS_SetScriptContent($id,$source)||IPS_GetScriptContent($id)!==$source)throw new RuntimeException('Cannot write observer script'); } function v4viewsInstall(string $stage): array { if(!function_exists('IPS_GetKernelVersion')||version_compare(IPS_GetKernelVersion(),'8.0','<'))throw new RuntimeException('Nur im IP-Symcon-Skripteditor ausfuehren.'); [$c,$p]=v4viewsConfig($stage);$marker=v4viewsMarker($c); if(!IPS_InstanceExists($c['managerId'])||IPS_GetInstance($c['managerId'])['ModuleInfo']['ModuleID']!=='{6F771B18-59D4-4C8A-B951-3B2FE9F6A2C4}')throw new RuntimeException('Expected manager missing'); foreach(array_merge($c['accounting']['sources'],$c['extraSources']) as $s){ if(!IPS_VariableExists($s['variableId']))throw new RuntimeException('Expected observation source missing'); $o=IPS_GetObject($s['variableId']);$v=IPS_GetVariable($s['variableId']); if($o['ParentID']!==$s['parentId']||$o['ObjectIdent']!==$s['ident']||!in_array($v['VariableType'],[1,2],true))throw new RuntimeException('Source identity differs'); } if(is_link($stage.'/data')||!is_dir($stage.'/data')||!is_writable($stage.'/data')||(fileperms($stage.'/data')&0077)!==0)throw new RuntimeException('Private data directory required'); $lock='ENELIX.V4.ViewsInstall.'.$c['installationId'];if(!IPS_SemaphoreEnter($lock,3000))throw new RuntimeException('Observer installation busy'); $created=[];$script=null;$newTimer=false;$report=['scope'=>'passive_separated_observation','startedAt'=>gmdate('c'), 'oldCollectorChanged'=>false,'modulesChanged'=>false,'pollingChanged'=>false,'socAccountsChanged'=>false,'trainingEnabled'=>false,'controlEnabled'=>false]; try{ $cat=v4viewsEnsure(0,'ENELIX_V4_SEPARATED_OBSERVATION',0,'V4 - getrennte Last und EV-SDL (nur Beobachtung)',$marker,$created); foreach(['PhysicalLoad'=>'Physische Last - Kandidat, keine Trainingsfreigabe','AllocationModel'=>'EV-SDL-Modell - KEINE separate Messung','ObservationStatus'=>'Beobachtungsstatus'] as $key=>$name)v4viewsEnsure($cat,$key,2,$name,$marker,$created); $script=v4viewsEnsure($cat,'Observe',3,'Getrennte Messsicht alle 30 Sekunden',$marker,$created); $stop=v4viewsEnsure($cat,'Stop',3,'Nur diese zusaetzliche Beobachtung stoppen',$marker,$created); $include=''observer_installed','categoryId'=>$cat,'scriptId'=>$script,'stopId'=>$stop,'firstObservation'=>$first,'futureTimerExecutionVerified'=>false]; echo "OK: Getrennte Last-/EV-SDL-Beobachtung eingerichtet, alle 30 Sekunden.\n"; echo 'Erste Aufnahme: '.$first['capturedAt'].'; Quellen: '.$first['sourceCount'].".\n"; echo 'Physische Last: '.$first['physicalLoadStatus'].'; EV-/SDL-Modell: '.$first['allocationModelStatus'].".\n"; echo "Keine Trainings-/Stellfreigabe. Bisheriger Sammler, Manager, Gateway, SDL und Polling unveraendert.\n"; }catch(Throwable $e){ $report['status']='needs_review';$report['reason']=substr($e->getMessage(),0,180); if($newTimer&&$script!==null)IPS_SetScriptTimer($script,0); echo 'FEHLER: '.$report['reason']."\n"; }finally{ $report['createdObjects']=$created;$report['finishedAt']=gmdate('c'); try{v4viewsJson($stage.'/INSTALL_RESULT.json',$report);}finally{IPS_SemaphoreLeave($lock);} echo 'OBSERVATION REPORT: '.$stage."/INSTALL_RESULT.json\n"; } return $report; }