diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-02-26 11:32:15 +0100 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-02-26 11:32:15 +0100 |
commit | 34aa9568d90c84296d1e1f631748e9aa44227802 (patch) | |
tree | 56648f9c95651ac7a6940c1f5ac0086e18a4176c /tools/lldp/draw-neighbors.pl | |
parent | e6fd0035555499fa186845f4c69b715e9ad246b9 (diff) |
tools: Make directory for lldp-misc
Cleaner this way
Diffstat (limited to 'tools/lldp/draw-neighbors.pl')
-rwxr-xr-x | tools/lldp/draw-neighbors.pl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/lldp/draw-neighbors.pl b/tools/lldp/draw-neighbors.pl new file mode 100755 index 0000000..323e676 --- /dev/null +++ b/tools/lldp/draw-neighbors.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use JSON; + +my $in; +while (<STDIN>) { + $in .= $_; +} + +my %assets = %{JSON::XS::decode_json($in)}; + +print "strict graph network {\n"; +while (my ($key, $value) = each %assets) { + print_tree ($key,0,undef); +} +print "}\n"; + +sub print_tree +{ + my ($chassis_id,$indent,$parent,$max) = @_; + if (!defined($parent)) { + $parent = ""; + } + if ($indent > 50) { + die "Possible loop detected."; + } + print " \"$assets{$chassis_id}{sysName}\" -- {"; + my @n; + while (my ($key, $value) = each %{$assets{$chassis_id}{neighbors}}) { + push @n, "\"$assets{$key}{sysName}\""; + } + print join(",",@n) . "};\n"; +} + |