Merge branch 'routeros-v7' into next

This commit is contained in:
Christian Hesse 2022-01-14 16:54:30 +01:00
commit db4afe28f0
11 changed files with 83 additions and 82 deletions

View file

@ -118,30 +118,15 @@ to be updated automatically!
### Changes for RouterOS v6
RouterOS v6 will become deprecated at some time in the future, but to date
it is still the default for these scripts (in branch `main`). This will
change however, so if you want to stay with RouterOS v6 for some time add
these lines to your `global-config-overlay`, if missing:
RouterOS v7 is the way to go, let's consider RouterOS v6 deprecated.
If you want to stay with RouterOS v6 for some time add these lines
to your `global-config-overlay`, if missing:
# Use branch routeros-v6 with RouterOS v6:
:global ScriptUpdatesUrlSuffix "\?h=routeros-v6";
Then reload the configuration.
### Changes for RouterOS v7
RouterOS v7 is developed in paralled to RouterOS v6. The former brings some
shiny new features, the latter provides proven stability.
The changes require incompatible changes to scripts, so these changes go to
a separate branch. If you decide to run RouterOS v7 please switch to branch
`routeros-v7` by adding these lines to your `global-config-overlay`:
# Use branch routeros-v7 with RouterOS v7:
:global ScriptUpdatesUrlSuffix "\?h=routeros-v7";
Then reload the configuration and continue below to update scripts.
Updating scripts
----------------

View file

@ -62,7 +62,7 @@ $WaitFullyConnected;
# create configuration export
:if ($BackupSendExport = true) do={
/ export terse file=$FilePath;
/ export terse show-sensitive file=$FilePath;
$WaitForFile ($FilePath . ".rsc");
:set ConfigFile ($FileName . ".rsc");
:set Attach ($Attach, ($FilePath . ".rsc"));

View file

@ -76,7 +76,7 @@ $WaitFullyConnected;
# create configuration export
:if ($BackupSendExport = true) do={
/ export terse file=$FilePath;
/ export terse show-sensitive file=$FilePath;
$WaitForFile ($FilePath . ".rsc");
:do {

View file

@ -24,98 +24,108 @@
:global SendNotification2;
:global SymbolForNotification;
:local FormatVoltage do={
:local Voltage [ :tonum $1 ];
:return (($Voltage / 10) . "." . [ :pick $Voltage ([ :len $Voltage ] - 1) ] . "V");
:local TempToNum do={
:global CharacterReplace;
:local T [ :toarray [ $CharacterReplace $1 "." "," ] ];
:return ($T->0 * 10 + $T->1);
}
:local CheckHealthCurrent [ / system health get ];
:if ([ :len $CheckHealthCurrent ] = 0) do={
:if ([ :len [ / system health find ] ] = 0) do={
$LogPrintExit2 error $0 ("Your device does not provide any health values.") true;
}
:if ([ :typeof $CheckHealthLast ] != "array") do={
:set CheckHealthLast [ :toarray "" ];
}
:if ([ :typeof $CheckHealthTemperatureNotified ] != "array") do={
:set CheckHealthTemperatureNotified [ :toarray "" ];
}
$ScriptLock $0;
:foreach Name,Voltage in=$CheckHealthCurrent do={
:if ($Name ~ "(battery|voltage)" && \
[ :typeof ($CheckHealthLast->$Name) ] = "num" && \
[ :typeof $Voltage ] = "num") do={
:if ($CheckHealthLast->$Name * (100 + $CheckHealthVoltagePercent) < $Voltage * 100 || \
$CheckHealthLast->$Name * 100 > $Voltage * (100 + $CheckHealthVoltagePercent)) do={
:foreach Voltage in=[ / system health find where type="V" ] do={
:local Name [ / system health get $Voltage name ];
:local Value [ / system health get $Voltage value ];
:if ([ :typeof ($CheckHealthLast->$Name) ] != "nothing") do={
:local NumCurr [ $TempToNum $Value ];
:local NumLast [ $TempToNum ($CheckHealthLast->$Name) ];
:if ($NumLast * (100 + $CheckHealthVoltagePercent) < $NumCurr * 100 || \
$NumLast * 100 > $NumCurr * (100 + $CheckHealthVoltagePercent)) do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification ("high-voltage-sign,chart-" . [ $IfThenElse ($CheckHealthLast->$Name < \
$Voltage) "in" "de" ] . "creasing") ] . "Health warning: " . $Name); \
subject=([ $SymbolForNotification ("high-voltage-sign,chart-" . [ $IfThenElse ($NumLast < \
$NumCurr) "in" "de" ] . "creasing") ] . "Health warning: " . $Name); \
message=("The " . $Name . " on " . $Identity . " jumped more than " . $CheckHealthVoltagePercent . "%.\n\n" . \
"old value: " . [ $FormatVoltage ($CheckHealthLast->$Name) ] . "\n" . \
"new value: " . [ $FormatVoltage $Voltage ]) });
"old value: " . ($CheckHealthLast->$Name) . " V\n" . \
"new value: " . $Value . " V") });
} else={
:if ($Voltage <= $CheckHealthVoltageLow && $CheckHealthLast->$Name > $CheckHealthVoltageLow) do={
:if ($NumCurr <= $CheckHealthVoltageLow && $NumLast > $CheckHealthVoltageLow) do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "high-voltage-sign,chart-decreasing" ] . "Health warning: Low " . $Name); \
message=("The " . $Name . " on " . $Identity . " dropped to " . [ $FormatVoltage $Voltage ] . " below hard limit.") });
message=("The " . $Name . " on " . $Identity . " dropped to " . $Value . " V below hard limit.") });
}
:if ($Voltage > $CheckHealthVoltageLow && $CheckHealthLast->$Name <= $CheckHealthVoltageLow) do={
:if ($NumCurr > $CheckHealthVoltageLow && $NumLast <= $CheckHealthVoltageLow) do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "high-voltage-sign,chart-increasing" ] . "Health recovery: Low " . $Name); \
message=("The " . $Name . " on " . $Identity . " recovered to " . [ $FormatVoltage $Voltage ] . " above hard limit.") });
message=("The " . $Name . " on " . $Identity . " recovered to " . $Value . " V above hard limit.") });
}
}
}
:set ($CheckHealthLast->$Name) $Value;
}
:foreach Name,PSU in=$CheckHealthCurrent do={
:if ($Name ~ "psu.*-state" && \
[ :typeof ($CheckHealthLast->$Name) ] = "str" && \
[ :typeof $PSU ] = "str") do={
:foreach PSU in=[ / system health find where name~"^psu.*-state\$" ] do={
:local Name [ / system health get $PSU name ];
:local Value [ / system health get $PSU value ];
:if ([ :typeof ($CheckHealthLast->$Name) ] != "nothing") do={
:if ($CheckHealthLast->$Name = "ok" && \
$PSU != "ok") do={
$Value != "ok") do={
$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={
$Value = "ok") do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \
message=("The power supply unit '" . $Name . "' on " . $Identity . " recovered!") });
}
}
:set ($CheckHealthLast->$Name) $Value;
}
:foreach Name,Temperature in=$CheckHealthCurrent do={
:if ($Name ~ "temperature" && \
[ :typeof $Temperature ] = "num") do={
:foreach Temperature in=[ / system health find where type="C" ] do={
:local Name [ / system health get $Temperature name ];
:local Value [ / system health get $Temperature value ];
:if ([ :typeof ($CheckHealthLast->$Name) ] != "nothing") do={
:if ([ :typeof ($CheckHealthTemperature->$Name) ] != "num" ) do={
$LogPrintExit2 info $0 ("No threshold given for " . $Name . ", assuming 50C.") false;
:set ($CheckHealthTemperature->$Name) 50;
}
:local Validate [ / system health get $Name ];
:while ($Temperature != $Validate) do={
:set Temperature $Validate;
:set Validate [ / system health get $Name ];
:local Validate [ / system health get [ find where name=$Name ] value ];
:while ($Value != $Validate) do={
:set Value $Validate;
:set Validate [ / system health get [ find where name=$Name ] value ];
}
:if ($Temperature > $CheckHealthTemperature->$Name && \
:if ($Value > $CheckHealthTemperature->$Name && \
$CheckHealthTemperatureNotified->$Name != true) do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "fire" ] . "Health warning: " . $Name); \
message=("The " . $Name . " on " . $Identity . " is above threshold: " . \
$Temperature . "\C2\B0" . "C") });
$Value . "\C2\B0" . "C") });
:set ($CheckHealthTemperatureNotified->$Name) true;
}
:if ($Temperature <= ($CheckHealthTemperature->$Name - $CheckHealthTemperatureDeviation) && \
:if ($Value <= ($CheckHealthTemperature->$Name - $CheckHealthTemperatureDeviation) && \
$CheckHealthTemperatureNotified->$Name = true) do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Health recovery: " . $Name); \
message=("The " . $Name . " on " . $Identity . " dropped below threshold: " . \
$Temperature . "\C2\B0" . "C") });
$Value . "\C2\B0" . "C") });
:set ($CheckHealthTemperatureNotified->$Name) false;
}
}
:set ($CheckHealthLast->$Name) $Value;
}
:set CheckHealthLast $CheckHealthCurrent;

View file

@ -32,11 +32,9 @@ place the required packages to CAPsMAN package path (see
function `$DownloadPackage`, use something like this to download latest
packages to directory `routeros`:
$DownloadPackage system "" arm routeros;
$DownloadPackage security "" arm routeros;
[...]
$DownloadPackage system "" mipsbe routeros;
$DownloadPackage security "" mipsbe routeros;
$DownloadPackage routeros "" arm routeros;
$DownloadPackage routeros "" arm64 routeros;
$DownloadPackage routeros "" mipsbe routeros;
[...]
Usage and invocation

View file

@ -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 74;
:global GlobalConfigVersion 75;
# This is used for DNS and backup file.
:global Domain "example.com";
@ -159,14 +159,11 @@
# alternative urls - main: stable code - next: currently in development
#:global ScriptUpdatesBaseUrl "https://raw.githubusercontent.com/eworm-de/routeros-scripts/main/";
#:global ScriptUpdatesBaseUrl "https://raw.githubusercontent.com/eworm-de/routeros-scripts/next/";
#:global ScriptUpdatesBaseUrl "https://raw.githubusercontent.com/eworm-de/routeros-scripts/routeros-v7/";
#:global ScriptUpdatesBaseUrl "https://gitlab.com/eworm-de/routeros-scripts/raw/main/";
#:global ScriptUpdatesBaseUrl "https://gitlab.com/eworm-de/routeros-scripts/raw/next/";
#:global ScriptUpdatesBaseUrl "https://gitlab.com/eworm-de/routeros-scripts/raw/routeros-v7/";
:global ScriptUpdatesUrlSuffix "";
# use next or routeros-v7 branch with default url (git.eworm.de)
# use next branch with default url (git.eworm.de)
#:global ScriptUpdatesUrlSuffix "\?h=next";
#:global ScriptUpdatesUrlSuffix "\?h=routeros-v7";
# Use this for defaults with $ScriptRunOnce
# Install module with:

View file

@ -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 74;
:global GlobalConfigVersion 75;
# Copy configuration from global-config here and modify it.

View file

@ -2,6 +2,9 @@
# Copyright (c) 2019-2022 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
:global IfThenElse;
:global RequiredRouterOS;
# Changes for global-config to be added to notification on script updates
:global GlobalConfigChanges {
1="Moved variables from 'global-config' to 'global-functions' for independence";
@ -73,11 +76,14 @@
67="Moved modules to directory with shorter name.";
68="Reintroduced 'global-wait' for functions in scheduler.";
69="Support hard lower limit for voltage in 'check-health'.";
70="MikroTik started pushing RouterOS v7. Changes are required if you run it, see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v7";
70="MikroTik started pushing RouterOS v7. Changes are no longer required.";
71="MikroTik is pushing RouterOS v7 even more, in parallel branches. If you want to keep RouterOS v6 for some time see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v6";
72="Introduced new script 'netwatch-dns' to manage DNS and DoH servers from netwatch.";
73="Renamed backup scripts ('cloud-backup' -> 'backup-cloud', 'email-backup' -> 'backup-email', 'upload-backup' -> 'backup-upload').";
74="Extended 'hotspot-to-wpa', it can now read additional configuration from templates and hotspot users.";
75=("Finally merged the RouterOS v7 code into the main branch. " . [ $IfThenElse ([ $RequiredRouterOS "global-config.changes" "7.0" false ] = true) \
("You may now drop '\$ScriptUpdatesUrlSuffix' from 'global-config-overlay'.") \
("Still running RouterOS v6, so last reminder to see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v6") ]);
};
# Migration steps to be applied on script updates

View file

@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
:global ExpectedConfigVersion 74;
:global ExpectedConfigVersion 75;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
@ -1257,12 +1257,11 @@
}
# check for required RouterOS version
$RequiredRouterOS "global-functions" "6.47" true;
# ... and give a hint on RouterOS v7.
:if ([ $RequiredRouterOS "global-functions" "7.0" false ] = true) do={
$LogPrintExit2 warning $0 ("RouterOS v7 brings some incompatible changes. Please switch to branch " . \
"'routeros-v7', see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v7") false;
$RequiredRouterOS "global-functions" "7.1" true;
} else={
$LogPrintExit2 warning $0 ("Still running RouterOS v6, please switch to branch " . \
"'routeros-v6', see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v6") false;
}
# signal we are ready

View file

@ -18,12 +18,18 @@
:local LED ([ $ParseKeyValueStore ($InstanceVal->"comment") ]->"leds");
:local LEDType [ / system leds get [ find where leds=$LED ] type ];
:if ($InstanceVal->"state" = "running" && $LEDType = "off") do={
$LogPrintExit2 info $0 ("OSPF instance " . $InstanceVal->"name" . " is running, led on!") false;
:local NeighborCount 0;
:foreach Area in=[ / routing ospf area find where instance=($InstanceVal->"name") ] do={
:local AreaName [ / routing ospf area get $Area name ];
:set NeighborCount ($NeighborCount + [ :len [ / routing ospf neighbor find where area=$AreaName ] ]);
}
:if ($NeighborCount > 0 && $LEDType = "off") do={
$LogPrintExit2 info $0 ("OSPF instance " . $InstanceVal->"name" . " has " . $NeighborCount . " neighbors, led on!") false;
/ system leds set type=on [ find where leds=$LED ];
}
:if ($InstanceVal->"state" = "down" && $LEDType = "on") do={
$LogPrintExit2 info $0 ("OSPF instance " . $InstanceVal->"name" . " is down, led off!") false;
:if ($NeighborCount = 0 && $LEDType = "on") do={
$LogPrintExit2 info $0 ("OSPF instance " . $InstanceVal->"name" . " has no neighbors, led off!") false;
/ system leds set type=off [ find where leds=$LED ];
}
}

View file

@ -29,4 +29,4 @@
}
$LogPrintExit2 info $0 ("Updating NTP servers to " . $Ntp1 . " and " . $Ntp2) false;
/ system ntp client set primary-ntp=$Ntp1 secondary-ntp=$Ntp2;
/ system ntp client set servers=($Ntp1, $Ntp2);