diff options
author | root <root@DEBIAN.TEMPLATE> | 2016-06-02 19:07:59 +0200 |
---|---|---|
committer | root <root@DEBIAN.TEMPLATE> | 2016-06-02 19:07:59 +0200 |
commit | 8b580cc21e08b187451cc36a379974ca898e5105 (patch) | |
tree | 54545f735e4d626d128bd61effa4360be164756b /extras/tools/lldp/draw-neighbors.pl | |
parent | 5222b78af21f90e230d50c075174fc84f45d4172 (diff) |
lldpdiscover imported
Diffstat (limited to 'extras/tools/lldp/draw-neighbors.pl')
-rwxr-xr-x | extras/tools/lldp/draw-neighbors.pl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/extras/tools/lldp/draw-neighbors.pl b/extras/tools/lldp/draw-neighbors.pl new file mode 100755 index 0000000..323e676 --- /dev/null +++ b/extras/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"; +} + |