diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/draw-neighbors.pl | 36 | ||||
| -rwxr-xr-x | tools/lldpdiscover.pl | 8 | 
2 files changed, 41 insertions, 3 deletions
diff --git a/tools/draw-neighbors.pl b/tools/draw-neighbors.pl new file mode 100755 index 0000000..a9abc79 --- /dev/null +++ b/tools/draw-neighbors.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +use strict; +use JSON; + +my $in; +while (<STDIN>) { +	$in .= $_; +} + +my %assets = %{JSON::XS::decode_json($in)}; + +print "Drawing family tree from JSON:\n\n"; +while (my ($key, $value) = each %assets) { +	print_tree ($key,0,undef); +	last; +} +sub print_tree +{ +	my ($chassis_id,$indent,$parent,$max) = @_; +	if (!defined($parent)) { +		$parent = ""; +	} +	if ($indent > 50) { +		die "Possible loop detected."; +	} +	for (my $i = 0; $i < $indent; $i++) { +		print "\t"; +	} +	print " - " . $assets{$chassis_id}{sysName} . "\n"; +	while (my ($key, $value) = each %{$assets{$chassis_id}{neighbors}}) { +		if ($key ne $parent) { +			print_tree($key,$indent+1,$chassis_id); +		} +	} +} diff --git a/tools/lldpdiscover.pl b/tools/lldpdiscover.pl index 9dccd7b..711292c 100755 --- a/tools/lldpdiscover.pl +++ b/tools/lldpdiscover.pl @@ -6,7 +6,7 @@ use strict;  use warnings;  use Data::Dumper; -use lib 'tgmanage/include'; +use lib '../include';  use nms;  # Actual assets detected, indexed by chassis ID @@ -19,12 +19,13 @@ my @chassis_ids_to_check;  # If we are given one switch on the command line, add that and then exit.  my ($cmdline_ip, $cmdline_community) = @ARGV;  if (defined($cmdline_ip) && defined($cmdline_community)) { +	my $chassis_id;  	eval {  		# Special-case for the first switch is to fetch chassis id  		# directly. Everything else is fetched from a neighbour  		# table.  		my $session = nms::snmp_open_session($cmdline_ip, $cmdline_community); -		my $chassis_id = get_lldp_chassis_id($session); +		$chassis_id = get_lldp_chassis_id($session);  		$assets{$chassis_id}{'community'} = $cmdline_community;  		@{$assets{$chassis_id}{'v4mgmt'}} = ($cmdline_ip);  		@{$assets{$chassis_id}{'v6mgmt'}} = (); @@ -53,11 +54,12 @@ if (defined($cmdline_ip) && defined($cmdline_community)) {  		}  	}  	print JSON::XS::encode_json(\%assets); +	# Creates corrupt output, hooray. +#	print JSON::XS->new->pretty(1)->encode(\%assets);  	exit;  } else {  	print "RTFSC\n";  } -  # Filter out stuff we don't scan. Return true if we care about it.  # XXX: Several of these things are temporary to test (e.g.: AP).  sub filter {  | 
