NTI Enviromux per SNMP auslesen (Environment-Controller)

Tach Zusammen,

wollte mal aus meinen „zusammengefunden“ Scripten was zurück in die Runden geben (Die Fundstellen sind im Script vermerkt).

Hiermit wird ein Environment Controller von NTI
http://www.networktechinc.com/enviro-rems.htmlhttp://www.networktechinc.com/environment-monitor-2d.html
(Sind schon mal günstig in der Bucht zu schießen) ausgelesen.

Viele Spaß und schöne Grüße

Udo

<?
/*
Das folgende Script fragt beim Aufruf einen Enviromux-Kontroller ab und speichert die Werte in die entsprechenden Variablen.
Die Variablen und deren Profile werden beim ersten Start des Scriptes automatisch generiert sofern sie nicht schon existieren.
Das Script setzt sich selbst auf "hidden", damit ein Link auf die Instanz im Webfront/iFront das Script nicht anzeigt.

Installation:
1. Eine neue Instanz anlegen (Dummy-Module)
2. Script unter dieser Instanz anlegen und den Inhalt dieser Datei dort einfügen
3. Script speichern und einmal ausführen
4. Fertig ;-)

Viel Spaß!

Autor: kea
Grundlage1: Das Script von "sanman" aus dem Thread "SNMP Geräte auslesen am Beispiel einer APC USV"
Grundlage2: Das Script von "konfu"     aus dem Thread "Auslesen einer APC SmartUPS USV mit ssnmp"
Vielen Dank an alle Vorposter

*/

// ## Veränderbare Daten ##############################################################################

set_time_limit(80); //Timeout auf 80s setzen

// USV Host-Config
$host           = "xx.yy.zz.71";
$community      = "public";

// ssnmpq Binary
$binary = "C:\ip-symcon\ssnmpq\ssnmpq2.exe";

// In welchem Abstand (Minuten) soll das Script ausgeführt werden?
$minutes = 5;

// Variablen-Namen definieren
$temp1	      	= "Temperatur 1";
$temp2        	= "Temperatur 2";
$hum1	      	= "rel. Feuchtigkeit 1";
$hum2        	= "rel. Feuchtigkeit 2";
$dry1		= "Kontakt 1";
$dry2		= "Kontakt 2";
$dry3		= "Kontakt 3";
$dry4		= "Kontakt 4";
$water		= "Wassersensor";
$lastread         = "Datum letzte SNMP Abfrage";

//Debug Ausgabe aktivieren?
$debug          = false;   // false true

//## Ab hier nichts mehr ändern #######################################################################

//OIDs

$temp1_OID	     	= ".1.3.6.1.4.1.3699.1.1.3.1.1.1.0";  // auf 1 setzen
$temp2_OID       	= ".1.3.6.1.4.1.3699.1.1.3.1.2.1.0";
$hum1_OID	     	= ".1.3.6.1.4.1.3699.1.1.3.1.3.1.0";
$hum2_OID        	= ".1.3.6.1.4.1.3699.1.1.3.1.4.1.0";
$dry1_OID			= ".1.3.6.1.4.1.3699.1.1.3.1.5.1.0";
$dry2_OID			= ".1.3.6.1.4.1.3699.1.1.3.1.6.1.0";
$dry3_OID			= ".1.3.6.1.4.1.3699.1.1.3.1.7.1.0";
$dry4_OID			= ".1.3.6.1.4.1.3699.1.1.3.1.8.1.0";
$water_OID			= ".1.3.6.1.4.1.3699.1.1.3.1.9.1.0";


//SNMP Query Funktion
function snmpget2($oid)
{
    global $host, $community, $binary;

    $oid = ltrim($oid,".");
    $value = IPS_Execute($binary, "/h:$host /c:$community /o:$oid /v", false, true);
    $value = trim($value);
    return $value;
}

// ID des Archive Handlers auslesen
//$archive = IPS_GetInstanceIDByName ( "Archive Handler", 0 );

// Variablen auf Existenz Prüfen. Wenn es die Variable nicht gibt wird sie angelegt.

//Zähler für Positionsbestimmung setzen
$zaehler = 1;

// Wo sind wir?
$parentID = IPS_GetObject($IPS_SELF);
$parentID = $parentID['ParentID'];

//Dieses Script auf "hidden" setzen, damit es im Webfront nicht auftaucht.
IPS_SetHidden($IPS_SELF, true);

// Ereignis für zyklische Abfrage anlegen, sofern nicht schon vorhanden
// Vorgehen:
// 1. Prüfen ob dieses Script Children hat (Ereignisse sind Children)
// 2. Prüfen ob eines dieser Childs ein Ereignis ist
// 3. Prüfen ob eines dieser Ereignisse ein zyklisches Ereignis ist
// 4. Bei zylischen Ereignissen den Zähler $ereignisse hochzählen
// 5. Wenn die Anzahl der zyklischen Ereignisse ($ereignisse) 0 ist, wird ein
//    passendes Ereignis angelegt

$ereignisse = 0;
$children = IPS_GetChildrenIDs($IPS_SELF);
$amount = count($children);
if ($amount > 0)
{
    foreach ($children as $id)
    {
       $array = IPS_GetObject($id);
        $type = $array["ObjectType"];
        if ($type == 4)
        {
           $event = IPS_GetEvent ( $id );
            if ($event["EventType"]== 1)
            {
               $ereignisse++;
            }
        }
    }

}

if ($ereignisse == 0)
{
    $eid = IPS_CreateEvent(1);
    IPS_SetEventCyclic($eid, 0, 0, 0, 2, 2 ,$minutes); //Alle 2 Minuten
    IPS_SetParent($eid, $_IPS['SELF']);
    IPS_SetEventActive($eid, true);
}

//-------------------------------------------------------------
//  Temperatur 1
if (!IPS_VariableProfileExists("ENV_Temperature"))
{
        IPS_CreateVariableProfile("ENV_Temperature", 2);
        IPS_SetVariableProfileText("ENV_Temperature", "", " °C");
        IPS_SetVariableProfileValues("ENV_Temperature", 0, 100, 0.5);
        IPS_SetVariableProfileDigits("ENV_Temperature", 1);
          IPS_SetVariableProfileIcon("ENV_Temperature",  "Temperature");
          if ($debug) { echo "Profil ENV_Temperature wurde angelegt.
"; }
}


$Var = @IPS_GetVariableIDByName($temp1, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $temp1ID = IPS_CreateVariable(2);
        IPS_SetName($temp1ID, $temp1);
        IPS_SetParent($temp1ID, $parentID);
        IPS_SetVariableCustomProfile($temp1ID, "ENV_Temperature");
        IPS_SetPosition($temp1ID, $zaehler);
        AC_SetLoggingStatus($archive, $temp1ID, true);
        if ($debug) { echo "Variable $temp1ID ($temp1) wurde angelegt.
"; }
}
else { $temp1ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

//  Temperatur 2

$Var = @IPS_GetVariableIDByName($temp2, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $temp2ID = IPS_CreateVariable(2);
        IPS_SetName($temp2ID, $temp2);
        IPS_SetParent($temp2ID, $parentID);
        IPS_SetVariableCustomProfile($temp2ID, "ENV_Temperature");
        IPS_SetPosition($temp2ID, $zaehler);
        AC_SetLoggingStatus($archive, $temp2ID, true);
        if ($debug) { echo "Variable $temp2ID ($temp2) wurde angelegt.
"; }
}
else { $temp2ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

//-------------------------------------------------------------
//  Feuchtigkeit 1
if (!IPS_VariableProfileExists("ENV_Humidity"))
{
        IPS_CreateVariableProfile("ENV_Humidity", 2);
        IPS_SetVariableProfileText("ENV_Humidity", "", " %RF");
        IPS_SetVariableProfileValues("ENV_Humidity", 0, 100, 1);
        IPS_SetVariableProfileDigits("ENV_Humidity", 0);
          IPS_SetVariableProfileIcon("ENV_Humidity",  "Speedo");
          if ($debug) { echo "Profil ENV_Humidity wurde angelegt.
"; }
}


$Var = @IPS_GetVariableIDByName($hum1, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $hum1ID = IPS_CreateVariable(2);
        IPS_SetName($hum1ID, $hum1);
        IPS_SetParent($hum1ID, $parentID);
        IPS_SetVariableCustomProfile($hum1ID, "ENV_Humidity");
        IPS_SetPosition($hum1ID, $zaehler);
        AC_SetLoggingStatus($archive, $hum1ID, true);
        if ($debug) { echo "Variable $hum1ID ($hum1) wurde angelegt.
"; }
}
else { $hum1ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

//  Feuchtigkeit 2

$Var = @IPS_GetVariableIDByName($hum2, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $hum2ID = IPS_CreateVariable(2);
        IPS_SetName($hum2ID, $hum2);
        IPS_SetParent($hum2ID, $parentID);
        IPS_SetVariableCustomProfile($hum2ID, "ENV_Humidity");
        IPS_SetPosition($hum2ID, $zaehler);
        AC_SetLoggingStatus($archive, $hum2ID, true);
        if ($debug) { echo "Variable $hum2ID ($hum2) wurde angelegt.
"; }
}
else { $hum2ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

//-------------------------------------------------------------
// Dry 1
if (!IPS_VariableProfileExists("ENV_Dry"))
{
        IPS_CreateVariableProfile("ENV_Dry", 0);
        IPS_SetVariableProfileAssociation("ENV_Dry", 0, "OFFEN", "", 0xff0000);
        IPS_SetVariableProfileAssociation("ENV_Dry", 1, "ZU", "", 0x00FF00);
        IPS_SetVariableProfileIcon("ENV_Dry",  "Lock");
        if ($debug) { echo "Profil ENV_Dry wurde angelegt.
"; }
}

$Var = @IPS_GetVariableIDByName($dry1, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $dry1ID = IPS_CreateVariable(0);
        IPS_SetName($dry1ID, $dry1);
        IPS_SetParent($dry1ID, $parentID);
        IPS_SetVariableCustomProfile($dry1ID, "ENV_Dry");
        IPS_SetPosition($dry1ID, $zaehler);
        AC_SetLoggingStatus($archive, $dry1ID, true);
        if ($debug) { echo "Variable $dry1ID ($dry1) wurde angelegt.
"; }
}
else { $dry1ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

// Dry 2

$Var = @IPS_GetVariableIDByName($dry2, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $dry2ID = IPS_CreateVariable(0);
        IPS_SetName($dry2ID, $dry2);
        IPS_SetParent($dry2ID, $parentID);
        IPS_SetVariableCustomProfile($dry2ID, "ENV_Dry");
        IPS_SetPosition($dry2ID, $zaehler);
        AC_SetLoggingStatus($archive, $dry2ID, true);
        if ($debug) { echo "Variable $dry2ID ($dry2) wurde angelegt.
"; }
}
else { $dry2ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

// Dry 3

$Var = @IPS_GetVariableIDByName($dry3, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $dry3ID = IPS_CreateVariable(0);
        IPS_SetName($dry3ID, $dry3);
        IPS_SetParent($dry3ID, $parentID);
        IPS_SetVariableCustomProfile($dry3ID, "ENV_Dry");
        IPS_SetPosition($dry3ID, $zaehler);
        AC_SetLoggingStatus($archive, $dry3ID, true);
        if ($debug) { echo "Variable $dry3ID ($dry3) wurde angelegt.
"; }
}
else { $dry3ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;


// Dry 4

$Var = @IPS_GetVariableIDByName($dry4, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $dry4ID = IPS_CreateVariable(0);
        IPS_SetName($dry4ID, $dry4);
        IPS_SetParent($dry4ID, $parentID);
        IPS_SetVariableCustomProfile($dry4ID, "ENV_Dry");
        IPS_SetPosition($dry4ID, $zaehler);
        AC_SetLoggingStatus($archive, $dry4ID, true);
        if ($debug) { echo "Variable $dry4ID ($dry4) wurde angelegt.
"; }
}
else { $dry4ID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

//-------------------------------------------------------------
// Water
if (!IPS_VariableProfileExists("ENV_Water"))
{
        IPS_CreateVariableProfile("ENV_Water", 0);
        IPS_SetVariableProfileAssociation("ENV_Water", 0, "Trocken", "", 0x00FF00);
        IPS_SetVariableProfileAssociation("ENV_Water", 1, "Nass!", "", 0xFF0000);
        IPS_SetVariableProfileIcon("ENV_Water",  "Drops");
        if ($debug) { echo "Profil ENV_Water wurde angelegt.
"; }
}

$Var = @IPS_GetVariableIDByName($water, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $waterID = IPS_CreateVariable(0);
        IPS_SetName($waterID, $water);
        IPS_SetParent($waterID, $parentID);
        IPS_SetVariableCustomProfile($waterID, "ENV_Water");
        IPS_SetPosition($waterID, $zaehler);
        AC_SetLoggingStatus($archive, $waterID, true);
        if ($debug) { echo "Variable $waterID ($water1) wurde angelegt.
"; }
}
else { $waterID = $Var;       }

$Var = false; //Sicher is sicher ...
$zaehler++;

//-------------------------------------------------------------
// Datum letzte Abfrage
$Var = @IPS_GetVariableIDByName($lastread, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $lastreadID = IPS_CreateVariable(3);
        IPS_SetName($lastreadID, $lastread);
        IPS_SetParent($lastreadID, $parentID);
        IPS_SetVariableCustomProfile($lastreadID, "UPS_Date");
        IPS_SetPosition($lastreadID, $zaehler);
        if ($debug) { echo "Variable $lastreadID ($lastread) wurde angelegt.
"; }
}
else { $lastreadID = $Var; }

$Var = false; //Sicher is sicher ...
$zaehler++;
//-------------------------------------------------------------





$value = snmpget2 ($temp1_OID);
if ($value != 0 or $value > 65000) 
	{ SetValue($temp1ID, $value/10); }
	if ($debug) { echo "$temp1 : $value
"; }

$value = snmpget2 ($temp2_OID);
if ($value != 0 or $value > 65000) 
	{ SetValue($temp2ID, $value/10); }
	if ($debug) { echo "$temp1 : $value
"; }

$value = snmpget2 ($hum1_OID);
if ($value = 0 or $value > 200) 
	{ SetValue($hum1ID, $value/10); }
	if ($debug) { echo "$hum1 : $value
"; }

$value = snmpget2 ($hum2_OID);
if ($value < 0 or $value > 200) 
	{ SetValue($hum2ID, $value/10); }
	if ($debug) { echo "$hum2 : $value
"; }

$value = snmpget2 ($dry1_OID);
SetValue($dry1ID, $value);
if ($debug) { echo "$dry1 : $value
"; }

$value = snmpget2 ($dry2_OID);
SetValue($dry2ID, $value);
if ($debug) { echo "$dry2 : $value
"; }

$value = snmpget2 ($dry3_OID);
SetValue($dry3ID, $value);
if ($debug) { echo "$dry3 : $value
"; }

$value = snmpget2 ($dry4_OID);
SetValue($dry4ID, $value);
if ($debug) { echo "$dry4 : $value
"; }

$value = snmpget2 ($water_OID);
SetValue($waterID, $value);
if ($debug) { echo "$water : $value
"; }

$date = date("d.m.Y H:i:s");
SetValueString($lastreadID, $date);
if ($debug) { echo "$lastreadID : $date
"; }
?>

N’abend Zusammen,

nach dem Umstieg auf Windows Server 2016 funktionierte ssnmpq.exe nicht mehr.
Habe das Script jetzt auf snmpget.exe umgestellt.
SnmpGet (Shell Tool) | SNMP Software

Folgendes muss getauscht werden:

ssnmpget.ex ins Stammverzeichniss von IPS kopieren und das Script anpassen:


// alt
// $binary = "C:\ip-symcon\ssnmpq\ssnmpq2.exe";
// neu
$binary = "C:\ip-symcon\SnmpGet.exe";

und


// alt
// $value = IPS_Execute($binary, "/h:$host /c:$community /o:$oid /v", false, true);
// neu
$value = IPS_Execute($binary, "-q -r:$host -c:$community -o:$oid", false, true);

Viele Grüße aus OBC

kea