From c7a2eecd3c875e8225da13a83cfd37c390ee7082 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 17:46:03 +0200 Subject: global-functions: introduce $SendEMail2, $SendNotification2 & $SendTelegram2 These accept just one array as argument. Adding new features is possible without breaking the API. These calls are the same for now: $SendNotification "Subject..." "Message..."; $SendNotification2 ({ subject="Subject..."; message="Message..." }); But the latter will bring more features in future. --- global-functions | 69 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/global-functions b/global-functions index 855221e..b8a7dad 100644 --- a/global-functions +++ b/global-functions @@ -43,8 +43,11 @@ :global ScriptInstallUpdate; :global ScriptLock; :global SendEMail; +:global SendEMail2; :global SendNotification; +:global SendNotification2; :global SendTelegram; +:global SendTelegram2; :global SymbolByUnicodeName; :global SymbolForNotification; :global TimeIsSync; @@ -867,11 +870,16 @@ } } -# send notification via e-mail +# send notification via e-mail - expects at lease two string arguments :set SendEMail do={ - :local Subject [ :tostr $1 ]; - :local Message [ :tostr $2 ]; - :local Link [ :tostr $3 ]; + :global SendEMail2; + + $SendEMail2 ({ subject=$1; message=$2; link=$3 }); +} + +# send notification via e-mail - expects one array argument +:set SendEMail2 do={ + :local Notification $1; :global Identity; :global EmailGeneralTo; @@ -892,9 +900,9 @@ :local Signature [ / system note get note ]; :set ($EmailQueue->[ :len $EmailQueue ]) { to=$EmailGeneralTo; cc=$EmailGeneralCc; - subject=[ $QuotedPrintable ("[" . $Identity . "] " . $Subject) ]; - body=($Message . \ - [ $IfThenElse ([ :len $Link ] > 0) ("\n\n" . $Link) "" ] . \ + subject=[ $QuotedPrintable ("[" . $Identity . "] " . ($Notification->"subject")) ]; + body=(($Notification->"message") . \ + [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \ [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) }; :if ([ :len [ / system scheduler find where name="FlushEmailQueue" ] ] = 0) do={ / system scheduler add name=FlushEmailQueue interval=1s start-time=startup \ @@ -902,27 +910,34 @@ } } -# send notification via e-mail and telegram -# Note that attachment is ignored for telegram, silent is ignored for e-mail! +# send notification via e-mail and telegram - expects at lease two string arguments :set SendNotification do={ - :local Subject [ :tostr $1 ]; - :local Message [ :tostr $2 ]; - :local Link [ :tostr $3 ]; - :local Silent [ :tostr $4 ]; + :global SendNotification2; + + $SendNotification2 ({ subject=$1; message=$2; link=$3; silent=$4 }); +} - :global SendEMail; - :global SendTelegram; +# send notification via e-mail and telegram - expects one array argument +:set SendNotification2 do={ + :local Notification $1; - $SendEMail $Subject $Message $Link; - $SendTelegram $Subject $Message $Link $Silent; + :global SendEMail2; + :global SendTelegram2; + + $SendEMail2 $Notification; + $SendTelegram2 $Notification; } -# send notification via telegram +# send notification via telegram - expects at lease two string arguments :set SendTelegram do={ - :local Subject [ :tostr $1 ]; - :local Message [ :tostr $2 ]; - :local Link [ :tostr $3 ]; - :local Silent [ :tostr $4 ]; + :global SendTelegram2; + + $SendTelegram2 ({ subject=$1; message=$2; link=$3; silent=$4 }); +} + +# send notification via telegram - expects one array argument +:set SendTelegram2 do={ + :local Notification $1; :global Identity; :global TelegramChatId; @@ -975,8 +990,8 @@ } :local Truncated false; - :local LenLink [ :len $Link ]; - :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message); + :local LenLink [ :len ($Notification->"link") ]; + :local Text ("[" . $Identity . "] " . ($Notification->"subject") . "\n\n" . ($Notification->"message")); :local LenText [ :len $Text ]; :if ($LenText > (3968 - $LenLink)) do={ :set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ]; @@ -985,7 +1000,7 @@ :set Text [ $EscapeMD $Text "body" ]; } :if ($LenLink > 0) do={ - :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . [ $EscapeMD $Link "hint" ]); + :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . [ $EscapeMD ($Notification->"link") "hint" ]); } :if ($Truncated = true) do={ :set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \ @@ -1001,7 +1016,7 @@ } / tool fetch check-certificate=yes-without-crl output=none http-method=post \ ("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \ - http-data=("chat_id=" . $ChatId . "&disable_notification=" . $Silent . \ + http-data=("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \ "&disable_web_page_preview=true&parse_mode=" . $ParseMode . "&text=" . $Text) as-value; } on-error={ $LogPrintExit2 info $0 ("Failed sending telegram notification! Queuing...") false; @@ -1013,7 +1028,7 @@ [ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \ " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]); :set ($TelegramQueue->[ :len $TelegramQueue ]) { - chatid=$ChatId; parsemode=$ParseMode; text=$Text; silent=$Silent }; + chatid=$ChatId; parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") }; :if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={ / system scheduler add name=FlushTelegramQueue interval=1m start-time=startup \ on-event=":global FlushTelegramQueue; \$FlushTelegramQueue;"; -- cgit v1.2.3-54-g00ecf From 76f32e3927d2e40f2b6cc28f93186bf84d222799 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:37:33 +0200 Subject: global-functions: $ScriptInstallUpdate: use $SendNotification2 --- global-functions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions b/global-functions index b8a7dad..aa0ea07 100644 --- a/global-functions +++ b/global-functions @@ -678,7 +678,7 @@ :global LogPrintExit2; :global ParseKeyValueStore; :global ScriptInstallUpdate; - :global SendNotification; + :global SendNotification2; :global SymbolForNotification; :global ValidateSyntax; @@ -845,8 +845,8 @@ :set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate"; } - $SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \ - $NotificationMessage $Link; + $SendNotification2 ({ subject=([ $SymbolForNotification "pushpin" ] . \ + "News and configuration changes"); message=$NotificationMessage; link=$Link }); :set SentConfigChangesNotification $ExpectedConfigVersion; } -- cgit v1.2.3-54-g00ecf From 71976f2eb92c68d8754385b318162d55b9171817 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:58:19 +0200 Subject: check-certificates: use $SendNotification2 --- check-certificates | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/check-certificates b/check-certificates index f99b20a..ff93046 100644 --- a/check-certificates +++ b/check-certificates @@ -20,7 +20,7 @@ :global IfThenElse; :global LogPrintExit2; :global ParseKeyValueStore; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global UrlEncode; :global WaitForFile; @@ -95,15 +95,15 @@ $WaitFullyConnected; / certificate set $CertNew name=($CertVal->"name"); } - $SendNotification ([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed") \ - ("A certificate on " . $Identity . " has been renewed.\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed"); \ + message=("A certificate on " . $Identity . " has been renewed.\n\n" . \ "Name: " . ($CertVal->"name") . "\n" . \ "CommonName: " . ($CertNewVal->"common-name") . "\n" . \ "Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \ "Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \ "Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \ "Validity: " . ($CertNewVal->"invalid-before") . " to " . ($CertNewVal->"invalid-after") . "\n" . \ - "Expires in: " . [ $FormatExpire ($CertNewVal->"expires-after") ]) "" "true"; + "Expires in: " . [ $FormatExpire ($CertNewVal->"expires-after") ]); silent=true }); $LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " has been renewed.") false; } on-error={ $LogPrintExit2 debug $0 ("Could not renew certificate " . ($CertVal->"name") . ".") false; @@ -118,15 +118,15 @@ $WaitFullyConnected; } else={ :local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ]; - $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Certificate warning!") \ - ("A certificate on " . $Identity . " " . $State . ".\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning!"); \ + message=("A certificate on " . $Identity . " " . $State . ".\n\n" . \ "Name: " . ($CertVal->"name") . "\n" . \ "CommonName: " . ($CertVal->"common-name") . "\n" . \ "Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \ "Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \ "Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \ "Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\n" . \ - "Expires in: " . [ $IfThenElse (($CertVal->"expired") = true) "expired" [ $FormatExpire ($CertVal->"expires-after") ] ]); + "Expires in: " . [ $IfThenElse (($CertVal->"expired") = true) "expired" [ $FormatExpire ($CertVal->"expires-after") ] ]) }); $LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " " . $State . \ ", it is invalid after " . ($CertVal->"invalid-after") . ".") false; } -- cgit v1.2.3-54-g00ecf From bf315c15f64d677ee879a6225d5985f6b8e25610 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:42:42 +0200 Subject: check-health: use $SendNotification2 --- check-health | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/check-health b/check-health index 761a72f..dba24d8 100644 --- a/check-health +++ b/check-health @@ -18,7 +18,7 @@ :global Identity; :global LogPrintExit2; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :local FormatVoltage do={ @@ -42,10 +42,10 @@ [ :typeof $Voltage ] = "num") do={ :if ($CheckHealthLast->$Name * (100 + $CheckHealthVoltagePercent) < $Voltage * 100 || \ $CheckHealthLast->$Name * 100 > $Voltage * (100 + $CheckHealthVoltagePercent)) do={ - $SendNotification ([ $SymbolForNotification "high-voltage-sign" ] . "Health warning: " . $Name) \ - ("The " . $Name . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "high-voltage-sign" ] . "Health warning: " . $Name); \ + message=("The " . $Name . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \ "old value: " . [ $FormatVoltage ($CheckHealthLast->$Name) ] . "\n" . \ - "new value: " . [ $FormatVoltage $Voltage ]); + "new value: " . [ $FormatVoltage $Voltage ]) }); } } } @@ -56,13 +56,13 @@ [ :typeof $PSU ] = "str") do={ :if ($CheckHealthLast->$Name = "ok" && \ $PSU != "ok") do={ - $SendNotification ([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $Name) \ - ("The power supply unit '" . $Name . "' on " . $Identity . " failed!"); + $SendNotification2 ({ subject=([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $Name); \ + message=("The power supply unit '" . $Name . "' on " . $Identity . " failed!") }); } :if ($CheckHealthLast->$Name != "ok" && \ $PSU = "ok") do={ - $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name) \ - ("The power supply unit '" . $Name . "' on " . $Identity . " recovered!"); + $SendNotification2 ({ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \ + message=("The power supply unit '" . $Name . "' on " . $Identity . " recovered!") }); } } } @@ -81,16 +81,16 @@ } :if ($Temperature > $CheckHealthTemperature->$Name && \ $CheckHealthTemperatureNotified->$Name != true) do={ - $SendNotification ([ $SymbolForNotification "fire" ] . "Health warning: " . $Name) \ - ("The " . $Name . " on " . $Identity . " is above threshold: " . \ - $Temperature . "\C2\B0" . "C"); + $SendNotification2 ({ subject=([ $SymbolForNotification "fire" ] . "Health warning: " . $Name); \ + message=("The " . $Name . " on " . $Identity . " is above threshold: " . \ + $Temperature . "\C2\B0" . "C") }); :set ($CheckHealthTemperatureNotified->$Name) true; } :if ($Temperature <= ($CheckHealthTemperature->$Name - $CheckHealthTemperatureDeviation) && \ $CheckHealthTemperatureNotified->$Name = true) do={ - $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name) \ - ("The " . $Name . " on " . $Identity . " dropped below threshold: " . \ - $Temperature . "\C2\B0" . "C"); + $SendNotification2 ({ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \ + message=("The " . $Name . " on " . $Identity . " dropped below threshold: " . \ + $Temperature . "\C2\B0" . "C") }); :set ($CheckHealthTemperatureNotified->$Name) false; } } -- cgit v1.2.3-54-g00ecf From 4fe11fadee928b40ea7d9a6f10fdfea9a49095ea Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:56:20 +0200 Subject: check-lte-firmware-upgrade: use $SendNotification2 --- check-lte-firmware-upgrade | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/check-lte-firmware-upgrade b/check-lte-firmware-upgrade index f55ec5f..6b46502 100644 --- a/check-lte-firmware-upgrade +++ b/check-lte-firmware-upgrade @@ -15,7 +15,7 @@ :global CharacterReplace; :global LogPrintExit2; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :foreach Interface in=[ / interface lte find ] do={ @@ -29,12 +29,12 @@ } else={ :if (($Firmware->"installed") != ($Firmware->"latest")) do={ :local Info [ / interface lte info $Interface once as-value ]; - $SendNotification ([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade") \ - ("A new firmware version " . ($Firmware->"latest") . " is available for " . \ - "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \ - "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \ - "Installed: " . ($Firmware->"installed") . "\n" . \ - "Available: " . ($Firmware->"latest")) "" "true"; + $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \ + message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \ + "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \ + "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \ + "Installed: " . ($Firmware->"installed") . "\n" . \ + "Available: " . ($Firmware->"latest")); silent=true }); :set SentLteFirmwareUpgradeNotification ($Firmware->"latest"); } } -- cgit v1.2.3-54-g00ecf From 19ca17190d6b8b9eaa979e5547e58ef661f7dbb9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:51:04 +0200 Subject: check-routeros-update: use $SendNotification2 --- check-routeros-update | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/check-routeros-update b/check-routeros-update index 5109e30..683f9be 100644 --- a/check-routeros-update +++ b/check-routeros-update @@ -19,7 +19,7 @@ :global DeviceInfo; :global LogPrintExit2; :global ScriptFromTerminal; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global VersionToNum; :global WaitFullyConnected; @@ -65,18 +65,18 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; :if ($NumInstalled < $NumLatest) do={ :if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={ $LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is a patch release, updating...") false; - $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ - ("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \ - ", updating on " . $Identity . "...") $Link "true"; + $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + message=("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \ + ", updating on " . $Identity . "..."); link=$Link; silent=true }); $DoUpdate; } :if ($SafeUpdateNeighbor = true && [ :len [ / ip neighbor find where \ version=($Update->"latest-version" . " (" . $Update->"channel" . ")") ] ] > 0) do={ $LogPrintExit2 info $0 ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false; - $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ - ("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \ - ", updating on " . $Identity . "...") $Link "true"; + $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + message=("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \ + ", updating on " . $Identity . "..."); link=$Link; silent=true }); $DoUpdate; } @@ -91,9 +91,9 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; } :if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={ $LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is considered safe, updating...") false; - $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ - ("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \ - ", updating on " . $Identity . "...") $Link "true"; + $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + message=("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \ + ", updating on " . $Identity . "..."); link=$Link; silent=true }); $DoUpdate; } } @@ -112,10 +112,10 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; $Update->"latest-version" . ".") true; } - $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ - ("A new RouterOS version " . ($Update->"latest-version") . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + message=("A new RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ".\n\n" . \ - [ $DeviceInfo ]) $Link "true"; + [ $DeviceInfo ]); link=$Link; silent=true }); :set SentRouterosUpdateNotification ($Update->"latest-version"); } @@ -125,10 +125,10 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; $Update->"latest-version" . ".") true; } - $SendNotification ([ $SymbolForNotification "warning-sign" ] . "RouterOS version") \ - ("A different RouterOS version " . ($Update->"latest-version") . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "RouterOS version"); \ + message=("A different RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ", but it is a downgrade.\n\n" . \ - [ $DeviceInfo ]) $Link "true"; + [ $DeviceInfo ]); link=$Link; silent=true }); $LogPrintExit2 info $0 ("A different RouterOS version " . ($Update->"latest-version") . \ " is available for downgrade.") false; :set SentRouterosUpdateNotification ($Update->"latest-version"); -- cgit v1.2.3-54-g00ecf From d6edf6c2d38255b7618d15124e3da790a8f5f414 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:53:54 +0200 Subject: cloud-backup: use $SendNotification2 --- cloud-backup | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cloud-backup b/cloud-backup index aa29faa..23fa164 100644 --- a/cloud-backup +++ b/cloud-backup @@ -18,7 +18,7 @@ :global LogPrintExit2; :global RandomDelay; :global ScriptFromTerminal; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global WaitFullyConnected; @@ -41,14 +41,14 @@ $WaitFullyConnected; } :local Cloud [ / system backup cloud get ([ find ]->0) ]; - $SendNotification ([ $SymbolForNotification "floppy-disk" ] . "Cloud backup") \ - ("Uploaded backup for " . $Identity . " to cloud.\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "floppy-disk" ] . "Cloud backup"); \ + message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \ [ $DeviceInfo ] . "\n\n" . \ "Name: " . $Cloud->"name" . "\n" . \ "Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\n" . \ - "Download key: " . $Cloud->"secret-download-key") "" "true"; + "Download key: " . $Cloud->"secret-download-key"); silent=true }); } on-error={ - $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed") \ - ("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]); + $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed"); \ + message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) }); $LogPrintExit2 error $0 ("Failed uploading backup for " . $Identity . " to cloud!") true; } -- cgit v1.2.3-54-g00ecf From 1ca3e8b59fbd4374ba9d94d83944411ef0d81ae2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:33:05 +0200 Subject: collect-wireless-mac: use $SendNotification2 --- collect-wireless-mac.capsman | 8 ++++---- collect-wireless-mac.local | 8 ++++---- collect-wireless-mac.template | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman index ca43dc5..92ac9d1 100644 --- a/collect-wireless-mac.capsman +++ b/collect-wireless-mac.capsman @@ -17,7 +17,7 @@ :global GetMacVendor; :global LogPrintExit2; :global ScriptLock; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; $ScriptLock $0; @@ -56,8 +56,8 @@ $ScriptLock $0; "first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface); $LogPrintExit2 info $0 $Message false; / caps-man access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes; - $SendNotification ([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid) \ - ("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ + message=("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ "Controller: " . $Identity . "\n" . \ "Interface: " . $Interface . "\n" . \ "SSID: " . $Ssid . "\n" . \ @@ -66,7 +66,7 @@ $ScriptLock $0; "Hostname: " . $HostName . "\n" . \ "Address: " . $Address . "\n" . \ "DNS name: " . $DnsName . "\n" . \ - "Date: " . $DateTime); + "Date: " . $DateTime) }); } else={ $LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \ [ / caps-man access-list get $AccessList comment ]) false; diff --git a/collect-wireless-mac.local b/collect-wireless-mac.local index 7489c4c..828b2eb 100644 --- a/collect-wireless-mac.local +++ b/collect-wireless-mac.local @@ -17,7 +17,7 @@ :global GetMacVendor; :global LogPrintExit2; :global ScriptLock; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; $ScriptLock $0; @@ -56,8 +56,8 @@ $ScriptLock $0; "first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface); $LogPrintExit2 info $0 $Message false; / interface wireless access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes; - $SendNotification ([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid) \ - ("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ + message=("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ "Controller: " . $Identity . "\n" . \ "Interface: " . $Interface . "\n" . \ "SSID: " . $Ssid . "\n" . \ @@ -66,7 +66,7 @@ $ScriptLock $0; "Hostname: " . $HostName . "\n" . \ "Address: " . $Address . "\n" . \ "DNS name: " . $DnsName . "\n" . \ - "Date: " . $DateTime); + "Date: " . $DateTime) }); } else={ $LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \ [ / interface wireless access-list get $AccessList comment ]) false; diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template index b6c4efa..8e4ab5d 100644 --- a/collect-wireless-mac.template +++ b/collect-wireless-mac.template @@ -18,7 +18,7 @@ :global GetMacVendor; :global LogPrintExit2; :global ScriptLock; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; $ScriptLock $0; @@ -58,8 +58,8 @@ $ScriptLock $0; "first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface); $LogPrintExit2 info $0 $Message false; / %PATH% access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes; - $SendNotification ([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid) \ - ("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ + message=("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ "Controller: " . $Identity . "\n" . \ "Interface: " . $Interface . "\n" . \ "SSID: " . $Ssid . "\n" . \ @@ -68,7 +68,7 @@ $ScriptLock $0; "Hostname: " . $HostName . "\n" . \ "Address: " . $Address . "\n" . \ "DNS name: " . $DnsName . "\n" . \ - "Date: " . $DateTime); + "Date: " . $DateTime) }); } else={ $LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \ [ / %PATH% access-list get $AccessList comment ]) false; -- cgit v1.2.3-54-g00ecf From 354aedd98e308ca860796c2f8fdd53ea9eedbb17 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:54:50 +0200 Subject: daily-psk: use $SendNotification2 --- daily-psk.capsman | 8 ++++---- daily-psk.local | 8 ++++---- daily-psk.template | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/daily-psk.capsman b/daily-psk.capsman index 7d2c2ae..eec3115 100644 --- a/daily-psk.capsman +++ b/daily-psk.capsman @@ -17,7 +17,7 @@ :global Identity; :global LogPrintExit2; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global UrlEncode; :global WaitForFile; @@ -81,12 +81,12 @@ $WaitFullyConnected; :set Seen ($Seen, $Ssid); :local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \ "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); - $SendNotification ([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid) \ - ("This is the daily PSK on " . $Identity . ":\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ + message=("This is the daily PSK on " . $Identity . ":\n\n" . \ "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ "Date: " . $Date . "\n\n" . \ - "A client device specific rule must not exist!") $Link; + "A client device specific rule must not exist!"); link=$Link }); } } } diff --git a/daily-psk.local b/daily-psk.local index 6186ddc..473238e 100644 --- a/daily-psk.local +++ b/daily-psk.local @@ -17,7 +17,7 @@ :global Identity; :global LogPrintExit2; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global UrlEncode; :global WaitForFile; @@ -81,12 +81,12 @@ $WaitFullyConnected; :set Seen ($Seen, $Ssid); :local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \ "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); - $SendNotification ([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid) \ - ("This is the daily PSK on " . $Identity . ":\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ + message=("This is the daily PSK on " . $Identity . ":\n\n" . \ "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ "Date: " . $Date . "\n\n" . \ - "A client device specific rule must not exist!") $Link; + "A client device specific rule must not exist!"); link=$Link }); } } } diff --git a/daily-psk.template b/daily-psk.template index 42abba5..cfb7ae7 100644 --- a/daily-psk.template +++ b/daily-psk.template @@ -18,7 +18,7 @@ :global Identity; :global LogPrintExit2; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global UrlEncode; :global WaitForFile; @@ -87,12 +87,12 @@ $WaitFullyConnected; :set Seen ($Seen, $Ssid); :local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \ "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); - $SendNotification ([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid) \ - ("This is the daily PSK on " . $Identity . ":\n\n" . \ + $SendNotification2 ({ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ + message=("This is the daily PSK on " . $Identity . ":\n\n" . \ "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ "Date: " . $Date . "\n\n" . \ - "A client device specific rule must not exist!") $Link; + "A client device specific rule must not exist!"); link=$Link }); } } } -- cgit v1.2.3-54-g00ecf From 81f84353cd75fb8e91e2e02d70b5ed5f17df12dd Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:45:51 +0200 Subject: log-forward: use $SendNotification2 --- log-forward | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/log-forward b/log-forward index 8842c7c..74aaeb4 100644 --- a/log-forward +++ b/log-forward @@ -22,7 +22,7 @@ :global LogPrintExit2; :global QuotedPrintable; :global ScriptLock; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global WaitFullyConnected; @@ -71,11 +71,11 @@ $WaitFullyConnected; } :if ($Count > 0) do={ - $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \ - ("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \ - "this message" ("these " . $Count . " messages") ] . " after " . \ - [ / system resource get uptime ] . " uptime." . [ $IfThenElse ($Duplicates = true) \ - (" Multi-repeated messages have been skipped.") ] . "\n" . $Messages); + $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "Log Forwarding"); \ + message=("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \ + "this message" ("these " . $Count . " messages") ] . " after " . \ + [ / system resource get uptime ] . " uptime." . [ $IfThenElse ($Duplicates = true) \ + (" Multi-repeated messages have been skipped.") ] . "\n" . $Messages) }); :set LogForwardRateLimit ($LogForwardRateLimit + 10); :set LogForwardLast ($MessageVal->".id"); -- cgit v1.2.3-54-g00ecf From 557016387ce270d0c7035be85c7b432841535eda Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:52:26 +0200 Subject: netwatch-notify: use $SendNotification2 --- netwatch-notify | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index ef67804..09dbfb8 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -15,7 +15,7 @@ :global IfThenElse; :global LogPrintExit2; :global ParseKeyValueStore; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global ValidateSyntax; @@ -38,9 +38,9 @@ :local Count ($Metric->"count"); :set ($Metric->"count") 0; :if ($Metric->"notified" = true) do={ - $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up") \ - ("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \ - "It was down for " . $Count . " checks since " . ($Metric->"since") . "."); + $SendNotification2 ({ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \ + message=("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \ + "It was down for " . $Count . " checks since " . ($Metric->"since") . ".") }); :if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={ :if ([ $ValidateSyntax ($HostInfo->"up-hook") ] = true) do={ $LogPrintExit2 info $0 ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false; @@ -76,8 +76,8 @@ ($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \ ("parent host " . $Parent . " is down.") ]) false; :if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={ - $SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \ - ("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . "."); + $SendNotification2 ({ subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ + message=("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".") }); :set ($Metric->"notified") true; :if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={ :if ([ $ValidateSyntax ($HostInfo->"down-hook") ] = true) do={ -- cgit v1.2.3-54-g00ecf From 123fe011151f66f0d6c9a27875d5139a9129ac10 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:46:58 +0200 Subject: sms-forward: use $SendNotification2 --- sms-forward | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sms-forward b/sms-forward index 1d47000..55103fc 100644 --- a/sms-forward +++ b/sms-forward @@ -15,7 +15,7 @@ :global IfThenElse; :global LogPrintExit2; :global ScriptLock; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global WaitFullyConnected; @@ -51,9 +51,9 @@ $WaitFullyConnected; :if ([ :len $Messages ] > 0) do={ :local Count [ :len $Delete ]; - $SendNotification ([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone) \ - ("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \ - " by " . $Identity . " from " . $Phone . ":" . $Messages); + $SendNotification2 ({ subject=([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone); \ + message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \ + " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ / tool sms inbox remove $Sms; } -- cgit v1.2.3-54-g00ecf From 66a92c3da9a43cf4b2df33d652053f72b70898a1 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 20:44:34 +0200 Subject: upload-backup: use $SendNotification2 --- upload-backup | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/upload-backup b/upload-backup index 15adc1f..eb9e2e0 100644 --- a/upload-backup +++ b/upload-backup @@ -26,7 +26,7 @@ :global LogPrintExit2; :global RandomDelay; :global ScriptFromTerminal; -:global SendNotification; +:global SendNotification2; :global SymbolForNotification; :global WaitForFile; :global WaitFullyConnected; @@ -80,13 +80,13 @@ $WaitFullyConnected; } } -$SendNotification [ $IfThenElse ($Failed > 0) \ +$SendNotification2 ({ subject=[ $IfThenElse ($Failed > 0) \ ([ $SymbolForNotification "warning-sign" ] . "Backup & Config upload with failure") \ - ([ $SymbolForNotification "floppy-disk" ] . "Backup & Config upload") ] \ - ("Backup and config export upload for " . $Identity . ".\n\n" . \ + ([ $SymbolForNotification "floppy-disk" ] . "Backup & Config upload") ]; \ + message=("Backup and config export upload for " . $Identity . ".\n\n" . \ [ $DeviceInfo ] . "\n\n" . \ "Backup file: " . $BackupFile . "\n" . \ - "Config file: " . $ConfigFile) "" "true"; + "Config file: " . $ConfigFile); silent=true }); :if ($Failed = 1) do={ :error "An error occured!"; -- cgit v1.2.3-54-g00ecf From e97b3945363c8f322b7ff7f4bf65f13d887d373b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:17:45 +0200 Subject: global-functions: introduce $EitherOr --- global-functions | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/global-functions b/global-functions index aa0ea07..48b58a6 100644 --- a/global-functions +++ b/global-functions @@ -24,6 +24,7 @@ :global DeviceInfo; :global DNSIsResolving; :global DownloadPackage; +:global EitherOr; :global EscapeForRegEx; :global FlushEmailQueue; :global FlushTelegramQueue; @@ -293,6 +294,16 @@ :return false; } +# return either first (if "true") or second +:set EitherOr do={ + :global IfThenElse; + + :if ([ :typeof $1 ] = "num") do={ + :return [ $IfThenElse ($1 != 0) $1 $2 ]; + } + :return [ $IfThenElse ([ :len [ :tostr $1 ] ] > 0) $1 $2 ]; +} + # escape for regular expression :set EscapeForRegEx do={ :local Input [ :tostr $1 ]; -- cgit v1.2.3-54-g00ecf From 42dcdae11eb5d3dcb25c07e2bb790b2c7851a785 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:20:02 +0200 Subject: global-functions: $SendEMail2: support overriding to and cc --- global-functions | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/global-functions b/global-functions index 48b58a6..e32a66e 100644 --- a/global-functions +++ b/global-functions @@ -894,14 +894,20 @@ :global Identity; :global EmailGeneralTo; + :global EmailGeneralToOverride; :global EmailGeneralCc; + :global EmailGeneralCcOverride; :global EmailQueue; + :global EitherOr; :global IfThenElse; :global LogPrintExit2; :global QuotedPrintable; - :if ([ :len $EmailGeneralTo ] = 0) do={ + :local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ]; + :local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ]; + + :if ([ :len $To ] = 0) do={ :return false; } @@ -910,7 +916,7 @@ } :local Signature [ / system note get note ]; :set ($EmailQueue->[ :len $EmailQueue ]) { - to=$EmailGeneralTo; cc=$EmailGeneralCc; + to=$To; cc=$Cc; subject=[ $QuotedPrintable ("[" . $Identity . "] " . ($Notification->"subject")) ]; body=(($Notification->"message") . \ [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \ -- cgit v1.2.3-54-g00ecf From bd05ca1133635a595a976d150fd10e36d46705aa Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:28:52 +0200 Subject: global-functions: $SendTelegram2: store token id in queue --- global-functions | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/global-functions b/global-functions index e32a66e..fa0a34f 100644 --- a/global-functions +++ b/global-functions @@ -370,7 +370,6 @@ # flush telegram queue :set FlushTelegramQueue do={ :global TelegramQueue; - :global TelegramTokenId; :global LogPrintExit2; @@ -385,7 +384,7 @@ :if ([ :typeof $Message ] = "array" ) do={ :do { / tool fetch check-certificate=yes-without-crl output=none http-method=post \ - ("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \ + ("https://api.telegram.org/bot" . ($Message->"tokenid") . "/sendMessage") \ http-data=("chat_id=" . ($Message->"chatid") . \ "&disable_notification=" . ($Message->"silent") . \ "&disable_web_page_preview=true&parse_mode=" . ($Message->"parsemode") . \ @@ -1044,8 +1043,8 @@ :set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \ [ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \ " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]); - :set ($TelegramQueue->[ :len $TelegramQueue ]) { - chatid=$ChatId; parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") }; + :set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TelegramTokenId; + parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") }; :if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={ / system scheduler add name=FlushTelegramQueue interval=1m start-time=startup \ on-event=":global FlushTelegramQueue; \$FlushTelegramQueue;"; -- cgit v1.2.3-54-g00ecf From 2d0ce176299c12de6898e17964ccfc4505b65b7c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:31:11 +0200 Subject: global-functions: $SendTelegram2: support overriding token id and chat id --- global-functions | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/global-functions b/global-functions index fa0a34f..3535f38 100644 --- a/global-functions +++ b/global-functions @@ -961,9 +961,11 @@ :global TelegramFixedWidthFont; :global TelegramQueue; :global TelegramTokenId; + :global TelegramTokenIdOverride; :global CertificateAvailable; :global CharacterReplace; + :global EitherOr; :global IfThenElse; :global LogPrintExit2; :global SymbolForNotification; @@ -996,12 +998,10 @@ :return $Return; } - :local ChatId $TelegramChatId; - :if ([ :len $TelegramChatIdOverride ] > 0) do={ - :set ChatId $TelegramChatIdOverride; - } + :local ChatId [ $EitherOr ($TelegramChatIdOverride->($Notification->"origin")) $TelegramChatId ]; + :local TokenId [ $EitherOr ($TelegramTokenIdOverride->($Notification->"origin")) $TelegramTokenId ]; - :if ([ :len $TelegramTokenId ] = 0 || [ :len $ChatId ] = 0) do={ + :if ([ :len $TokenId ] = 0 || [ :len $ChatId ] = 0) do={ :return false; } @@ -1031,7 +1031,7 @@ $LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; } / tool fetch check-certificate=yes-without-crl output=none http-method=post \ - ("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \ + ("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \ http-data=("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \ "&disable_web_page_preview=true&parse_mode=" . $ParseMode . "&text=" . $Text) as-value; } on-error={ @@ -1043,7 +1043,7 @@ :set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \ [ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \ " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]); - :set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TelegramTokenId; + :set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId; parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") }; :if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={ / system scheduler add name=FlushTelegramQueue interval=1m start-time=startup \ -- cgit v1.2.3-54-g00ecf From c64082388195fc81d0d43e8d360d64663c1d70a9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:38:37 +0200 Subject: global-functions: $ScriptInstallUpdate: pass origin to $SendNotification2 --- global-functions | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/global-functions b/global-functions index 3535f38..ddddcb8 100644 --- a/global-functions +++ b/global-functions @@ -855,8 +855,9 @@ :set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate"; } - $SendNotification2 ({ subject=([ $SymbolForNotification "pushpin" ] . \ - "News and configuration changes"); message=$NotificationMessage; link=$Link }); + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "pushpin" ] . "News and configuration changes"); \ + message=$NotificationMessage; link=$Link }); :set SentConfigChangesNotification $ExpectedConfigVersion; } -- cgit v1.2.3-54-g00ecf From ebd3dbedcbe5c71dde258a5e05a531ad8c70983f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:58:35 +0200 Subject: check-certificates: pass origin to $SendNotification2 --- check-certificates | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/check-certificates b/check-certificates index ff93046..a052930 100644 --- a/check-certificates +++ b/check-certificates @@ -95,7 +95,8 @@ $WaitFullyConnected; / certificate set $CertNew name=($CertVal->"name"); } - $SendNotification2 ({ subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed"); \ message=("A certificate on " . $Identity . " has been renewed.\n\n" . \ "Name: " . ($CertVal->"name") . "\n" . \ "CommonName: " . ($CertNewVal->"common-name") . "\n" . \ @@ -118,7 +119,8 @@ $WaitFullyConnected; } else={ :local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ]; - $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning!"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning!"); \ message=("A certificate on " . $Identity . " " . $State . ".\n\n" . \ "Name: " . ($CertVal->"name") . "\n" . \ "CommonName: " . ($CertVal->"common-name") . "\n" . \ -- cgit v1.2.3-54-g00ecf From baed8b5cfd7245efef3432182a53c63651aa744a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:43:22 +0200 Subject: check-health: pass origin to $SendNotification2 --- check-health | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/check-health b/check-health index dba24d8..ec89545 100644 --- a/check-health +++ b/check-health @@ -42,7 +42,8 @@ [ :typeof $Voltage ] = "num") do={ :if ($CheckHealthLast->$Name * (100 + $CheckHealthVoltagePercent) < $Voltage * 100 || \ $CheckHealthLast->$Name * 100 > $Voltage * (100 + $CheckHealthVoltagePercent)) do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "high-voltage-sign" ] . "Health warning: " . $Name); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "high-voltage-sign" ] . "Health warning: " . $Name); \ message=("The " . $Name . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \ "old value: " . [ $FormatVoltage ($CheckHealthLast->$Name) ] . "\n" . \ "new value: " . [ $FormatVoltage $Voltage ]) }); @@ -56,12 +57,14 @@ [ :typeof $PSU ] = "str") do={ :if ($CheckHealthLast->$Name = "ok" && \ $PSU != "ok") do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $Name); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $Name); \ message=("The power supply unit '" . $Name . "' on " . $Identity . " failed!") }); } :if ($CheckHealthLast->$Name != "ok" && \ $PSU = "ok") do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \ message=("The power supply unit '" . $Name . "' on " . $Identity . " recovered!") }); } } @@ -81,14 +84,16 @@ } :if ($Temperature > $CheckHealthTemperature->$Name && \ $CheckHealthTemperatureNotified->$Name != true) do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "fire" ] . "Health warning: " . $Name); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "fire" ] . "Health warning: " . $Name); \ message=("The " . $Name . " on " . $Identity . " is above threshold: " . \ $Temperature . "\C2\B0" . "C") }); :set ($CheckHealthTemperatureNotified->$Name) true; } :if ($Temperature <= ($CheckHealthTemperature->$Name - $CheckHealthTemperatureDeviation) && \ $CheckHealthTemperatureNotified->$Name = true) do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \ message=("The " . $Name . " on " . $Identity . " dropped below threshold: " . \ $Temperature . "\C2\B0" . "C") }); :set ($CheckHealthTemperatureNotified->$Name) false; -- cgit v1.2.3-54-g00ecf From fbe4c457c6c233e3dbe8e58c2d8d8eead9d9c091 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:57:25 +0200 Subject: check-lte-firmware-upgrade: pass origin to $SendNotification2 --- check-lte-firmware-upgrade | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/check-lte-firmware-upgrade b/check-lte-firmware-upgrade index 6b46502..c05c436 100644 --- a/check-lte-firmware-upgrade +++ b/check-lte-firmware-upgrade @@ -29,7 +29,8 @@ } else={ :if (($Firmware->"installed") != ($Firmware->"latest")) do={ :local Info [ / interface lte info $Interface once as-value ]; - $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \ message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \ "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \ "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \ -- cgit v1.2.3-54-g00ecf From 8e1c524b8583aa476af232d2e2e2a19f5f34540c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:53:28 +0200 Subject: check-routeros-update: pass origin to $SendNotification2 --- check-routeros-update | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/check-routeros-update b/check-routeros-update index 683f9be..0309730 100644 --- a/check-routeros-update +++ b/check-routeros-update @@ -65,7 +65,8 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; :if ($NumInstalled < $NumLatest) do={ :if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={ $LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is a patch release, updating...") false; - $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ message=("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \ ", updating on " . $Identity . "..."); link=$Link; silent=true }); $DoUpdate; @@ -74,7 +75,8 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; :if ($SafeUpdateNeighbor = true && [ :len [ / ip neighbor find where \ version=($Update->"latest-version" . " (" . $Update->"channel" . ")") ] ] > 0) do={ $LogPrintExit2 info $0 ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false; - $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ message=("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \ ", updating on " . $Identity . "..."); link=$Link; silent=true }); $DoUpdate; @@ -91,7 +93,8 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; } :if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={ $LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is considered safe, updating...") false; - $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ message=("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \ ", updating on " . $Identity . "..."); link=$Link; silent=true }); $DoUpdate; @@ -112,7 +115,8 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; $Update->"latest-version" . ".") true; } - $SendNotification2 ({ subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \ message=("A new RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ".\n\n" . \ [ $DeviceInfo ]); link=$Link; silent=true }); @@ -125,7 +129,8 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false; $Update->"latest-version" . ".") true; } - $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "RouterOS version"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "warning-sign" ] . "RouterOS version"); \ message=("A different RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ", but it is a downgrade.\n\n" . \ [ $DeviceInfo ]); link=$Link; silent=true }); -- cgit v1.2.3-54-g00ecf From a9b932d67e294db78555a1473b53e2a23e5632ca Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:55:31 +0200 Subject: cloud-backup: pass origin to $SendNotification2 --- cloud-backup | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cloud-backup b/cloud-backup index 23fa164..546f614 100644 --- a/cloud-backup +++ b/cloud-backup @@ -41,14 +41,16 @@ $WaitFullyConnected; } :local Cloud [ / system backup cloud get ([ find ]->0) ]; - $SendNotification2 ({ subject=([ $SymbolForNotification "floppy-disk" ] . "Cloud backup"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "floppy-disk" ] . "Cloud backup"); \ message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \ [ $DeviceInfo ] . "\n\n" . \ "Name: " . $Cloud->"name" . "\n" . \ "Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\n" . \ "Download key: " . $Cloud->"secret-download-key"); silent=true }); } on-error={ - $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed"); \ message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) }); $LogPrintExit2 error $0 ("Failed uploading backup for " . $Identity . " to cloud!") true; } -- cgit v1.2.3-54-g00ecf From 714a679402ffaa009c74ae5c0d30c2f995e83f57 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:39:30 +0200 Subject: collect-wireless-mac: pass origin to $SendNotification2 --- collect-wireless-mac.capsman | 3 ++- collect-wireless-mac.local | 3 ++- collect-wireless-mac.template | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman index 92ac9d1..4cf8649 100644 --- a/collect-wireless-mac.capsman +++ b/collect-wireless-mac.capsman @@ -56,7 +56,8 @@ $ScriptLock $0; "first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface); $LogPrintExit2 info $0 $Message false; / caps-man access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes; - $SendNotification2 ({ subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ message=("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ "Controller: " . $Identity . "\n" . \ "Interface: " . $Interface . "\n" . \ diff --git a/collect-wireless-mac.local b/collect-wireless-mac.local index 828b2eb..a7c26e6 100644 --- a/collect-wireless-mac.local +++ b/collect-wireless-mac.local @@ -56,7 +56,8 @@ $ScriptLock $0; "first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface); $LogPrintExit2 info $0 $Message false; / interface wireless access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes; - $SendNotification2 ({ subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ message=("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ "Controller: " . $Identity . "\n" . \ "Interface: " . $Interface . "\n" . \ diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template index 8e4ab5d..41cf299 100644 --- a/collect-wireless-mac.template +++ b/collect-wireless-mac.template @@ -58,7 +58,8 @@ $ScriptLock $0; "first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface); $LogPrintExit2 info $0 $Message false; / %PATH% access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes; - $SendNotification2 ({ subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid); \ message=("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \ "Controller: " . $Identity . "\n" . \ "Interface: " . $Interface . "\n" . \ -- cgit v1.2.3-54-g00ecf From fe9754c6939fb58dd0d9d2cd281e8dcf9cd9a128 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:56:30 +0200 Subject: daily-psk: pass origin to $SendNotification2 --- daily-psk.capsman | 3 ++- daily-psk.local | 3 ++- daily-psk.template | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/daily-psk.capsman b/daily-psk.capsman index eec3115..ca95fb8 100644 --- a/daily-psk.capsman +++ b/daily-psk.capsman @@ -81,7 +81,8 @@ $WaitFullyConnected; :set Seen ($Seen, $Ssid); :local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \ "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); - $SendNotification2 ({ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ diff --git a/daily-psk.local b/daily-psk.local index 473238e..bddf2c9 100644 --- a/daily-psk.local +++ b/daily-psk.local @@ -81,7 +81,8 @@ $WaitFullyConnected; :set Seen ($Seen, $Ssid); :local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \ "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); - $SendNotification2 ({ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ diff --git a/daily-psk.template b/daily-psk.template index cfb7ae7..967b51a 100644 --- a/daily-psk.template +++ b/daily-psk.template @@ -87,7 +87,8 @@ $WaitFullyConnected; :set Seen ($Seen, $Ssid); :local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \ "?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]); - $SendNotification2 ({ subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \ message=("This is the daily PSK on " . $Identity . ":\n\n" . \ "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ -- cgit v1.2.3-54-g00ecf From 87cbc1edadddaae330d58b23cc101d8ab5abddc6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:50:44 +0200 Subject: log-forward: pass origin to $SendNotification2 --- log-forward | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/log-forward b/log-forward index 74aaeb4..8f72893 100644 --- a/log-forward +++ b/log-forward @@ -71,7 +71,8 @@ $WaitFullyConnected; } :if ($Count > 0) do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "warning-sign" ] . "Log Forwarding"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "warning-sign" ] . "Log Forwarding"); \ message=("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \ "this message" ("these " . $Count . " messages") ] . " after " . \ [ / system resource get uptime ] . " uptime." . [ $IfThenElse ($Duplicates = true) \ -- cgit v1.2.3-54-g00ecf From e6223a3661af4ee3888f2656d103a865eb6ab27a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:54:30 +0200 Subject: netwatch-notify: pass origin to $SendNotification2 --- netwatch-notify | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 09dbfb8..5600857 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -38,7 +38,8 @@ :local Count ($Metric->"count"); :set ($Metric->"count") 0; :if ($Metric->"notified" = true) do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \ message=("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \ "It was down for " . $Count . " checks since " . ($Metric->"since") . ".") }); :if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={ @@ -76,7 +77,8 @@ ($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \ ("parent host " . $Parent . " is down.") ]) false; :if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={ - $SendNotification2 ({ subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \ message=("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".") }); :set ($Metric->"notified") true; :if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={ -- cgit v1.2.3-54-g00ecf From 0d249d6da4fa1e1a02b7bdaee8be6c4be72b942b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:51:32 +0200 Subject: sms-forward: pass origin to $SendNotification2 --- sms-forward | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sms-forward b/sms-forward index 55103fc..2eecc07 100644 --- a/sms-forward +++ b/sms-forward @@ -51,7 +51,8 @@ $WaitFullyConnected; :if ([ :len $Messages ] > 0) do={ :local Count [ :len $Delete ]; - $SendNotification2 ({ subject=([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone); \ + $SendNotification2 ({ origin=$0; \ + subject=([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone); \ message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \ " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ -- cgit v1.2.3-54-g00ecf From 9fc75f5932d6a1db129b2d74cfa1fd2aed851328 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:49:39 +0200 Subject: upload-backup: pass origin to $SendNotification2 --- upload-backup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/upload-backup b/upload-backup index eb9e2e0..921b196 100644 --- a/upload-backup +++ b/upload-backup @@ -80,7 +80,8 @@ $WaitFullyConnected; } } -$SendNotification2 ({ subject=[ $IfThenElse ($Failed > 0) \ +$SendNotification2 ({ origin=$0; \ + subject=[ $IfThenElse ($Failed > 0) \ ([ $SymbolForNotification "warning-sign" ] . "Backup & Config upload with failure") \ ([ $SymbolForNotification "floppy-disk" ] . "Backup & Config upload") ]; \ message=("Backup and config export upload for " . $Identity . ".\n\n" . \ -- cgit v1.2.3-54-g00ecf From b497edd092b5b01e7601460308c45d6970fabb54 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 28 Apr 2021 15:11:08 +0200 Subject: global-config: comment on overriding e-mail and Telegram settings --- global-config | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/global-config b/global-config index 107ef19..58c9617 100644 --- a/global-config +++ b/global-config @@ -33,6 +33,13 @@ # This is whether or not to send Telegram messages with fixed-width font. :global TelegramFixedWidthFont true; +# It is possible to override e-mail and Telegram setting for every script. +# This is done in arrays EmailGeneralToOverride, EmailGeneralCcOverride, +# TelegramTokenIdOverride and TelegramChatIdOverride like this: +#:global EmailGeneralToOverride { +# "check-certificates"="override@example.com"; +#} + # Toggle this to disable symbols in notifications. :global NotificationsWithSymbols true; # Toggle this to disable color output in terminal/cli. -- cgit v1.2.3-54-g00ecf From 56b75237754eb065aecb932b3082ba0ca29c3f7c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 28 Apr 2021 15:33:37 +0200 Subject: global-functions: notify about settings override --- global-config | 2 +- global-config-overlay | 2 +- global-config.changes | 1 + global-functions | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/global-config b/global-config index 58c9617..9e69c18 100644 --- a/global-config +++ b/global-config @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! -:global GlobalConfigVersion 47; +:global GlobalConfigVersion 48; # This is used for DNS and backup file. :global Domain "example.com"; diff --git a/global-config-overlay b/global-config-overlay index 850e6d8..316fde5 100644 --- a/global-config-overlay +++ b/global-config-overlay @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! # Comment or remove to disable news and change notifications. -:global GlobalConfigVersion 47; +:global GlobalConfigVersion 48; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index 2dc68f7..d3d1059 100644 --- a/global-config.changes +++ b/global-config.changes @@ -51,6 +51,7 @@ 45="We have a Telegram Group! Come along and say hello: https://t.me/routeros_scripts"; 46="Added configurable random delay in backup scripts to stretch execution and prevent resource congestion."; 47="Removed obsolete intermediate certificate 'Let's Encrypt Authority X3' from store."; + 48="Added support for overriding e-mail and Telegram settings for every script."; }; # Migration steps to be applied on script updates diff --git a/global-functions b/global-functions index ddddcb8..ff16076 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 47; +:global ExpectedConfigVersion 48; # global variables not to be changed by user :global GlobalFunctionsReady false; -- cgit v1.2.3-54-g00ecf