I'm looking for a device inventory of company assets. I want to see the name, serial number, LAN IP and model number of the assets so I can add it to a third party "up/down" monitoring tool. All Meraki will show me using the GUI is a downloadable csv file with MAC, Serial, Model, etc., but frustratingly not the information that I need.
What to do... Simple, use the Meraki API.
To learn how you can follow the link: https://www.acendri-solutions.com/post/how-to-create-a-complete-device-inventory-using-the-meraki-api or the walkthrough below without pictures :)
First, login into your Meraki dashboard. Go to Organization, then Settings. Check the box to "enable access to the Cisco Meraki Dashboard API". Save the changes and then click on the profile hyperlink.
Inside your profile screen click the box to "Generate new API Key". Copy this key down on a notepad.
Using a Linux server create a variable with the API key value using the following command and your apikey value:
export apikey=41aa26b8fasdfasdfadsfasdfasdfasdfda45f408
Now we need to find our Company Organization ID with the following command:
curl --location --request GET "https://dashboard.meraki.com/api/v0/organizations" \
--header "X-Cisco-Meraki-API-Key: $apikey" | jq .
(This requires a seperate install of the command line JSON processor JQ.)
Now we are ready to create a second variable for Org ID:
export organizationId=6zzzz4
We can now run an API command for "devices/statuses" to do a dump of all devices with all variables:
curl --location --request GET "https://dashboard.meraki.com/api/v1/organizations/$organizationId/devices/statuses" \
--header "X-Cisco-Meraki-API-Key: $apikey" | jq .
The general JSON variables we can now play with are:
"name", "serial", "mac", "publicIp", "networkId", "status", "lastReportedAt",
The access points and switches have additional variables for:
"lanIp", "gateway", "ipType", "primaryDns", "secondaryDns"
Finally, the MX security appliances have the following additional variables:
"usingCellularFailover", "wan1Ip", "wan1Gateway", "wan1IpType", "wan1PrimaryDns", "wan1SecondaryDns", "wan2Ip", "wan2Gateway", "wan2IpType", "wan2PrimaryDns", "wan2SecondaryDns",
I want to see the name, serial number, IP address, and model number of the assets so I am going to craft my command like this:
curl --location --request GET "https://dashboard.meraki.com/api/v1/organizations/$organizationId/devices/statuses" --header "X-Cisco-Meraki-API-Key: $apikey" | jq ".[] | [.name, .serial, .status, .lanIp, .wan1Ip] | @csv" | sed -e 's/"//g' | tr -d '\\'
The JQ command is creating a csv file with the data from the variables .name, .serial, .status, .lanIP, and .wan1Ip. I'm then using "sed" and "tr" to replace the extra \ and " characters.
Now I can copy this into Excel.
Again, frustratingly, Meraki doesn't give me all of the data I want in one place. I still would like the model number of the devices. While I'm at it, I might as well grab the MAC and the Network ID. This might come in handy at some point in the future.
The next API command is "inventoryDevices". We will craft the following command to pull the remaining variables from Meraki.
curl --location --request GET "https://dashboard.meraki.com/api/v1/organizations/$organizationId/inventoryDevices" \
--header "X-Cisco-Meraki-API-Key: $apikey" | jq ".[] | [.serial, .mac, .networkId, .model] | u/csv" | sed -e 's/"//g' | tr -d '\\'
While this output is great, it doesn't line up with the other spreadsheet list. I have way more devices in this inventoryDevices list that are not being used or were never claimed and I can not just do a "1 for 1" import into the other devices/statuses spreadsheet.
Fine... lets copy the data to a second tab within excel.
This next part gets a little tricky. We will use the "vlookup" function in excel to cross-reference the serial numbers from tab 1, column B to the inventory list on tab 2 using the entire dataset (Sheet2!A1:D132). Then we want to instruct vlookup to return the value of column 3 (mac) and only if the serial numbers are exact matches (TRUE).
For .mac, (F2) =VLOOKUP($B2,Sheet2!A1:D132,2,TRUE)
For .networkId (G2) =VLOOKUP($B2,Sheet2!A1:D132,3,TRUE)
For .model (H2) =VLOOKUP($B2,Sheet2!A1:D132,4,TRUE)
Then copy this to the remaining cells in the Sheet1 inventory to complete the data import.
I know this sounds like a lot but once you get used to the techniques it only takes a few minutes. The pay off is worth it. You will now have a complete, accurate inventory of all devices, with all the important variables, in one place!
No comments:
Post a Comment