mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
Merge branch 'notifications' into next
This commit is contained in:
commit
da87761220
|
@ -20,7 +20,7 @@
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ParseKeyValueStore;
|
:global ParseKeyValueStore;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
|
@ -95,15 +95,16 @@ $WaitFullyConnected;
|
||||||
/ certificate set $CertNew name=($CertVal->"name");
|
/ certificate set $CertNew name=($CertVal->"name");
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification ([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed"); \
|
||||||
|
message=("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
||||||
"Name: " . ($CertVal->"name") . "\n" . \
|
"Name: " . ($CertVal->"name") . "\n" . \
|
||||||
"CommonName: " . ($CertNewVal->"common-name") . "\n" . \
|
"CommonName: " . ($CertNewVal->"common-name") . "\n" . \
|
||||||
"Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
"Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
||||||
"Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \
|
"Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \
|
||||||
"Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \
|
"Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \
|
||||||
"Validity: " . ($CertNewVal->"invalid-before") . " to " . ($CertNewVal->"invalid-after") . "\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;
|
$LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " has been renewed.") false;
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 debug $0 ("Could not renew certificate " . ($CertVal->"name") . ".") false;
|
$LogPrintExit2 debug $0 ("Could not renew certificate " . ($CertVal->"name") . ".") false;
|
||||||
|
@ -118,15 +119,16 @@ $WaitFullyConnected;
|
||||||
} else={
|
} else={
|
||||||
:local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ];
|
:local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ];
|
||||||
|
|
||||||
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "Certificate warning!") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A certificate on " . $Identity . " " . $State . ".\n\n" . \
|
subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning!"); \
|
||||||
|
message=("A certificate on " . $Identity . " " . $State . ".\n\n" . \
|
||||||
"Name: " . ($CertVal->"name") . "\n" . \
|
"Name: " . ($CertVal->"name") . "\n" . \
|
||||||
"CommonName: " . ($CertVal->"common-name") . "\n" . \
|
"CommonName: " . ($CertVal->"common-name") . "\n" . \
|
||||||
"Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
"Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
||||||
"Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \
|
"Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \
|
||||||
"Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \
|
"Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \
|
||||||
"Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\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 . \
|
$LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " " . $State . \
|
||||||
", it is invalid after " . ($CertVal->"invalid-after") . ".") false;
|
", it is invalid after " . ($CertVal->"invalid-after") . ".") false;
|
||||||
}
|
}
|
||||||
|
|
33
check-health
33
check-health
|
@ -18,7 +18,7 @@
|
||||||
:global Identity;
|
:global Identity;
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
:local FormatVoltage do={
|
:local FormatVoltage do={
|
||||||
|
@ -42,10 +42,11 @@
|
||||||
[ :typeof $Voltage ] = "num") do={
|
[ :typeof $Voltage ] = "num") do={
|
||||||
:if ($CheckHealthLast->$Name * (100 + $CheckHealthVoltagePercent) < $Voltage * 100 || \
|
:if ($CheckHealthLast->$Name * (100 + $CheckHealthVoltagePercent) < $Voltage * 100 || \
|
||||||
$CheckHealthLast->$Name * 100 > $Voltage * (100 + $CheckHealthVoltagePercent)) do={
|
$CheckHealthLast->$Name * 100 > $Voltage * (100 + $CheckHealthVoltagePercent)) do={
|
||||||
$SendNotification ([ $SymbolForNotification "high-voltage-sign" ] . "Health warning: " . $Name) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("The " . $Name . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \
|
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" . \
|
"old value: " . [ $FormatVoltage ($CheckHealthLast->$Name) ] . "\n" . \
|
||||||
"new value: " . [ $FormatVoltage $Voltage ]);
|
"new value: " . [ $FormatVoltage $Voltage ]) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,13 +57,15 @@
|
||||||
[ :typeof $PSU ] = "str") do={
|
[ :typeof $PSU ] = "str") do={
|
||||||
:if ($CheckHealthLast->$Name = "ok" && \
|
:if ($CheckHealthLast->$Name = "ok" && \
|
||||||
$PSU != "ok") do={
|
$PSU != "ok") do={
|
||||||
$SendNotification ([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $Name) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("The power supply unit '" . $Name . "' on " . $Identity . " failed!");
|
subject=([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $Name); \
|
||||||
|
message=("The power supply unit '" . $Name . "' on " . $Identity . " failed!") });
|
||||||
}
|
}
|
||||||
:if ($CheckHealthLast->$Name != "ok" && \
|
:if ($CheckHealthLast->$Name != "ok" && \
|
||||||
$PSU = "ok") do={
|
$PSU = "ok") do={
|
||||||
$SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("The power supply unit '" . $Name . "' on " . $Identity . " recovered!");
|
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 && \
|
:if ($Temperature > $CheckHealthTemperature->$Name && \
|
||||||
$CheckHealthTemperatureNotified->$Name != true) do={
|
$CheckHealthTemperatureNotified->$Name != true) do={
|
||||||
$SendNotification ([ $SymbolForNotification "fire" ] . "Health warning: " . $Name) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("The " . $Name . " on " . $Identity . " is above threshold: " . \
|
subject=([ $SymbolForNotification "fire" ] . "Health warning: " . $Name); \
|
||||||
$Temperature . "\C2\B0" . "C");
|
message=("The " . $Name . " on " . $Identity . " is above threshold: " . \
|
||||||
|
$Temperature . "\C2\B0" . "C") });
|
||||||
:set ($CheckHealthTemperatureNotified->$Name) true;
|
:set ($CheckHealthTemperatureNotified->$Name) true;
|
||||||
}
|
}
|
||||||
:if ($Temperature <= ($CheckHealthTemperature->$Name - $CheckHealthTemperatureDeviation) && \
|
:if ($Temperature <= ($CheckHealthTemperature->$Name - $CheckHealthTemperatureDeviation) && \
|
||||||
$CheckHealthTemperatureNotified->$Name = true) do={
|
$CheckHealthTemperatureNotified->$Name = true) do={
|
||||||
$SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("The " . $Name . " on " . $Identity . " dropped below threshold: " . \
|
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \
|
||||||
$Temperature . "\C2\B0" . "C");
|
message=("The " . $Name . " on " . $Identity . " dropped below threshold: " . \
|
||||||
|
$Temperature . "\C2\B0" . "C") });
|
||||||
:set ($CheckHealthTemperatureNotified->$Name) false;
|
:set ($CheckHealthTemperatureNotified->$Name) false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
:foreach Interface in=[ / interface lte find ] do={
|
:foreach Interface in=[ / interface lte find ] do={
|
||||||
|
@ -29,12 +29,13 @@
|
||||||
} else={
|
} else={
|
||||||
:if (($Firmware->"installed") != ($Firmware->"latest")) do={
|
:if (($Firmware->"installed") != ($Firmware->"latest")) do={
|
||||||
:local Info [ / interface lte info $Interface once as-value ];
|
:local Info [ / interface lte info $Interface once as-value ];
|
||||||
$SendNotification ([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A new firmware version " . ($Firmware->"latest") . " is available for " . \
|
subject=([ $SymbolForNotification "sparkles" ] . "LTE firmware upgrade"); \
|
||||||
|
message=("A new firmware version " . ($Firmware->"latest") . " is available for " . \
|
||||||
"LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \
|
"LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \
|
||||||
"Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \
|
"Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \
|
||||||
"Installed: " . ($Firmware->"installed") . "\n" . \
|
"Installed: " . ($Firmware->"installed") . "\n" . \
|
||||||
"Available: " . ($Firmware->"latest")) "" "true";
|
"Available: " . ($Firmware->"latest")); silent=true });
|
||||||
:set SentLteFirmwareUpgradeNotification ($Firmware->"latest");
|
:set SentLteFirmwareUpgradeNotification ($Firmware->"latest");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
:global DeviceInfo;
|
:global DeviceInfo;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ScriptFromTerminal;
|
:global ScriptFromTerminal;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global VersionToNum;
|
:global VersionToNum;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
@ -65,18 +65,20 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false;
|
||||||
:if ($NumInstalled < $NumLatest) do={
|
:if ($NumInstalled < $NumLatest) do={
|
||||||
:if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={
|
:if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={
|
||||||
$LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is a patch release, updating...") false;
|
$LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is a patch release, updating...") false;
|
||||||
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \
|
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \
|
||||||
", updating on " . $Identity . "...") $Link "true";
|
message=("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \
|
||||||
|
", updating on " . $Identity . "..."); link=$Link; silent=true });
|
||||||
$DoUpdate;
|
$DoUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ($SafeUpdateNeighbor = true && [ :len [ / ip neighbor find where \
|
:if ($SafeUpdateNeighbor = true && [ :len [ / ip neighbor find where \
|
||||||
version=($Update->"latest-version" . " (" . $Update->"channel" . ")") ] ] > 0) do={
|
version=($Update->"latest-version" . " (" . $Update->"channel" . ")") ] ] > 0) do={
|
||||||
$LogPrintExit2 info $0 ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false;
|
$LogPrintExit2 info $0 ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false;
|
||||||
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \
|
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \
|
||||||
", updating on " . $Identity . "...") $Link "true";
|
message=("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \
|
||||||
|
", updating on " . $Identity . "..."); link=$Link; silent=true });
|
||||||
$DoUpdate;
|
$DoUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,9 +93,10 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false;
|
||||||
}
|
}
|
||||||
:if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={
|
:if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={
|
||||||
$LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is considered safe, updating...") false;
|
$LogPrintExit2 info $0 ("Version " . $Update->"latest-version" . " is considered safe, updating...") false;
|
||||||
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \
|
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \
|
||||||
", updating on " . $Identity . "...") $Link "true";
|
message=("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \
|
||||||
|
", updating on " . $Identity . "..."); link=$Link; silent=true });
|
||||||
$DoUpdate;
|
$DoUpdate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,10 +115,11 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false;
|
||||||
$Update->"latest-version" . ".") true;
|
$Update->"latest-version" . ".") true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A new RouterOS version " . ($Update->"latest-version") . \
|
subject=([ $SymbolForNotification "sparkles" ] . "RouterOS update"); \
|
||||||
|
message=("A new RouterOS version " . ($Update->"latest-version") . \
|
||||||
" is available for " . $Identity . ".\n\n" . \
|
" is available for " . $Identity . ".\n\n" . \
|
||||||
[ $DeviceInfo ]) $Link "true";
|
[ $DeviceInfo ]); link=$Link; silent=true });
|
||||||
:set SentRouterosUpdateNotification ($Update->"latest-version");
|
:set SentRouterosUpdateNotification ($Update->"latest-version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,10 +129,11 @@ $LogPrintExit2 debug $0 ("Checking for updates...") false;
|
||||||
$Update->"latest-version" . ".") true;
|
$Update->"latest-version" . ".") true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "RouterOS version") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A different RouterOS version " . ($Update->"latest-version") . \
|
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" . \
|
" 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") . \
|
$LogPrintExit2 info $0 ("A different RouterOS version " . ($Update->"latest-version") . \
|
||||||
" is available for downgrade.") false;
|
" is available for downgrade.") false;
|
||||||
:set SentRouterosUpdateNotification ($Update->"latest-version");
|
:set SentRouterosUpdateNotification ($Update->"latest-version");
|
||||||
|
|
14
cloud-backup
14
cloud-backup
|
@ -18,7 +18,7 @@
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global RandomDelay;
|
:global RandomDelay;
|
||||||
:global ScriptFromTerminal;
|
:global ScriptFromTerminal;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
|
@ -41,14 +41,16 @@ $WaitFullyConnected;
|
||||||
}
|
}
|
||||||
:local Cloud [ / system backup cloud get ([ find ]->0) ];
|
:local Cloud [ / system backup cloud get ([ find ]->0) ];
|
||||||
|
|
||||||
$SendNotification ([ $SymbolForNotification "floppy-disk" ] . "Cloud backup") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Uploaded backup for " . $Identity . " to cloud.\n\n" . \
|
subject=([ $SymbolForNotification "floppy-disk" ] . "Cloud backup"); \
|
||||||
|
message=("Uploaded backup for " . $Identity . " to cloud.\n\n" . \
|
||||||
[ $DeviceInfo ] . "\n\n" . \
|
[ $DeviceInfo ] . "\n\n" . \
|
||||||
"Name: " . $Cloud->"name" . "\n" . \
|
"Name: " . $Cloud->"name" . "\n" . \
|
||||||
"Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\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={
|
} on-error={
|
||||||
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]);
|
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;
|
$LogPrintExit2 error $0 ("Failed uploading backup for " . $Identity . " to cloud!") true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
$ScriptLock $0;
|
$ScriptLock $0;
|
||||||
|
@ -56,8 +56,9 @@ $ScriptLock $0;
|
||||||
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
|
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
|
||||||
$LogPrintExit2 info $0 $Message false;
|
$LogPrintExit2 info $0 $Message false;
|
||||||
/ caps-man access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
|
/ caps-man access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
|
||||||
$SendNotification ([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \
|
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" . \
|
"Controller: " . $Identity . "\n" . \
|
||||||
"Interface: " . $Interface . "\n" . \
|
"Interface: " . $Interface . "\n" . \
|
||||||
"SSID: " . $Ssid . "\n" . \
|
"SSID: " . $Ssid . "\n" . \
|
||||||
|
@ -66,7 +67,7 @@ $ScriptLock $0;
|
||||||
"Hostname: " . $HostName . "\n" . \
|
"Hostname: " . $HostName . "\n" . \
|
||||||
"Address: " . $Address . "\n" . \
|
"Address: " . $Address . "\n" . \
|
||||||
"DNS name: " . $DnsName . "\n" . \
|
"DNS name: " . $DnsName . "\n" . \
|
||||||
"Date: " . $DateTime);
|
"Date: " . $DateTime) });
|
||||||
} else={
|
} else={
|
||||||
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
|
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
|
||||||
[ / caps-man access-list get $AccessList comment ]) false;
|
[ / caps-man access-list get $AccessList comment ]) false;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
$ScriptLock $0;
|
$ScriptLock $0;
|
||||||
|
@ -56,8 +56,9 @@ $ScriptLock $0;
|
||||||
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
|
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
|
||||||
$LogPrintExit2 info $0 $Message false;
|
$LogPrintExit2 info $0 $Message false;
|
||||||
/ interface wireless access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
|
/ interface wireless access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
|
||||||
$SendNotification ([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \
|
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" . \
|
"Controller: " . $Identity . "\n" . \
|
||||||
"Interface: " . $Interface . "\n" . \
|
"Interface: " . $Interface . "\n" . \
|
||||||
"SSID: " . $Ssid . "\n" . \
|
"SSID: " . $Ssid . "\n" . \
|
||||||
|
@ -66,7 +67,7 @@ $ScriptLock $0;
|
||||||
"Hostname: " . $HostName . "\n" . \
|
"Hostname: " . $HostName . "\n" . \
|
||||||
"Address: " . $Address . "\n" . \
|
"Address: " . $Address . "\n" . \
|
||||||
"DNS name: " . $DnsName . "\n" . \
|
"DNS name: " . $DnsName . "\n" . \
|
||||||
"Date: " . $DateTime);
|
"Date: " . $DateTime) });
|
||||||
} else={
|
} else={
|
||||||
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
|
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
|
||||||
[ / interface wireless access-list get $AccessList comment ]) false;
|
[ / interface wireless access-list get $AccessList comment ]) false;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
$ScriptLock $0;
|
$ScriptLock $0;
|
||||||
|
@ -58,8 +58,9 @@ $ScriptLock $0;
|
||||||
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
|
"first seen on " . $DateTime . " connected to SSID " . $Ssid . ", interface " . $Interface);
|
||||||
$LogPrintExit2 info $0 $Message false;
|
$LogPrintExit2 info $0 $Message false;
|
||||||
/ %PATH% access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
|
/ %PATH% access-list add place-before=$PlaceBefore comment=$Message mac-address=$Mac disabled=yes;
|
||||||
$SendNotification ([ $SymbolForNotification "mobile-phone" ] . $Mac . " connected to " . $Ssid) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("A device with unknown MAC address connected to " . $Ssid . " on " . $Identity . ".\n\n" . \
|
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" . \
|
"Controller: " . $Identity . "\n" . \
|
||||||
"Interface: " . $Interface . "\n" . \
|
"Interface: " . $Interface . "\n" . \
|
||||||
"SSID: " . $Ssid . "\n" . \
|
"SSID: " . $Ssid . "\n" . \
|
||||||
|
@ -68,7 +69,7 @@ $ScriptLock $0;
|
||||||
"Hostname: " . $HostName . "\n" . \
|
"Hostname: " . $HostName . "\n" . \
|
||||||
"Address: " . $Address . "\n" . \
|
"Address: " . $Address . "\n" . \
|
||||||
"DNS name: " . $DnsName . "\n" . \
|
"DNS name: " . $DnsName . "\n" . \
|
||||||
"Date: " . $DateTime);
|
"Date: " . $DateTime) });
|
||||||
} else={
|
} else={
|
||||||
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
|
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
|
||||||
[ / %PATH% access-list get $AccessList comment ]) false;
|
[ / %PATH% access-list get $AccessList comment ]) false;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
:global Identity;
|
:global Identity;
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
|
@ -81,12 +81,13 @@ $WaitFullyConnected;
|
||||||
:set Seen ($Seen, $Ssid);
|
:set Seen ($Seen, $Ssid);
|
||||||
:local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \
|
:local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
$SendNotification ([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("This is the daily PSK on " . $Identity . ":\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
"SSID: " . $Ssid . "\n" . \
|
"SSID: " . $Ssid . "\n" . \
|
||||||
"PSK: " . $NewPsk . "\n" . \
|
"PSK: " . $NewPsk . "\n" . \
|
||||||
"Date: " . $Date . "\n\n" . \
|
"Date: " . $Date . "\n\n" . \
|
||||||
"A client device specific rule must not exist!") $Link;
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
:global Identity;
|
:global Identity;
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
|
@ -81,12 +81,13 @@ $WaitFullyConnected;
|
||||||
:set Seen ($Seen, $Ssid);
|
:set Seen ($Seen, $Ssid);
|
||||||
:local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \
|
:local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
$SendNotification ([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("This is the daily PSK on " . $Identity . ":\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
"SSID: " . $Ssid . "\n" . \
|
"SSID: " . $Ssid . "\n" . \
|
||||||
"PSK: " . $NewPsk . "\n" . \
|
"PSK: " . $NewPsk . "\n" . \
|
||||||
"Date: " . $Date . "\n\n" . \
|
"Date: " . $Date . "\n\n" . \
|
||||||
"A client device specific rule must not exist!") $Link;
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
:global Identity;
|
:global Identity;
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
|
@ -87,12 +87,13 @@ $WaitFullyConnected;
|
||||||
:set Seen ($Seen, $Ssid);
|
:set Seen ($Seen, $Ssid);
|
||||||
:local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \
|
:local Link ("https://www.eworm.de/cgi-bin/cqrlogo-wifi.cgi" . \
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
$SendNotification ([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("This is the daily PSK on " . $Identity . ":\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
"SSID: " . $Ssid . "\n" . \
|
"SSID: " . $Ssid . "\n" . \
|
||||||
"PSK: " . $NewPsk . "\n" . \
|
"PSK: " . $NewPsk . "\n" . \
|
||||||
"Date: " . $Date . "\n\n" . \
|
"Date: " . $Date . "\n\n" . \
|
||||||
"A client device specific rule must not exist!") $Link;
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
:global GlobalConfigVersion 47;
|
:global GlobalConfigVersion 48;
|
||||||
|
|
||||||
# This is used for DNS and backup file.
|
# This is used for DNS and backup file.
|
||||||
:global Domain "example.com";
|
:global Domain "example.com";
|
||||||
|
@ -33,6 +33,13 @@
|
||||||
# This is whether or not to send Telegram messages with fixed-width font.
|
# This is whether or not to send Telegram messages with fixed-width font.
|
||||||
:global TelegramFixedWidthFont true;
|
: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.
|
# Toggle this to disable symbols in notifications.
|
||||||
:global NotificationsWithSymbols true;
|
:global NotificationsWithSymbols true;
|
||||||
# Toggle this to disable color output in terminal/cli.
|
# Toggle this to disable color output in terminal/cli.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
# Comment or remove to disable news and change notifications.
|
# Comment or remove to disable news and change notifications.
|
||||||
:global GlobalConfigVersion 47;
|
:global GlobalConfigVersion 48;
|
||||||
|
|
||||||
# Copy configuration from global-config here and modify it.
|
# Copy configuration from global-config here and modify it.
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
45="We have a Telegram Group! Come along and say hello: https://t.me/routeros_scripts";
|
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.";
|
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.";
|
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
|
# Migration steps to be applied on script updates
|
||||||
|
|
118
global-functions
118
global-functions
|
@ -8,7 +8,7 @@
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/
|
# https://git.eworm.de/cgit/routeros-scripts/about/
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 47;
|
:global ExpectedConfigVersion 48;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
@ -24,6 +24,7 @@
|
||||||
:global DeviceInfo;
|
:global DeviceInfo;
|
||||||
:global DNSIsResolving;
|
:global DNSIsResolving;
|
||||||
:global DownloadPackage;
|
:global DownloadPackage;
|
||||||
|
:global EitherOr;
|
||||||
:global EscapeForRegEx;
|
:global EscapeForRegEx;
|
||||||
:global FlushEmailQueue;
|
:global FlushEmailQueue;
|
||||||
:global FlushTelegramQueue;
|
:global FlushTelegramQueue;
|
||||||
|
@ -43,8 +44,11 @@
|
||||||
:global ScriptInstallUpdate;
|
:global ScriptInstallUpdate;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
:global SendEMail;
|
:global SendEMail;
|
||||||
|
:global SendEMail2;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
|
:global SendNotification2;
|
||||||
:global SendTelegram;
|
:global SendTelegram;
|
||||||
|
:global SendTelegram2;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolByUnicodeName;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global TimeIsSync;
|
:global TimeIsSync;
|
||||||
|
@ -290,6 +294,16 @@
|
||||||
:return false;
|
: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
|
# escape for regular expression
|
||||||
:set EscapeForRegEx do={
|
:set EscapeForRegEx do={
|
||||||
:local Input [ :tostr $1 ];
|
:local Input [ :tostr $1 ];
|
||||||
|
@ -356,7 +370,6 @@
|
||||||
# flush telegram queue
|
# flush telegram queue
|
||||||
:set FlushTelegramQueue do={
|
:set FlushTelegramQueue do={
|
||||||
:global TelegramQueue;
|
:global TelegramQueue;
|
||||||
:global TelegramTokenId;
|
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
|
|
||||||
|
@ -371,7 +384,7 @@
|
||||||
:if ([ :typeof $Message ] = "array" ) do={
|
:if ([ :typeof $Message ] = "array" ) do={
|
||||||
:do {
|
:do {
|
||||||
/ tool fetch check-certificate=yes-without-crl output=none http-method=post \
|
/ 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") . \
|
http-data=("chat_id=" . ($Message->"chatid") . \
|
||||||
"&disable_notification=" . ($Message->"silent") . \
|
"&disable_notification=" . ($Message->"silent") . \
|
||||||
"&disable_web_page_preview=true&parse_mode=" . ($Message->"parsemode") . \
|
"&disable_web_page_preview=true&parse_mode=" . ($Message->"parsemode") . \
|
||||||
|
@ -675,7 +688,7 @@
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ParseKeyValueStore;
|
:global ParseKeyValueStore;
|
||||||
:global ScriptInstallUpdate;
|
:global ScriptInstallUpdate;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global ValidateSyntax;
|
:global ValidateSyntax;
|
||||||
|
|
||||||
|
@ -842,8 +855,9 @@
|
||||||
:set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate";
|
:set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate";
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
$NotificationMessage $Link;
|
subject=([ $SymbolForNotification "pushpin" ] . "News and configuration changes"); \
|
||||||
|
message=$NotificationMessage; link=$Link });
|
||||||
:set SentConfigChangesNotification $ExpectedConfigVersion;
|
: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={
|
:set SendEMail do={
|
||||||
:local Subject [ :tostr $1 ];
|
:global SendEMail2;
|
||||||
:local Message [ :tostr $2 ];
|
|
||||||
:local Link [ :tostr $3 ];
|
$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 Identity;
|
||||||
:global EmailGeneralTo;
|
:global EmailGeneralTo;
|
||||||
|
:global EmailGeneralToOverride;
|
||||||
:global EmailGeneralCc;
|
:global EmailGeneralCc;
|
||||||
|
:global EmailGeneralCcOverride;
|
||||||
:global EmailQueue;
|
:global EmailQueue;
|
||||||
|
|
||||||
|
:global EitherOr;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global QuotedPrintable;
|
: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;
|
:return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -891,10 +916,10 @@
|
||||||
}
|
}
|
||||||
:local Signature [ / system note get note ];
|
:local Signature [ / system note get note ];
|
||||||
:set ($EmailQueue->[ :len $EmailQueue ]) {
|
:set ($EmailQueue->[ :len $EmailQueue ]) {
|
||||||
to=$EmailGeneralTo; cc=$EmailGeneralCc;
|
to=$To; cc=$Cc;
|
||||||
subject=[ $QuotedPrintable ("[" . $Identity . "] " . $Subject) ];
|
subject=[ $QuotedPrintable ("[" . $Identity . "] " . ($Notification->"subject")) ];
|
||||||
body=($Message . \
|
body=(($Notification->"message") . \
|
||||||
[ $IfThenElse ([ :len $Link ] > 0) ("\n\n" . $Link) "" ] . \
|
[ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \
|
||||||
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) };
|
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) };
|
||||||
:if ([ :len [ / system scheduler find where name="FlushEmailQueue" ] ] = 0) do={
|
:if ([ :len [ / system scheduler find where name="FlushEmailQueue" ] ] = 0) do={
|
||||||
/ system scheduler add name=FlushEmailQueue interval=1s start-time=startup \
|
/ system scheduler add name=FlushEmailQueue interval=1s start-time=startup \
|
||||||
|
@ -902,27 +927,34 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# send notification via e-mail and telegram
|
# send notification via e-mail and telegram - expects at lease two string arguments
|
||||||
# Note that attachment is ignored for telegram, silent is ignored for e-mail!
|
|
||||||
:set SendNotification do={
|
:set SendNotification do={
|
||||||
:local Subject [ :tostr $1 ];
|
:global SendNotification2;
|
||||||
:local Message [ :tostr $2 ];
|
|
||||||
:local Link [ :tostr $3 ];
|
|
||||||
:local Silent [ :tostr $4 ];
|
|
||||||
|
|
||||||
:global SendEMail;
|
$SendNotification2 ({ subject=$1; message=$2; link=$3; silent=$4 });
|
||||||
:global SendTelegram;
|
|
||||||
|
|
||||||
$SendEMail $Subject $Message $Link;
|
|
||||||
$SendTelegram $Subject $Message $Link $Silent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# send notification via telegram
|
# send notification via e-mail and telegram - expects one array argument
|
||||||
|
:set SendNotification2 do={
|
||||||
|
:local Notification $1;
|
||||||
|
|
||||||
|
:global SendEMail2;
|
||||||
|
:global SendTelegram2;
|
||||||
|
|
||||||
|
$SendEMail2 $Notification;
|
||||||
|
$SendTelegram2 $Notification;
|
||||||
|
}
|
||||||
|
|
||||||
|
# send notification via telegram - expects at lease two string arguments
|
||||||
:set SendTelegram do={
|
:set SendTelegram do={
|
||||||
:local Subject [ :tostr $1 ];
|
:global SendTelegram2;
|
||||||
:local Message [ :tostr $2 ];
|
|
||||||
:local Link [ :tostr $3 ];
|
$SendTelegram2 ({ subject=$1; message=$2; link=$3; silent=$4 });
|
||||||
:local Silent [ :tostr $4 ];
|
}
|
||||||
|
|
||||||
|
# send notification via telegram - expects one array argument
|
||||||
|
:set SendTelegram2 do={
|
||||||
|
:local Notification $1;
|
||||||
|
|
||||||
:global Identity;
|
:global Identity;
|
||||||
:global TelegramChatId;
|
:global TelegramChatId;
|
||||||
|
@ -930,9 +962,11 @@
|
||||||
:global TelegramFixedWidthFont;
|
:global TelegramFixedWidthFont;
|
||||||
:global TelegramQueue;
|
:global TelegramQueue;
|
||||||
:global TelegramTokenId;
|
:global TelegramTokenId;
|
||||||
|
:global TelegramTokenIdOverride;
|
||||||
|
|
||||||
:global CertificateAvailable;
|
:global CertificateAvailable;
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
|
:global EitherOr;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
@ -965,18 +999,16 @@
|
||||||
:return $Return;
|
:return $Return;
|
||||||
}
|
}
|
||||||
|
|
||||||
:local ChatId $TelegramChatId;
|
:local ChatId [ $EitherOr ($TelegramChatIdOverride->($Notification->"origin")) $TelegramChatId ];
|
||||||
:if ([ :len $TelegramChatIdOverride ] > 0) do={
|
:local TokenId [ $EitherOr ($TelegramTokenIdOverride->($Notification->"origin")) $TelegramTokenId ];
|
||||||
:set ChatId $TelegramChatIdOverride;
|
|
||||||
}
|
|
||||||
|
|
||||||
:if ([ :len $TelegramTokenId ] = 0 || [ :len $ChatId ] = 0) do={
|
:if ([ :len $TokenId ] = 0 || [ :len $ChatId ] = 0) do={
|
||||||
:return false;
|
:return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
:local Truncated false;
|
:local Truncated false;
|
||||||
:local LenLink [ :len $Link ];
|
:local LenLink [ :len ($Notification->"link") ];
|
||||||
:local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message);
|
:local Text ("[" . $Identity . "] " . ($Notification->"subject") . "\n\n" . ($Notification->"message"));
|
||||||
:local LenText [ :len $Text ];
|
:local LenText [ :len $Text ];
|
||||||
:if ($LenText > (3968 - $LenLink)) do={
|
:if ($LenText > (3968 - $LenLink)) do={
|
||||||
:set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ];
|
:set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ];
|
||||||
|
@ -985,7 +1017,7 @@
|
||||||
:set Text [ $EscapeMD $Text "body" ];
|
:set Text [ $EscapeMD $Text "body" ];
|
||||||
}
|
}
|
||||||
:if ($LenLink > 0) do={
|
: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={
|
:if ($Truncated = true) do={
|
||||||
:set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \
|
:set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \
|
||||||
|
@ -1000,8 +1032,8 @@
|
||||||
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true;
|
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true;
|
||||||
}
|
}
|
||||||
/ tool fetch check-certificate=yes-without-crl output=none http-method=post \
|
/ 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=" . $Silent . \
|
http-data=("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \
|
||||||
"&disable_web_page_preview=true&parse_mode=" . $ParseMode . "&text=" . $Text) as-value;
|
"&disable_web_page_preview=true&parse_mode=" . $ParseMode . "&text=" . $Text) as-value;
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 info $0 ("Failed sending telegram notification! Queuing...") false;
|
$LogPrintExit2 info $0 ("Failed sending telegram notification! Queuing...") false;
|
||||||
|
@ -1012,8 +1044,8 @@
|
||||||
:set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \
|
:set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \
|
||||||
[ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \
|
[ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \
|
||||||
" " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]);
|
" " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]);
|
||||||
:set ($TelegramQueue->[ :len $TelegramQueue ]) {
|
:set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId;
|
||||||
chatid=$ChatId; parsemode=$ParseMode; text=$Text; silent=$Silent };
|
parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") };
|
||||||
:if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={
|
:if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={
|
||||||
/ system scheduler add name=FlushTelegramQueue interval=1m start-time=startup \
|
/ system scheduler add name=FlushTelegramQueue interval=1m start-time=startup \
|
||||||
on-event=":global FlushTelegramQueue; \$FlushTelegramQueue;";
|
on-event=":global FlushTelegramQueue; \$FlushTelegramQueue;";
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global QuotedPrintable;
|
:global QuotedPrintable;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
|
@ -71,11 +71,12 @@ $WaitFullyConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ($Count > 0) do={
|
:if ($Count > 0) do={
|
||||||
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \
|
subject=([ $SymbolForNotification "warning-sign" ] . "Log Forwarding"); \
|
||||||
|
message=("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) \
|
||||||
"this message" ("these " . $Count . " messages") ] . " after " . \
|
"this message" ("these " . $Count . " messages") ] . " after " . \
|
||||||
[ / system resource get uptime ] . " uptime." . [ $IfThenElse ($Duplicates = true) \
|
[ / system resource get uptime ] . " uptime." . [ $IfThenElse ($Duplicates = true) \
|
||||||
(" Multi-repeated messages have been skipped.") ] . "\n" . $Messages);
|
(" Multi-repeated messages have been skipped.") ] . "\n" . $Messages) });
|
||||||
|
|
||||||
:set LogForwardRateLimit ($LogForwardRateLimit + 10);
|
:set LogForwardRateLimit ($LogForwardRateLimit + 10);
|
||||||
:set LogForwardLast ($MessageVal->".id");
|
:set LogForwardLast ($MessageVal->".id");
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ParseKeyValueStore;
|
:global ParseKeyValueStore;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global ValidateSyntax;
|
:global ValidateSyntax;
|
||||||
|
|
||||||
|
@ -38,9 +38,10 @@
|
||||||
:local Count ($Metric->"count");
|
:local Count ($Metric->"count");
|
||||||
:set ($Metric->"count") 0;
|
:set ($Metric->"count") 0;
|
||||||
:if ($Metric->"notified" = true) do={
|
:if ($Metric->"notified" = true) do={
|
||||||
$SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \
|
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \
|
||||||
"It was down for " . $Count . " checks since " . ($Metric->"since") . ".");
|
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 ([ :typeof ($HostInfo->"up-hook") ] = "str") do={
|
||||||
:if ([ $ValidateSyntax ($HostInfo->"up-hook") ] = true) do={
|
:if ([ $ValidateSyntax ($HostInfo->"up-hook") ] = true) do={
|
||||||
$LogPrintExit2 info $0 ("Running hook on host " . $HostName . " up: " . ($HostInfo->"up-hook")) false;
|
$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.") ] \
|
($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \
|
||||||
("parent host " . $Parent . " is down.") ]) false;
|
("parent host " . $Parent . " is down.") ]) false;
|
||||||
:if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={
|
:if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={
|
||||||
$SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".");
|
subject=([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down"); \
|
||||||
|
message=("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . ".") });
|
||||||
:set ($Metric->"notified") true;
|
:set ($Metric->"notified") true;
|
||||||
:if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={
|
:if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={
|
||||||
:if ([ $ValidateSyntax ($HostInfo->"down-hook") ] = true) do={
|
:if ([ $ValidateSyntax ($HostInfo->"down-hook") ] = true) do={
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
|
@ -51,9 +51,10 @@ $WaitFullyConnected;
|
||||||
|
|
||||||
:if ([ :len $Messages ] > 0) do={
|
:if ([ :len $Messages ] > 0) do={
|
||||||
:local Count [ :len $Delete ];
|
:local Count [ :len $Delete ];
|
||||||
$SendNotification ([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone) \
|
$SendNotification2 ({ origin=$0; \
|
||||||
("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \
|
subject=([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone); \
|
||||||
" by " . $Identity . " from " . $Phone . ":" . $Messages);
|
message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \
|
||||||
|
" by " . $Identity . " from " . $Phone . ":" . $Messages) });
|
||||||
:foreach Sms in=$Delete do={
|
:foreach Sms in=$Delete do={
|
||||||
/ tool sms inbox remove $Sms;
|
/ tool sms inbox remove $Sms;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
:global RandomDelay;
|
:global RandomDelay;
|
||||||
:global ScriptFromTerminal;
|
:global ScriptFromTerminal;
|
||||||
:global SendNotification;
|
:global SendNotification2;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
:global WaitFullyConnected;
|
: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 "warning-sign" ] . "Backup & Config upload with failure") \
|
||||||
([ $SymbolForNotification "floppy-disk" ] . "Backup & Config upload") ] \
|
([ $SymbolForNotification "floppy-disk" ] . "Backup & Config upload") ]; \
|
||||||
("Backup and config export upload for " . $Identity . ".\n\n" . \
|
message=("Backup and config export upload for " . $Identity . ".\n\n" . \
|
||||||
[ $DeviceInfo ] . "\n\n" . \
|
[ $DeviceInfo ] . "\n\n" . \
|
||||||
"Backup file: " . $BackupFile . "\n" . \
|
"Backup file: " . $BackupFile . "\n" . \
|
||||||
"Config file: " . $ConfigFile) "" "true";
|
"Config file: " . $ConfigFile); silent=true });
|
||||||
|
|
||||||
:if ($Failed = 1) do={
|
:if ($Failed = 1) do={
|
||||||
:error "An error occured!";
|
:error "An error occured!";
|
||||||
|
|
Loading…
Reference in a new issue