Hallo Senior,
danke für den Tipp! Soweit ich es gesehen habe, überwacht der Watchdog ja nur das Alter einer Variablen, oder?
Ich habe etwas gestöbert und den Befehl Sys_Ping gefunden, der mir hilft. Daraus habe ich dann gleich mal ein kleines „allgemeines Monitoring“ geschrieben, was mir verschiedene Geräte überwachen und alarmieren kann. Das Script einfach in einen leeren Ordner legen und einmal ausführen - ist aber „alpha“, wer Fehler findet, darf sie mir gerne schicken
<?php
// Konfig ----------------------------------------------------------------------------------------
$archiveID = 52555; // In welchem Archiv soll der Online-Verlauf gespeichert werden?
$checkActiveName = "Aktiv"; // Variablenname
$checkScriptName = "check"; // Variablenname
$alertEventName = "alert"; // Variablenname
$onlineVariableName = "Online"; // Variablenname
$intervalVariableName = "Intervall"; // Variablenname
$timeoutVariableName = "Timeout"; // Variablenname
$hostVariableName = "Host"; // Variablenname für IP-Adresse oder DNS Hostname
$alertWebFrontName = "Alert-WebfrontID"; // WebFront ID für Push-Alerts bei Statusänderung
// Array mit allen zu überwachenden Hosts und deren Parametern
$hosts = array(
"Blackbox" => array(
"Aktiv" => true,
"Host" => "192.168.5.3",
"Intervall" => 60,
"Timeout" => 1000,
"Alert-WebfrontID" => 27413,
),
"Delorean" => array(
"Aktiv" => true,
"Host" => "192.168.5.4",
"Intervall" => 60,
"Timeout" => 1000,
"Alert-WebfrontID" => 27413,
),
"CCU Home" => array(
"Aktiv" => true,
"Host" => "192.168.5.55",
"Intervall" => 10,
"Timeout" => 1000,
"Alert-WebfrontID" => 27413,
),
"CCU Beatbox" => array(
"Aktiv" => true,
"Host" => "192.168.7.3",
"Intervall" => 30,
"Timeout" => 3000,
"Alert-WebfrontID" => 27413,
),
);
// Ab hier nichts mehr ändern --------------------------------------------------------------------
$rootID = IPS_GetParent($_IPS['SELF']);
$hostNames = array_keys($hosts);
// Prüfen, ob Hosts (Dummy-Instanzen) existieren, die lauf Konfig-Array nicht da sein sollten
$childrenIDs = IPS_GetChildrenIDs($rootID);
foreach ($childrenIDs as $childID) {
$child = IPS_GetObject($childID);
if (($child["ObjectType"] == 1) and (!in_array($child["ObjectName"], $hostNames))) {
// Löschfunktion fehlt noch (rekursiv), nur Hinweis ausgeben
print("Should delete ID ".$child["ObjectID"]." (".$child["ObjectName"].")
");
}
}
// Alle Hosts durchgehen
foreach ($hosts as $hostname => $host) {
$host[$onlineVariableName] = false; // Variable für den Online-Status zusätzlich zur Konfiguration erzeugen
// Prüfen ob Host schon existiert ist, ggf. erzeugen
$hostID = @IPS_GetObjectIDByName($hostname, $rootID);
if (!$hostID) {
$hostID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
IPS_SetParent($hostID, $rootID);
IPS_SetName($hostID, $hostname);
}
// Prüfen, ob Variablen existieren, die lauf Konfig-Array nicht da sein sollten
$variableNames = array_keys($host);
$childrenVariableIDs = IPS_GetChildrenIDs($hostID);
foreach ($childrenVariableIDs as $childVariableID) {
$childVariable = IPS_GetObject($childVariableID);
if (($childVariable["ObjectType"] == 2) and (!in_array($childVariable["ObjectName"], $variableNames))) {
if ($childVariable["ObjectID"] != 0) IPS_DeleteVariable($childVariable["ObjectID"]); // Überflüssige Variable löschen
}
}
// Variablen anlegen und füllen
foreach($host as $variableName => $value) {
$variableID = @IPS_GetObjectIDByName($variableName, $hostID);
if (!$variableID) {
if (is_integer($value)) $type = 1;
if (is_string($value)) $type = 3;
if (is_bool($value)) $type = 0;
if (is_double($value)) $type = 2;
$variableID = IPS_CreateVariable($type);
IPS_SetParent($variableID, $hostID);
IPS_SetName($variableID, $variableName);
// Aktivierung Archivierung der Online-Variable
if ($variableName == $onlineVariableName) {
SetValue($variableID, false);
AC_SetLoggingStatus($archiveID, $variableID, true);
IPS_ApplyChanges($archiveID);
}
}
// Script der Online-Variable in jedem Fall neu anlegen/befüllen
if ($variableName == $onlineVariableName) {
// Check Script
$scriptID = @IPS_GetObjectIDByName($checkScriptName, $variableID);
if (!$scriptID) {
$scriptID = IPS_CreateScript(0);
IPS_SetParent($scriptID, $variableID);
IPS_SetName($scriptID, $checkScriptName);
}
IPS_SetScriptContent($scriptID, generateCheckScriptContent($hostname));
IPS_SetScriptTimer($scriptID, $host[$intervalVariableName]);
IPS_SetEventActive(IPS_GetEventIDByName("ScriptTimer", $scriptID), $host[$checkActiveName]);
// Alert Event
$alertEventID = @IPS_GetObjectIDByName($alertEventName, $variableID);
if (!$alertEventID) {
$alertEventID = IPS_CreateEvent(0);
IPS_SetParent($alertEventID, $variableID);
IPS_SetName($alertEventID, $alertEventName);
IPS_SetEventTrigger($alertEventID, 1, $variableID);
IPS_SetEventActive($alertEventID, 1);
}
IPS_SetEventScript($alertEventID, generateAlertEventScriptContent($hostname));
}
else SetValue($variableID, $value);
}
}
function generateCheckScriptContent($hostName) {
global $hosts;
global $hostVariableName;
global $timeoutVariableName;
$stringPing = "Sys_Ping('".$hosts[$hostName][$hostVariableName]."',".$hosts[$hostName][$timeoutVariableName].")";
$stringVariableID = "IPS_GetParent(\$_IPS['SELF'])";
$content = "<? setValue(".$stringVariableID.",".$stringPing.");";
return $content;
}
function generateAlertEventScriptContent($hostName) {
global $hosts;
global $alertWebFrontName;
$stringStatus = $hostName." ist jetzt '.(\$_IPS['VALUE'] ? 'online' : 'offline').'!";
$content = "WFC_PushNotification(".$hosts[$hostName][$alertWebFrontName].",'Monitoring','".$stringStatus."','trickling', 0);";
return $content;
}
Dazu dann noch an beliebiger Stelle manuell ein Event erstellt für die Abschaltung der CCU falls das Monitoring „offline“ meldet. Auslöser ist die „online“ Variable der CCU aus dem Monitoring, die ID ist die der I/O Instanz der CCU:
IPS_SetProperty(17296, "Open", $_IPS['VALUE']);
IPS_ApplyChanges(17296);
CU
Golo