aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lldp/draw-neighbors.pl
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly.no>2016-02-26 13:05:31 +0000
committerKristian Lyngstol <kly@kly.no>2016-02-26 13:05:31 +0000
commit885156ee6a26ed047bba3f90541eaab92b65d758 (patch)
treee8a70cd6bca09641efac0c64c4c20d27efab2bda /tools/lldp/draw-neighbors.pl
parentc6997a4810e09619e9018c91d163f3f38b17212c (diff)
parent3dae75bde90aecc0cef2e3496f3565dcb3eeec0c (diff)
Merge branch 'master' of github.com:tech-server/tgmanage
Diffstat (limited to 'tools/lldp/draw-neighbors.pl')
-rwxr-xr-xtools/lldp/draw-neighbors.pl35
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";
+}
+