mirror of
https://github.com/nymurbd/MikroTik-scripts.git
synced 2025-07-21 19:34:37 +02:00
global-functions.d/inspectvar: add $InspectVar...
to inspect variables. This is useful for variables with (nested) arrays, for example inspecting $NetwatchNotify (from netwatch-notify): [admin@Mikrotik] > $InspectVar $NetwatchNotify -type-> array -key-> quad-one -type-> array -key-> count -type-> num -value-> 0 -key-> notified -type-> bool -value-> false -key-> parent -type-> nothing -key-> resolve-failed -type-> nothing -key-> since -type-> nothing -key-> example.com -type-> array -key-> count -type-> num -value-> 0 -key-> notified -type-> bool -value-> false -key-> parent -type-> str -value-> quad-one -key-> resolve-failed -type-> nothing -key-> since -type-> nothing
This commit is contained in:
parent
ce78d7d9e9
commit
9295d06fe2
5 changed files with 44 additions and 3 deletions
40
global-functions.d/inspectvar
Normal file
40
global-functions.d/inspectvar
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: global-functions.d/inspectvar
|
||||
# Copyright (c) 2020-2021 Christian Hesse <mail@eworm.de>
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
|
||||
:global InspectVar;
|
||||
|
||||
# inspect variable
|
||||
:set InspectVar do={
|
||||
:local Input $1;
|
||||
:local Level (0 + [ :tonum $2 ]);
|
||||
|
||||
:global InspectVar;
|
||||
|
||||
:local PutIndent do={
|
||||
:local Prefix [ :tostr $1 ];
|
||||
:local Value [ :tostr $2 ];
|
||||
:local Level [ :tonum $3 ];
|
||||
|
||||
:local Indent "";
|
||||
:for I from=1 to=$Level step=1 do={
|
||||
:set Indent ($Indent . " ");
|
||||
}
|
||||
:put ($Indent . "-" . $Prefix . "-> " . $Value);
|
||||
}
|
||||
|
||||
:local TypeOf [ :typeof $Input ];
|
||||
$PutIndent "type" $TypeOf $Level;
|
||||
|
||||
:if ($TypeOf = "array") do={
|
||||
:foreach Key,Value in=$Input do={
|
||||
$PutIndent "key" $Key ($Level + 1);
|
||||
$InspectVar $Value ($Level + 2);
|
||||
}
|
||||
} else={
|
||||
:if ($TypeOf != "nothing") do={
|
||||
$PutIndent "value" $Input $Level;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue