ospf-to-leds: introduce script to visualize ospf state via leds

This commit is contained in:
Christian Hesse 2020-10-23 14:13:40 +02:00
parent ebbc40e3a0
commit ae5570325b
7 changed files with 63 additions and 3 deletions

View file

@ -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)

34
doc/ospf-to-leds.md Normal file
View file

@ -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)

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 33;
:global GlobalConfigVersion 34;
# This is used for DNS and backup file.
:global Domain "example.com";

View file

@ -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.

View file

@ -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.";
};

View file

@ -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;

24
ospf-to-leds Normal file
View file

@ -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 ];
}
}