Get mac vendor result as dci
-
Hello
What is the best way to get "https://api.macvendors.com/%{node_mac}" result as DCI value and apply that via template ?
Egert
-
On one of the nodes with agent (let's call it "node1") add external parameter:
ExternalParameter=ResolveMAC(*):curl -s "https://api.macvendors.com/$1"
Then add DCI in the template:
Parameter=ResolveMAC(%{node_mac})
Source Node=node1But I'd use mapping tables instead of calling remote service.
-
-
Mapping tables might better just for the reason of not disclosing the addresses to 3-rd party and for reliability.
You can add this script to script library and then use macro %[name_of_script] to get mac address of that node's interface that has primary IP address.
mac = NULL; for (i:$node->interfaces) { if ($node->ipAddr == i->ipAddr) mac = i->macAddr; } return mac; -
You can download latest mapping here: http://standards-oui.ieee.org/oui.txt
Then parse it and save in the mapping table (in this example - using nxshell):
#!/usr/bin/env nxshell TABLE_NAME='MAC Address' # find mapping table, create if missing table_id = -1 for t in session.listMappingTables(): if t.name == TABLE_NAME: table_id = t.id break if table_id == -1: table_id = session.createMappingTable(TABLE_NAME, 'Lookup table for MAC -> Vendor', 0) target_table = session.getMappingTable(table_id) with open('oui.txt', 'r') as f: target_table.data.clear() for line in f.readlines(): if "(hex)" in line: (mac, _, name) = line.strip().split('\t') mac = mac.split(' ')[0].replace('-', ':') target_table.data.add(MappingTableEntry(mac, name, None)) session.updateMappingTable(target_table)Then you can lookup with map() function (in this example - find interface which have primary IP address):
for (i : $node->interfaces) { if (i->ipAddr == $node->ipAddr) { return map("MAC Address", (substr(i->macAddr, 0, 8))); } }Result: Apple, Inc. -
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login