mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
global-functions: introduce and use $SymbolForNotification
This commit is contained in:
parent
0e7b2d3ac7
commit
075859c898
9 changed files with 35 additions and 18 deletions
12
check-health
12
check-health
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
:local FormatVoltage do={
|
:local FormatVoltage do={
|
||||||
:local Voltage [ :tonum $1 ];
|
:local Voltage [ :tonum $1 ];
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
[ :typeof ($CheckHealthCurrent->$Voltage) ] = "num") do={
|
[ :typeof ($CheckHealthCurrent->$Voltage) ] = "num") do={
|
||||||
:if ($CheckHealthLast->$Voltage * (100 + $CheckHealthVoltagePercent) < $CheckHealthCurrent->$Voltage * 100 || \
|
:if ($CheckHealthLast->$Voltage * (100 + $CheckHealthVoltagePercent) < $CheckHealthCurrent->$Voltage * 100 || \
|
||||||
$CheckHealthLast->$Voltage * 100 > $CheckHealthCurrent->$Voltage * (100 + $CheckHealthVoltagePercent)) do={
|
$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" . \
|
("The " . $Voltage . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \
|
||||||
"old value: " . [ $FormatVoltage ($CheckHealthLast->$Voltage) ] . "\n" . \
|
"old value: " . [ $FormatVoltage ($CheckHealthLast->$Voltage) ] . "\n" . \
|
||||||
"new value: " . [ $FormatVoltage ($CheckHealthCurrent->$Voltage) ]);
|
"new value: " . [ $FormatVoltage ($CheckHealthCurrent->$Voltage) ]);
|
||||||
|
@ -40,12 +40,12 @@
|
||||||
[ :typeof ($CheckHealthCurrent->($PSU . "-state")) ] = "str") do={
|
[ :typeof ($CheckHealthCurrent->($PSU . "-state")) ] = "str") do={
|
||||||
:if ($CheckHealthLast->($PSU . "-state") = "ok" && \
|
:if ($CheckHealthLast->($PSU . "-state") = "ok" && \
|
||||||
$CheckHealthCurrent->($PSU . "-state") != "ok") do={
|
$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!");
|
("The power supply unit '" . $PSU . "' on " . $Identity . " failed!");
|
||||||
}
|
}
|
||||||
:if ($CheckHealthLast->($PSU . "-state") != "ok" && \
|
:if ($CheckHealthLast->($PSU . "-state") != "ok" && \
|
||||||
$CheckHealthCurrent->($PSU . "-state") = "ok") do={
|
$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!");
|
("The power supply unit '" . $PSU . "' on " . $Identity . " recovered!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,13 @@
|
||||||
}
|
}
|
||||||
:if ($CheckHealthLast->$Temperature <= $CheckHealthTemperature->$Temperature && \
|
:if ($CheckHealthLast->$Temperature <= $CheckHealthTemperature->$Temperature && \
|
||||||
$CheckHealthCurrent->$Temperature > $CheckHealthTemperature->$Temperature) do={
|
$CheckHealthCurrent->$Temperature > $CheckHealthTemperature->$Temperature) do={
|
||||||
$SendNotification ([ $SymbolByUnicodeName "fire" ] . " Health warning: " . $Temperature) \
|
$SendNotification ([ $SymbolForNotification "fire" ] . "Health warning: " . $Temperature) \
|
||||||
("The " . $Temperature . " on " . $Identity . " is above threshold: " . \
|
("The " . $Temperature . " on " . $Identity . " is above threshold: " . \
|
||||||
$CheckHealthCurrent->$Temperature . "\C2\B0" . "C");
|
$CheckHealthCurrent->$Temperature . "\C2\B0" . "C");
|
||||||
}
|
}
|
||||||
:if ($CheckHealthLast->$Temperature > $CheckHealthTemperature->$Temperature && \
|
:if ($CheckHealthLast->$Temperature > $CheckHealthTemperature->$Temperature && \
|
||||||
$CheckHealthCurrent->$Temperature <= $CheckHealthTemperature->$Temperature) do={
|
$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: " . \
|
("The " . $Temperature . " on " . $Identity . " dropped below threshold: " . \
|
||||||
$CheckHealthCurrent->$Temperature . "\C2\B0" . "C");
|
$CheckHealthCurrent->$Temperature . "\C2\B0" . "C");
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
:global ScriptFromTerminal;
|
:global ScriptFromTerminal;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolForNotification;
|
||||||
:global VersionToNum;
|
:global VersionToNum;
|
||||||
|
|
||||||
:local DoUpdate do={
|
:local DoUpdate do={
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
$Update->"latest-version" . ".") true;
|
$Update->"latest-version" . ".") true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification ([ $SymbolByUnicodeName "sparkles" ] . " RouterOS update") \
|
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
|
||||||
("A new RouterOS version " . ($Update->"latest-version") . \
|
("A new RouterOS version " . ($Update->"latest-version") . \
|
||||||
" is available for " . $Identity . ".\n\n" . \
|
" is available for " . $Identity . ".\n\n" . \
|
||||||
[ $DeviceInfo ] . "\n\n" . \
|
[ $DeviceInfo ] . "\n\n" . \
|
||||||
|
|
|
@ -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 23;
|
:global GlobalConfigVersion 24;
|
||||||
|
|
||||||
# This is used for DNS and backup file.
|
# This is used for DNS and backup file.
|
||||||
:global Domain "example.com";
|
:global Domain "example.com";
|
||||||
|
@ -28,6 +28,9 @@
|
||||||
#:global TelegramTokenId "123456:ABCDEF-GHI";
|
#:global TelegramTokenId "123456:ABCDEF-GHI";
|
||||||
#:global TelegramChatId "12345678";
|
#:global TelegramChatId "12345678";
|
||||||
|
|
||||||
|
# Toggle this to disable symbols in notifications.
|
||||||
|
:global NotificationsWithSymbols true;
|
||||||
|
|
||||||
# This defines what backups to generate and what password to use.
|
# This defines what backups to generate and what password to use.
|
||||||
:global BackupSendBinary false;
|
:global BackupSendBinary false;
|
||||||
:global BackupSendExport true;
|
:global BackupSendExport true;
|
||||||
|
|
|
@ -9,7 +9,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 change notifications.
|
# Comment or remove to disable change notifications.
|
||||||
:global GlobalConfigVersion 23;
|
:global GlobalConfigVersion 24;
|
||||||
|
|
||||||
# Copy configuration from global-config here and modify it.
|
# Copy configuration from global-config here and modify it.
|
||||||
|
|
||||||
|
|
|
@ -27,4 +27,5 @@
|
||||||
21="Added support for installing patch updates automatically by 'check-routeros-update'";
|
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"
|
22="Dropped '\$ScriptUpdatesIgnore' from global configuration, auto-migrating to ignore flag in comment"
|
||||||
23="Added 'log-forward' with configurable filter, which replaces 'early-errors'";
|
23="Added 'log-forward' with configurable filter, which replaces 'early-errors'";
|
||||||
|
24="Made symbols in notifications configurable.";
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 23;
|
:global ExpectedConfigVersion 24;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
@ -41,6 +41,7 @@
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
:global SendTelegram;
|
:global SendTelegram;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolByUnicodeName;
|
||||||
|
:global SymbolForNotification;
|
||||||
:global TimeIsSync;
|
:global TimeIsSync;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global VersionToNum;
|
:global VersionToNum;
|
||||||
|
@ -747,6 +748,18 @@
|
||||||
:return ($Symbols->$1);
|
: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
|
# check if system time is sync
|
||||||
:set TimeIsSync do={
|
:set TimeIsSync do={
|
||||||
:if ([ / system ntp client get enabled ] = true) do={
|
:if ([ / system ntp client get enabled ] = true) do={
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
:global MailServerIsUp;
|
:global MailServerIsUp;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolForNotification;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
$WaitFullyConnected;
|
$WaitFullyConnected;
|
||||||
|
@ -40,7 +40,7 @@ $WaitFullyConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ($Count > 0) do={
|
: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 " . \
|
("The log on " . $Identity . " contains these " . $Count . " messages after " . \
|
||||||
[ / system resource get uptime ] . " uptime.\n" . $Messages);
|
[ / system resource get uptime ] . " uptime.\n" . $Messages);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
:global ParseKeyValueStore;
|
:global ParseKeyValueStore;
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
:if ([ :typeof $NetwatchNotify ] = "nothing") do={
|
:if ([ :typeof $NetwatchNotify ] = "nothing") do={
|
||||||
:set NetwatchNotify [ :toarray "" ];
|
:set NetwatchNotify [ :toarray "" ];
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
: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 ([ $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" . \
|
("Host " . $HostName . " (" . $HostVal->"host" . ") is up since " . $HostVal->"since" . ".\n" . \
|
||||||
"It was down for " . $Count . " checks.");
|
"It was down for " . $Count . " checks.");
|
||||||
:if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={
|
:if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
$LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \
|
$LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \
|
||||||
$Metric->"count" . " checks.") false;
|
$Metric->"count" . " checks.") false;
|
||||||
:if ($Metric->"count" >= 5 && $Metric->"notified" != true) do={
|
: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" . ".");
|
("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={
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
:global MailServerIsUp;
|
:global MailServerIsUp;
|
||||||
:global SendNotification;
|
:global SendNotification;
|
||||||
:global SymbolByUnicodeName;
|
:global SymbolForNotification;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
:if ([ / tool sms get receive-enabled ] = false) do={
|
:if ([ / tool sms get receive-enabled ] = false) do={
|
||||||
|
@ -47,7 +47,7 @@ $WaitFullyConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ([ :len $Messages ] > 0) do={
|
: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 . \
|
("These message(s) were received by " . $Identity . \
|
||||||
" from " . $Phone . ":" . $Messages);
|
" from " . $Phone . ":" . $Messages);
|
||||||
:foreach Sms in=$Delete do={
|
:foreach Sms in=$Delete do={
|
||||||
|
|
Loading…
Reference in a new issue