diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-06-04 19:36:37 +0200 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-06-04 19:36:37 +0200 |
commit | 546f83cc05d41aed091e8895e42f75f0295ff87d (patch) | |
tree | 66b6e651c1284b8199d7cfa8a866c383fcd2bb47 /extras/tools/lldp/draw-neighbors.pl | |
parent | 24a5282cb63c8aab2531ae3e54c07e2c5bbebea7 (diff) |
tools: redo discovery in the form of lolwhat
what?
lol...
just figure it out for me.
Ok, so the tool isn't entirely done, but it departs from the simple
lldpdiscver.pl method that was very limited when things weren't working as
they should.
The long-term idea of lolwhat is that it should be able to do all sorts of
discovery. Right now it just takes a list of IPs and figures out how things
are connected by SNMP. It uses LLDP info from SNMP, but it does not
_currently_ traverse new hosts based on what it finds.
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"; +} |