diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | doc/ospf-to-leds.md | 34 | ||||
-rw-r--r-- | global-config | 2 | ||||
-rw-r--r-- | global-config-overlay | 2 | ||||
-rw-r--r-- | global-config.changes | 1 | ||||
-rw-r--r-- | global-functions | 2 | ||||
-rw-r--r-- | ospf-to-leds | 24 |
7 files changed, 63 insertions, 3 deletions
@@ -171,6 +171,7 @@ Available Scripts * [Mode button with multiple presses](doc/mode-button.md) * [Notify on host up and down](doc/netwatch-notify.md) * [Manage remote logging](doc/netwatch-syslog.md) +* [Visualize OSPF state via LEDs](doc/ospf-to-leds.md) * [Manage system update](doc/packages-update.md) * [Run scripts on ppp connection](doc/ppp-on-up.md) * [Rotate NTP servers](doc/rotate-ntp.md) diff --git a/doc/ospf-to-leds.md b/doc/ospf-to-leds.md new file mode 100644 index 0000000..72fab6b --- /dev/null +++ b/doc/ospf-to-leds.md @@ -0,0 +1,34 @@ +Visualize OSPF state via LEDs +============================= + +[◀ Go back to main README](../README.md) + +Description +----------- + +Physical interfaces have their state LEDs, software-defined connectivity +does not. This script helps to visualize whether or not an OSPF instance +is running. + +Requirements and installation +----------------------------- + +Just install the script: + + $ScriptInstallUpdate ospf-to-leds; + +... and add a scheduler to run the script periodically: + + / system scheduler add interval=20s name=ospf-to-leds on-event="/ system script run ospf-to-leds;" start-time=startup; + +Configuration +------------- + +The configuration goes to OSPF instance's comment. To visualize state for +instance `default` via LED `user-led` set this: + + / routing ospf instance set default comment="ospf-to-leds, leds=user-led"; + +--- +[◀ Go back to main README](../README.md) +[▲ Go back to top](#top) diff --git a/global-config b/global-config index 8721f8d..68d12e7 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 33; +:global GlobalConfigVersion 34; # This is used for DNS and backup file. :global Domain "example.com"; diff --git a/global-config-overlay b/global-config-overlay index 984e577..99295e6 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 33; +:global GlobalConfigVersion 34; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index 04f8a53..7d14e85 100644 --- a/global-config.changes +++ b/global-config.changes @@ -37,4 +37,5 @@ 31="Switched Telegram notifications to fixed-width font, with opt-out."; 32="Merged mode (& reset) button scripts in single new script 'mode-button'."; 33="Added configurable deviation on health temperature recovery threshold against notification flooding."; + 34="Introduced script 'ospf-to-leds' to visualize OSPF instance state via LEDs."; }; diff --git a/global-functions b/global-functions index 10f14f6..ab3247a 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 33; +:global ExpectedConfigVersion 34; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/ospf-to-leds b/ospf-to-leds new file mode 100644 index 0000000..61b90ce --- /dev/null +++ b/ospf-to-leds @@ -0,0 +1,24 @@ +#!rsc by RouterOS +# RouterOS script: ospf-to-leds +# Copyright (c) 2020 Christian Hesse <mail@eworm.de> +# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md +# +# visualize ospf instance state via leds +# https://git.eworm.de/cgit/routeros-scripts/about/doc/ospf-to-leds.md + +:global LogPrintExit; +:global ParseKeyValueStore; + +:foreach Instance in=[ / routing ospf instance find where comment~"^ospf-to-leds," ] do={ + :local InstanceVal [ / routing ospf instance get $Instance ]; + :local LED ([ $ParseKeyValueStore ($InstanceVal->"comment") ]->"leds"); + :local LEDType [ / system leds get [ find where leds=$LED ] type ]; + + $LogPrintExit debug ("OSPF instance " . $InstanceVal->"name" . " is " . $InstanceVal->"state" . ".") false; + :if ($InstanceVal->"state" = "running" && $LEDType = "off") do={ + / system leds set type=on [ find where leds=$LED ]; + } + :if ($InstanceVal->"state" = "down" && $LEDType = "on") do={ + / system leds set type=off [ find where leds=$LED ]; + } +} |