diff options
Diffstat (limited to 'extras/tools/lldp/draw-neighbors.pl')
-rwxr-xr-x | extras/tools/lldp/draw-neighbors.pl | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/extras/tools/lldp/draw-neighbors.pl b/extras/tools/lldp/draw-neighbors.pl index 323e676..0a3f9d0 100755 --- a/extras/tools/lldp/draw-neighbors.pl +++ b/extras/tools/lldp/draw-neighbors.pl @@ -4,32 +4,55 @@ use strict; use JSON; my $in; +my ($full) = @ARGV; while (<STDIN>) { $in .= $_; } my %assets = %{JSON::XS::decode_json($in)}; +my %map = %{$assets{hood}}; +my %map2 = %{$assets{extended}}; print "strict graph network {\n"; -while (my ($key, $value) = each %assets) { +while (my ($key, $value) = each %map) { print_tree ($key,0,undef); } +if ($full eq "full") { +while (my ($key, $value) = each %map2) { + print_tree2 ($key,0,undef); +}} print "}\n"; sub print_tree { - my ($chassis_id,$indent,$parent,$max) = @_; + my ($name,$indent,$parent,$max) = @_; if (!defined($parent)) { $parent = ""; } if ($indent > 50) { die "Possible loop detected."; } - print " \"$assets{$chassis_id}{sysName}\" -- {"; + print " \"$name\" -- {"; my @n; - while (my ($key, $value) = each %{$assets{$chassis_id}{neighbors}}) { - push @n, "\"$assets{$key}{sysName}\""; + while (my ($key, $value) = each %{$map{$name}}) { + push @n, "\"$key\""; } print join(",",@n) . "};\n"; } +sub print_tree2 +{ + my ($name,$indent,$parent,$max) = @_; + if (!defined($parent)) { + $parent = ""; + } + if ($indent > 50) { + die "Possible loop detected."; + } + print " \"$name\" -- {"; + my @n; + while (my ($key, $value) = each %{$map2{$name}}) { + push @n, "\"$key\""; + } + print join(",",@n) . "};\n"; +} |