aboutsummaryrefslogtreecommitdiffstats
path: root/tools/draw-neighbors.pl
blob: 323e6769e44e03b9655d6d78cb440caa2057dea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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";
}