Skip to content

Commit

Permalink
ospf-to-leds: introduce script to visualize ospf state via leds
Browse files Browse the repository at this point in the history
  • Loading branch information
eworm-de committed Oct 23, 2020
1 parent ebbc40e commit ae55703
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions doc/ospf-to-leds.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion global-config
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion global-config-overlay
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions global-config.changes
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
};
2 changes: 1 addition & 1 deletion global-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions ospf-to-leds
Original file line number Diff line number Diff line change
@@ -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 ];
}
}

0 comments on commit ae55703

Please sign in to comment.