aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-04-28 20:16:08 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-04-28 20:16:08 +0200
commitda877612209b217fdfd5429889b6d7284bfd10a5 (patch)
tree17fae6776664e6c550c3ba3b2ea7025779b9c35e
parentd4c9d1c577d14991a63f285e57fcf2cfaa2d5cd4 (diff)
parent56b75237754eb065aecb932b3082ba0ca29c3f7c (diff)
Merge branch 'notifications' into next
-rw-r--r--check-certificates16
-rw-r--r--check-health33
-rw-r--r--check-lte-firmware-upgrade15
-rw-r--r--check-routeros-update37
-rw-r--r--cloud-backup14
-rw-r--r--collect-wireless-mac.capsman9
-rw-r--r--collect-wireless-mac.local9
-rw-r--r--collect-wireless-mac.template9
-rw-r--r--daily-psk.capsman9
-rw-r--r--daily-psk.local9
-rw-r--r--daily-psk.template9
-rw-r--r--global-config9
-rw-r--r--global-config-overlay2
-rw-r--r--global-config.changes1
-rw-r--r--global-functions116
-rw-r--r--log-forward13
-rw-r--r--netwatch-notify14
-rw-r--r--sms-forward9
-rw-r--r--upload-backup11
19 files changed, 205 insertions, 139 deletions
diff --git a/check-certificates b/check-certificates
index f99b20a..a052930 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,16 @@ $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 ({ 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" . \
"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 +119,16 @@ $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 ({ 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" . \
"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;
}
diff --git a/check-health b/check-health
index 761a72f..ec89545 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,11 @@
[ :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 ({ 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 ]);
+ "new value: " . [ $FormatVoltage $Voltage ]) });
}
}
}
@@ -56,13 +57,15 @@
[ :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 ({ 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={
- $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name) \
- ("The power supply unit '" . $Name . "' on " . $Identity . " recovered!");
+ $SendNotification2 ({ origin=$0; \
+ subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \
+ message=("The power supply unit '" . $Name . "' on " . $Identity . " recovered!") });
}
}
}
@@ -81,16 +84,18 @@
}
: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 ({ 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={
- $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name) \
- ("The " . $Name . " on " . $Identity . " dropped below threshold: " . \
- $Temperature . "\C2\B0" . "C");
+ $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;
}
}
diff --git a/check-lte-firmware-upgrade b/check-lte-firmware-upgrade
index f55ec5f..c05c436 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,13 @@
} 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 ({ 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" . \
+ "Installed: " . ($Firmware->"installed") . "\n" . \
+ "Available: " . ($Firmware->"latest")); silent=true });
:set SentLteFirmwareUpgradeNotification ($Firmware->"latest");
}
}
diff --git a/check-routeros-update b/check-routeros-update
index 5109e30..0309730 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,20 @@ $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 ({ 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;
}
: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 ({ 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,9 +93,10 @@ $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 ({ 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,10 +115,11 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false;
$Update->"latest-version" . ".") true;
}
- $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
- ("A new RouterOS version " . ($Update->"latest-version") . \
+ $SendNotification2 ({ origin=$0; \
+ 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 +129,11 @@ $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 ({ 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 "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");
diff --git a/cloud-backup b/cloud-backup
index aa29faa..546f614 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,16 @@ $WaitFullyConnected;
}
:local Cloud [ / system backup cloud get ([ find ]->0) ];
- $SendNotification ([ $SymbolForNotification "floppy-disk" ] . "Cloud backup") \
- ("Uploaded backup for " . $Identity . " to cloud.\n\n" . \
+ $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") "" "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 ({ 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;
}
diff --git a/collect-wireless-mac.capsman b/collect-wireless-mac.capsman
index ca43dc5..4cf8649 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,9 @@ $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 ({ 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" . \
"SSID: " . $Ssid . "\n" . \
@@ -66,7 +67,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..a7c26e6 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,9 @@ $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 ({ 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" . \
"SSID: " . $Ssid . "\n" . \
@@ -66,7 +67,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..41cf299 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,9 @@ $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 ({ 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" . \
"SSID: " . $Ssid . "\n" . \
@@ -68,7 +69,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;
diff --git a/daily-psk.capsman b/daily-psk.capsman
index 7d2c2ae..ca95fb8 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,13 @@ $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 ({ origin=$0; \
+ 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..bddf2c9 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,13 @@ $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 ({ origin=$0; \
+ 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..967b51a 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,13 @@ $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 ({ origin=$0; \
+ 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/global-config b/global-config
index 107ef19..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";
@@ -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.
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 855221e..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;
@@ -24,6 +24,7 @@
:global DeviceInfo;
:global DNSIsResolving;
:global DownloadPackage;
+:global EitherOr;
:global EscapeForRegEx;
:global FlushEmailQueue;
:global FlushTelegramQueue;
@@ -43,8 +44,11 @@
:global ScriptInstallUpdate;
:global ScriptLock;
:global SendEMail;
+:global SendEMail2;
:global SendNotification;
+:global SendNotification2;
:global SendTelegram;
+:global SendTelegram2;
:global SymbolByUnicodeName;
:global SymbolForNotification;
:global TimeIsSync;
@@ -290,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 ];
@@ -356,7 +370,6 @@
# flush telegram queue
:set FlushTelegramQueue do={
:global TelegramQueue;
- :global TelegramTokenId;
:global LogPrintExit2;
@@ -371,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") . \
@@ -675,7 +688,7 @@
:global LogPrintExit2;
:global ParseKeyValueStore;
:global ScriptInstallUpdate;
- :global SendNotification;
+ :global SendNotification2;
:global SymbolForNotification;
:global ValidateSyntax;
@@ -842,8 +855,9 @@
:set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate";
}
- $SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \
- $NotificationMessage $Link;
+ $SendNotification2 ({ origin=$0; \
+ subject=([ $SymbolForNotification "pushpin" ] . "News and configuration changes"); \
+ message=$NotificationMessage; link=$Link });
:set SentConfigChangesNotification $ExpectedConfigVersion;
}
@@ -867,22 +881,33 @@
}
}
-# 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;
+ :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;
}
@@ -891,10 +916,10 @@
}
: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) "" ] . \
+ to=$To; cc=$Cc;
+ 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 +927,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 });
+}
+
+# send notification via e-mail and telegram - expects one array argument
+:set SendNotification2 do={
+ :local Notification $1;
- :global SendEMail;
- :global SendTelegram;
+ :global SendEMail2;
+ :global SendTelegram2;
- $SendEMail $Subject $Message $Link;
- $SendTelegram $Subject $Message $Link $Silent;
+ $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;
@@ -930,9 +962,11 @@
:global TelegramFixedWidthFont;
:global TelegramQueue;
:global TelegramTokenId;
+ :global TelegramTokenIdOverride;
:global CertificateAvailable;
:global CharacterReplace;
+ :global EitherOr;
:global IfThenElse;
:global LogPrintExit2;
:global SymbolForNotification;
@@ -965,18 +999,16 @@
: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;
}
: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 +1017,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" ] . \
@@ -1000,8 +1032,8 @@
$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") \
- http-data=("chat_id=" . $ChatId . "&disable_notification=" . $Silent . \
+ ("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={
$LogPrintExit2 info $0 ("Failed sending telegram notification! Queuing...") false;
@@ -1012,8 +1044,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=$Silent };
+ :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 \
on-event=":global FlushTelegramQueue; \$FlushTelegramQueue;";
diff --git a/log-forward b/log-forward
index 8842c7c..8f72893 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,12 @@ $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 ({ 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) \
+ (" Multi-repeated messages have been skipped.") ] . "\n" . $Messages) });
:set LogForwardRateLimit ($LogForwardRateLimit + 10);
:set LogForwardLast ($MessageVal->".id");
diff --git a/netwatch-notify b/netwatch-notify
index ef67804..5600857 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,10 @@
: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 ({ 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={
:if ([ $ValidateSyntax ($HostInfo->"up-hook") ] = true) do={
$LogPrintExit2 info $0 ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false;
@@ -76,8 +77,9 @@
($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 ({ 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={
:if ([ $ValidateSyntax ($HostInfo->"down-hook") ] = true) do={
diff --git a/sms-forward b/sms-forward
index 1d47000..2eecc07 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,10 @@ $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 ({ 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={
/ tool sms inbox remove $Sms;
}
diff --git a/upload-backup b/upload-backup
index 15adc1f..921b196 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,14 @@ $WaitFullyConnected;
}
}
-$SendNotification [ $IfThenElse ($Failed > 0) \
+$SendNotification2 ({ origin=$0; \
+ 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!";