diff options
-rw-r--r-- | check-health | 12 | ||||
-rw-r--r-- | check-routeros-update | 4 | ||||
-rw-r--r-- | global-config | 5 | ||||
-rw-r--r-- | global-config-overlay | 2 | ||||
-rw-r--r-- | global-config.changes | 1 | ||||
-rw-r--r-- | global-functions | 15 | ||||
-rw-r--r-- | log-forward | 4 | ||||
-rw-r--r-- | netwatch-notify | 6 | ||||
-rw-r--r-- | sms-forward | 4 |
9 files changed, 35 insertions, 18 deletions
diff --git a/check-health b/check-health index a63483e..33ad59f 100644 --- a/check-health +++ b/check-health @@ -13,7 +13,7 @@ :global LogPrintExit; :global SendNotification; -:global SymbolByUnicodeName; +:global SymbolForNotification; :local FormatVoltage do={ :local Voltage [ :tonum $1 ]; @@ -27,7 +27,7 @@ [ :typeof ($CheckHealthCurrent->$Voltage) ] = "num") do={ :if ($CheckHealthLast->$Voltage * (100 + $CheckHealthVoltagePercent) < $CheckHealthCurrent->$Voltage * 100 || \ $CheckHealthLast->$Voltage * 100 > $CheckHealthCurrent->$Voltage * (100 + $CheckHealthVoltagePercent)) do={ - $SendNotification ([ $SymbolByUnicodeName "high-voltage-sign" ] . " Health warning: " . $Voltage) \ + $SendNotification ([ $SymbolForNotification "high-voltage-sign" ] . "Health warning: " . $Voltage) \ ("The " . $Voltage . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \ "old value: " . [ $FormatVoltage ($CheckHealthLast->$Voltage) ] . "\n" . \ "new value: " . [ $FormatVoltage ($CheckHealthCurrent->$Voltage) ]); @@ -40,12 +40,12 @@ [ :typeof ($CheckHealthCurrent->($PSU . "-state")) ] = "str") do={ :if ($CheckHealthLast->($PSU . "-state") = "ok" && \ $CheckHealthCurrent->($PSU . "-state") != "ok") do={ - $SendNotification ([ $SymbolByUnicodeName "cross-mark" ] . " Health warning: " . $PSU . " state") \ + $SendNotification ([ $SymbolForNotification "cross-mark" ] . "Health warning: " . $PSU . " state") \ ("The power supply unit '" . $PSU . "' on " . $Identity . " failed!"); } :if ($CheckHealthLast->($PSU . "-state") != "ok" && \ $CheckHealthCurrent->($PSU . "-state") = "ok") do={ - $SendNotification ([ $SymbolByUnicodeName "white-heavy-check-mark" ] . " Health recovery: " . $PSU . " state") \ + $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $PSU . " state") \ ("The power supply unit '" . $PSU . "' on " . $Identity . " recovered!"); } } @@ -60,13 +60,13 @@ } :if ($CheckHealthLast->$Temperature <= $CheckHealthTemperature->$Temperature && \ $CheckHealthCurrent->$Temperature > $CheckHealthTemperature->$Temperature) do={ - $SendNotification ([ $SymbolByUnicodeName "fire" ] . " Health warning: " . $Temperature) \ + $SendNotification ([ $SymbolForNotification "fire" ] . "Health warning: " . $Temperature) \ ("The " . $Temperature . " on " . $Identity . " is above threshold: " . \ $CheckHealthCurrent->$Temperature . "\C2\B0" . "C"); } :if ($CheckHealthLast->$Temperature > $CheckHealthTemperature->$Temperature && \ $CheckHealthCurrent->$Temperature <= $CheckHealthTemperature->$Temperature) do={ - $SendNotification ([ $SymbolByUnicodeName "white-heavy-check-mark" ] . " Health recovery: " . $Temperature) \ + $SendNotification ([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Temperature) \ ("The " . $Temperature . " on " . $Identity . " dropped below threshold: " . \ $CheckHealthCurrent->$Temperature . "\C2\B0" . "C"); } diff --git a/check-routeros-update b/check-routeros-update index 8b1b54f..ee018c0 100644 --- a/check-routeros-update +++ b/check-routeros-update @@ -15,7 +15,7 @@ :global LogPrintExit; :global ScriptFromTerminal; :global SendNotification; -:global SymbolByUnicodeName; +:global SymbolForNotification; :global VersionToNum; :local DoUpdate do={ @@ -89,7 +89,7 @@ $Update->"latest-version" . ".") true; } - $SendNotification ([ $SymbolByUnicodeName "sparkles" ] . " RouterOS update") \ + $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ ("A new RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ".\n\n" . \ [ $DeviceInfo ] . "\n\n" . \ diff --git a/global-config b/global-config index 87ac2c7..4e5fd4a 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 23; +:global GlobalConfigVersion 24; # This is used for DNS and backup file. :global Domain "example.com"; @@ -28,6 +28,9 @@ #:global TelegramTokenId "123456:ABCDEF-GHI"; #:global TelegramChatId "12345678"; +# Toggle this to disable symbols in notifications. +:global NotificationsWithSymbols true; + # This defines what backups to generate and what password to use. :global BackupSendBinary false; :global BackupSendExport true; diff --git a/global-config-overlay b/global-config-overlay index 676db65..001128d 100644 --- a/global-config-overlay +++ b/global-config-overlay @@ -9,7 +9,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 change notifications. -:global GlobalConfigVersion 23; +:global GlobalConfigVersion 24; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index d3ff78f..82d67d7 100644 --- a/global-config.changes +++ b/global-config.changes @@ -27,4 +27,5 @@ 21="Added support for installing patch updates automatically by 'check-routeros-update'"; 22="Dropped '\$ScriptUpdatesIgnore' from global configuration, auto-migrating to ignore flag in comment" 23="Added 'log-forward' with configurable filter, which replaces 'early-errors'"; + 24="Made symbols in notifications configurable."; }; diff --git a/global-functions b/global-functions index ba9142f..0eb0e4c 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 23; +:global ExpectedConfigVersion 24; # global variables not to be changed by user :global GlobalFunctionsReady false; @@ -41,6 +41,7 @@ :global SendNotification; :global SendTelegram; :global SymbolByUnicodeName; +:global SymbolForNotification; :global TimeIsSync; :global UrlEncode; :global VersionToNum; @@ -747,6 +748,18 @@ :return ($Symbols->$1); } +# return symbol for notification +:set SymbolForNotification do={ + :global NotificationsWithSymbols; + + :global SymbolByUnicodeName; + + :if ($NotificationsWithSymbols != true) do={ + :return ""; + } + :return ([ $SymbolByUnicodeName $1 ] . " "); +} + # check if system time is sync :set TimeIsSync do={ :if ([ / system ntp client get enabled ] = true) do={ diff --git a/log-forward b/log-forward index 1bba504..0500072 100644 --- a/log-forward +++ b/log-forward @@ -13,7 +13,7 @@ :global LogPrintExit; :global MailServerIsUp; :global SendNotification; -:global SymbolByUnicodeName; +:global SymbolForNotification; :global WaitFullyConnected; $WaitFullyConnected; @@ -40,7 +40,7 @@ $WaitFullyConnected; } :if ($Count > 0) do={ - $SendNotification ([ $SymbolByUnicodeName "warning-sign" ] . " Log Forwarding") \ + $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \ ("The log on " . $Identity . " contains these " . $Count . " messages after " . \ [ / system resource get uptime ] . " uptime.\n" . $Messages); diff --git a/netwatch-notify b/netwatch-notify index 44f0657..0f464a9 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -11,7 +11,7 @@ :global ParseKeyValueStore; :global LogPrintExit; :global SendNotification; -:global SymbolByUnicodeName; +:global SymbolForNotification; :if ([ :typeof $NetwatchNotify ] = "nothing") do={ :set NetwatchNotify [ :toarray "" ]; @@ -32,7 +32,7 @@ :local Count ($Metric->"count"); :set ($Metric->"count") 0; :if ($Metric->"notified" = true) do={ - $SendNotification ([ $SymbolByUnicodeName "white-heavy-check-mark" ] . " Netwatch Notify: " . $HostName . " up") \ + $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."); :if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={ @@ -46,7 +46,7 @@ $LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \ $Metric->"count" . " checks.") false; :if ($Metric->"count" >= 5 && $Metric->"notified" != true) do={ - $SendNotification ([ $SymbolByUnicodeName "cross-mark" ] . " Netwatch Notify: " . $HostName . " down") \ + $SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \ ("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . "."); :set ($Metric->"notified") true; :if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={ diff --git a/sms-forward b/sms-forward index 88b39b9..8f38a4a 100644 --- a/sms-forward +++ b/sms-forward @@ -11,7 +11,7 @@ :global LogPrintExit; :global MailServerIsUp; :global SendNotification; -:global SymbolByUnicodeName; +:global SymbolForNotification; :global WaitFullyConnected; :if ([ / tool sms get receive-enabled ] = false) do={ @@ -47,7 +47,7 @@ $WaitFullyConnected; } :if ([ :len $Messages ] > 0) do={ - $SendNotification ([ $SymbolByUnicodeName "incoming-envelope" ] . " SMS Forwarding from " . $Phone) \ + $SendNotification ([ $SymbolForNotification "incoming-envelope" ] . "SMS Forwarding from " . $Phone) \ ("These message(s) were received by " . $Identity . \ " from " . $Phone . ":" . $Messages); :foreach Sms in=$Delete do={ |