diff --git a/Monitoring Server Influx V1/form.json b/Monitoring Server Influx V1/form.json index 809dd5a..9cf7ae0 100644 --- a/Monitoring Server Influx V1/form.json +++ b/Monitoring Server Influx V1/form.json @@ -9,6 +9,7 @@ { "type": "ValidationTextBox", "name": "Projectname", "caption": "Projectname" }, { "type": "NumberSpinner", "name": "ISP", "caption": "ISP-Number" }, + { "type": "SelectInstance", "name": "SqlId", "caption": "SQL Connector" }, { "type": "SelectInstance", "name": "VisuId", "caption": "Web Visu" }, { "type": "CheckBox", "name": "SendNotification", "caption": "Send Notification" }, diff --git a/Monitoring Server Influx V1/module.php b/Monitoring Server Influx V1/module.php index 1261719..ff6e1d7 100644 --- a/Monitoring Server Influx V1/module.php +++ b/Monitoring Server Influx V1/module.php @@ -12,8 +12,8 @@ class MonitoringServer extends IPSModule { $this->RegisterPropertyInteger("ParseAnalogCategoryID","0"); $this->RegisterPropertyInteger("ISP","1"); + $this->RegisterPropertyInteger("SqlId","27624"); $this->RegisterPropertyInteger("VisuId","0"); - $this->RegisterPropertyInteger("Projectnumber",123456); $this->RegisterPropertyString("Projectname","Musterprojekt"); $this->RegisterPropertyString("InfluxDatabase","monitoring"); @@ -28,6 +28,9 @@ class MonitoringServer extends IPSModule { $this->RegisterPropertyInteger("MailInst", 0); $this->RegisterPropertyString("MailAdresses", "hallo@mail.com,info@stoerung.de"); + $this->RegisterPropertyBoolean("SendPhone",false); + $this->RegisterPropertyString("PhoneNumbers", "0159123456789,0157987456123"); + $this->RegisterPropertyBoolean("SendFtp",false); $this->RegisterPropertyString("FtpHost", "your-server.de"); $this->RegisterPropertyString("FtpUser", "YourUser"); @@ -405,15 +408,19 @@ class MonitoringServer extends IPSModule { private function notify($trigid, $webfrontid, $targetid, $projectnumber, $projectname, $ispnr){ + $projectnumber = $this->ReadPropertyInteger("Projectnumber"); + $projectname = $this->ReadPropertyString("Projectname"); + $ispnumber = $this->ReadPropertyInteger("ISP"); $sendit = $this->ReadPropertyBoolean("SendNotification"); $sendwhatsapp = $this->ReadPropertyBoolean("SendWhatsapp"); + $sendphone = $this->ReadPropertyBoolean("SendPhone"); $sendmail = $this->ReadPropertyBoolean("SendMail"); $senddc = $this->ReadPropertyBoolean("SendDiscord"); - + $idSql = $this->ReadPropertyInteger("SqlId"); $idWhatsapp = $this->ReadPropertyInteger("WhatappInst"); $numbersWhatsapp = $this->ReadPropertyString("WhatsappNumbers"); - + $numbersPhone = $this->ReadPropertyString("PhoneNumbers"); $idMail = $this->ReadPropertyInteger("MailInst"); $mailAdresses = $this->ReadPropertyString("MailAdresses"); @@ -437,11 +444,12 @@ class MonitoringServer extends IPSModule { VISU_PostNotification($webfrontid, $art, $smname, $ico, $targetid); } - + $whatsapp = 0; + $whatsapped = 0; if ($sendwhatsapp == true){ if ( $idWhatsapp > 0 && $idWhatsapp != 123456){ - + $whatsapp = 1; //IPS_LogMessage ("Whatsapp" .$projectnumber , "Senden gestartet"); $paramvals = [ "pn" => $art, @@ -453,23 +461,38 @@ class MonitoringServer extends IPSModule { WBM_SendMessageEx($idWhatsapp,$number,$paramvals); // IPS_LogMessage ("Send Whatsapp " .$projectnumber , "Whatsapp an folgende Nummer gesendet: ". $number ); } + $whatsapped = 1; }else { WBM_SendMessage($idWhatsapp,$paramvals); //IPS_LogMessage ("Send Whatsapp " .$projectnumber , "Whatsapp an konfigurierte Nummern gesendet"); + $whatsapped = 1; } } } + $phonenumber = '0'; + $phone = 0; + $phoned = 0; + + if ($sendphone == true){ + $phone = 1; + if ($numbersPhone != ""){ + $phonenumbers = $numbersPhone; + } + } + + $mail = 0; + $mailed = 0; if ($sendmail == true){ if ($idMail > 0 && $idMail != 123456){ - //IPS_LogMessage ("Sendmail " .$projectnumber , "Mailing gestartet"); - + $mail = 1; $adresses = str_getcsv($mailAdresses); + $email_address = $adresses; foreach ($adresses as $adress){ SMTP_SendMailEx($idMail, $adress, $art, $smname); - // IPS_LogMessage ("Sendmail " .$projectnumber , "Mail an folgende Adresse gesendet: ".$adress ); + $mailed = 1; } } } @@ -484,7 +507,55 @@ class MonitoringServer extends IPSModule { $this->WriteAttributeString("AtAlarmtable", $td); //IPS_LogMessage ("Notify", "Alarmhistory updated"); - + MySQL_Open($idSql); + + // Beispielwerte (ersetzen durch echte) + $topic = ''; + + $sms = 0; + $smsnumber = '0'; + $smsed = 0; + + + // === Helfer: Escaping für Strings === + if (function_exists('MySQL_RealEscapeString')) { + $esc = fn(string $s) => MySQL_RealEscapeString($idSql, $s); + } else { + // Fallback, falls Modul-Funktion nicht verfügbar ist + $esc = fn(string $s) => addslashes($s); + } + + // === INSERT bauen === + $sql = sprintf( + "INSERT INTO alarms ( + topic, projectnumber, projectname, isp, name, + sms, smsnumber, smsed, + whatsapp, wanumber, whatsapped, + phone, phonenumber, phoned, + mail, email_address, mailed, + push + ) VALUES ( + '%s','%s','%s','%s','%s', + %d,'%s',%d, + %d,'%s',%d, + %d,'%s',%d, + %d,'%s',%d, + %d + )", + $esc($topic), $esc($projectnumber), $esc($projectname), $esc($ispnumber), $esc($smname), + (int)$sms, $esc($smsnumber), (int)$smsed, + (int)$whatsapp, $esc($numbersWhatsapp), (int)$whatsapped, + (int)$phone, $esc($phonenumber), (int)$phoned, + (int)$mail, $esc($email_address), (int)$mailed, + (int)$push + ); + + // === Ausführen === + $ok = MySQL_ExecuteSimple($idSql, $sql); + if (!$ok) { + echo "INSERT fehlgeschlagen.\n"; + return; + } } elseif (GetValue($trigid) == false) { $this->SetBuffer($smname, "true"); diff --git a/library.json b/library.json index 8f7794e..57b7a9d 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "version": "6.0", "date": 1491343200 }, - "version": "2.5", - "build": 10, + "version": "2.6", + "build": 0, "date": 0 } \ No newline at end of file