In my perl script Ive filled a two dimensional hash by collecting CDP neighbour information from cisco routers in my network via SNMP (in this case ip addresses of the devices). Hashes have allowed me to limit duplicates and capture parent daughter relationships.
$name{$hostIP}{$neighbourIP} = $name;
I’d like to use the hashed data with D3.js (in a dendrogram) to illustrate the router topology or connection relationships and need the data formatted in JSON recursively like:
{
name: "10.120.5.1",
children: [
{
name: "10.120.5.2",
children: [
{
name: "10.120.5.3",
children: [
{
name: "10.120.5.4"
},
{
name: "10.120.6.1"
},
{
name: "10.120.6.2"
},
{
name: "10.120.6.3"
}
]
}
]
}
]
}
Can someone provide examples using libraries or normal print statements showing how to convert the hash format to JSON similar to the above? Perl is preferred but any language like python, C would help. Also if anyone knows of any open source scripting that does this job already I’d love to compare.
Does this help with the recursion? Starting from a hash similar to yours, I perform
Walking the data twice seems sub-optimal, but not doing it results in very deep dendrograms.