3 years ago
Manual topology mapping
After years of suffering with the horrific (and broken) topology mapping, how about just giving us the ability to create our own dependencies/maps, similar to The Dude or MangeEngine's OpManager?
This is basically what you need for the configsource for CDP, but I can see why they didn’t do it. The problem is IP address reusage. This toposource outputs the mac address of the queried device as the “from” node and outputs the IP addresses of its neighbors as the “to” nodes. The problem is that the IP address needs to be an ERI on the neighbor in LM. So, an ERI source would have to go along with this to make the IP addresses into ERIs on the device. At that point you run the risk of ERI collision/merging issues if IP addresses are reused somewhere else in the network. I suppose topo.namespace would be the way to mitigate this. Basically each customer (for MSPs) would have to have a namespace, then each IP network would have to have a sub-namespace (combination of the customer namespace and the network’s namespace).
import com.santaba.agent.groovyapi.snmp.Snmp
import groovy.json.*
Oid = "1.3.6.1.4.1.9.9.23.1.2.1.1"
wildvalueTerms = 2
def host = hostProps.get('system.hostname')
def props = hostProps.toProperties()
int timeout = 10000 // 10 sec timeout.
def eris = hostProps.get('predef.externalResourceID')
eri = eris.tokenize(",")[0]
eri = eri.split("::")[-1]
def snmpMapToTable(snmpmap, int wildvalueTerms = 1) {
rows = [:]
snmpmap.each {k,v ->
splits = k.tokenize(".")
col = splits.dropRight(wildvalueTerms).join(".")
wildvalue = splits.takeRight(wildvalueTerms).join(".")
if (!(rows.containsKey(wildvalue))) { rows[wildvalue] = [:] }
rows[wildvalue][col] = v
}
return rows
}
try {walkResult = Snmp.walkAsMap(host, Oid, props, timeout)}
catch (Exception e) {println(e);return 1}
try {entryRaw = snmpMapToTable(walkResult, wildvalueTerms)}
catch (Exception e) {println(e);return 2}
output = ["edges": entryRaw.collect{k,v-> ["type": "Network", "from": eri, "to": v["4"].tokenize(":").collect{address -> Integer.parseInt(address, 16)}.join(".")]}]
println(new JsonBuilder(output).toPrettyString())
return 0