Major changes in Alarm Handling

This commit is contained in:
jhartworks
2025-09-30 09:48:58 +02:00
parent add6324b19
commit 058c27c96c
3 changed files with 83 additions and 11 deletions
+1
View File
@@ -9,6 +9,7 @@
{ "type": "ValidationTextBox", "name": "Projectname", "caption": "Projectname" }, { "type": "ValidationTextBox", "name": "Projectname", "caption": "Projectname" },
{ "type": "NumberSpinner", "name": "ISP", "caption": "ISP-Number" }, { "type": "NumberSpinner", "name": "ISP", "caption": "ISP-Number" },
{ "type": "SelectInstance", "name": "SqlId", "caption": "SQL Connector" },
{ "type": "SelectInstance", "name": "VisuId", "caption": "Web Visu" }, { "type": "SelectInstance", "name": "VisuId", "caption": "Web Visu" },
{ "type": "CheckBox", "name": "SendNotification", "caption": "Send Notification" }, { "type": "CheckBox", "name": "SendNotification", "caption": "Send Notification" },
+80 -9
View File
@@ -12,8 +12,8 @@ class MonitoringServer extends IPSModule {
$this->RegisterPropertyInteger("ParseAnalogCategoryID","0"); $this->RegisterPropertyInteger("ParseAnalogCategoryID","0");
$this->RegisterPropertyInteger("ISP","1"); $this->RegisterPropertyInteger("ISP","1");
$this->RegisterPropertyInteger("SqlId","27624");
$this->RegisterPropertyInteger("VisuId","0"); $this->RegisterPropertyInteger("VisuId","0");
$this->RegisterPropertyInteger("Projectnumber",123456); $this->RegisterPropertyInteger("Projectnumber",123456);
$this->RegisterPropertyString("Projectname","Musterprojekt"); $this->RegisterPropertyString("Projectname","Musterprojekt");
$this->RegisterPropertyString("InfluxDatabase","monitoring"); $this->RegisterPropertyString("InfluxDatabase","monitoring");
@@ -28,6 +28,9 @@ class MonitoringServer extends IPSModule {
$this->RegisterPropertyInteger("MailInst", 0); $this->RegisterPropertyInteger("MailInst", 0);
$this->RegisterPropertyString("MailAdresses", "hallo@mail.com,info@stoerung.de"); $this->RegisterPropertyString("MailAdresses", "hallo@mail.com,info@stoerung.de");
$this->RegisterPropertyBoolean("SendPhone",false);
$this->RegisterPropertyString("PhoneNumbers", "0159123456789,0157987456123");
$this->RegisterPropertyBoolean("SendFtp",false); $this->RegisterPropertyBoolean("SendFtp",false);
$this->RegisterPropertyString("FtpHost", "your-server.de"); $this->RegisterPropertyString("FtpHost", "your-server.de");
$this->RegisterPropertyString("FtpUser", "YourUser"); $this->RegisterPropertyString("FtpUser", "YourUser");
@@ -405,15 +408,19 @@ class MonitoringServer extends IPSModule {
private function notify($trigid, $webfrontid, $targetid, $projectnumber, $projectname, $ispnr){ 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"); $sendit = $this->ReadPropertyBoolean("SendNotification");
$sendwhatsapp = $this->ReadPropertyBoolean("SendWhatsapp"); $sendwhatsapp = $this->ReadPropertyBoolean("SendWhatsapp");
$sendphone = $this->ReadPropertyBoolean("SendPhone");
$sendmail = $this->ReadPropertyBoolean("SendMail"); $sendmail = $this->ReadPropertyBoolean("SendMail");
$senddc = $this->ReadPropertyBoolean("SendDiscord"); $senddc = $this->ReadPropertyBoolean("SendDiscord");
$idSql = $this->ReadPropertyInteger("SqlId");
$idWhatsapp = $this->ReadPropertyInteger("WhatappInst"); $idWhatsapp = $this->ReadPropertyInteger("WhatappInst");
$numbersWhatsapp = $this->ReadPropertyString("WhatsappNumbers"); $numbersWhatsapp = $this->ReadPropertyString("WhatsappNumbers");
$numbersPhone = $this->ReadPropertyString("PhoneNumbers");
$idMail = $this->ReadPropertyInteger("MailInst"); $idMail = $this->ReadPropertyInteger("MailInst");
$mailAdresses = $this->ReadPropertyString("MailAdresses"); $mailAdresses = $this->ReadPropertyString("MailAdresses");
@@ -437,11 +444,12 @@ class MonitoringServer extends IPSModule {
VISU_PostNotification($webfrontid, $art, $smname, $ico, $targetid); VISU_PostNotification($webfrontid, $art, $smname, $ico, $targetid);
} }
$whatsapp = 0;
$whatsapped = 0;
if ($sendwhatsapp == true){ if ($sendwhatsapp == true){
if ( $idWhatsapp > 0 && $idWhatsapp != 123456){ if ( $idWhatsapp > 0 && $idWhatsapp != 123456){
$whatsapp = 1;
//IPS_LogMessage ("Whatsapp" .$projectnumber , "Senden gestartet"); //IPS_LogMessage ("Whatsapp" .$projectnumber , "Senden gestartet");
$paramvals = [ $paramvals = [
"pn" => $art, "pn" => $art,
@@ -453,23 +461,38 @@ class MonitoringServer extends IPSModule {
WBM_SendMessageEx($idWhatsapp,$number,$paramvals); WBM_SendMessageEx($idWhatsapp,$number,$paramvals);
// IPS_LogMessage ("Send Whatsapp " .$projectnumber , "Whatsapp an folgende Nummer gesendet: ". $number ); // IPS_LogMessage ("Send Whatsapp " .$projectnumber , "Whatsapp an folgende Nummer gesendet: ". $number );
} }
$whatsapped = 1;
}else }else
{ {
WBM_SendMessage($idWhatsapp,$paramvals); WBM_SendMessage($idWhatsapp,$paramvals);
//IPS_LogMessage ("Send Whatsapp " .$projectnumber , "Whatsapp an konfigurierte Nummern gesendet"); //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 ($sendmail == true){
if ($idMail > 0 && $idMail != 123456){ if ($idMail > 0 && $idMail != 123456){
//IPS_LogMessage ("Sendmail " .$projectnumber , "Mailing gestartet"); $mail = 1;
$adresses = str_getcsv($mailAdresses); $adresses = str_getcsv($mailAdresses);
$email_address = $adresses;
foreach ($adresses as $adress){ foreach ($adresses as $adress){
SMTP_SendMailEx($idMail, $adress, $art, $smname); 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); $this->WriteAttributeString("AtAlarmtable", $td);
//IPS_LogMessage ("Notify", "Alarmhistory updated"); //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) { elseif (GetValue($trigid) == false) {
$this->SetBuffer($smname, "true"); $this->SetBuffer($smname, "true");
+2 -2
View File
@@ -7,7 +7,7 @@
"version": "6.0", "version": "6.0",
"date": 1491343200 "date": 1491343200
}, },
"version": "2.5", "version": "2.6",
"build": 10, "build": 0,
"date": 0 "date": 0
} }