|
1 |
| -# This is a script to print a list of all devices in a organization's inventory and their up/down status. |
2 |
| -# The script will not return up/down status for MV security cameras, as this was not supported at time of writing. |
3 |
| -# |
4 |
| -# To run the script, enter: |
5 |
| -# python deviceupdownstatus.py -k <api key> -o <org name> [-a <snmp auth key> -p <snmp priv key>] |
6 |
| -# |
7 |
| -# Mandatory arguments: |
8 |
| -# -k <api key> : Your Meraki Dashboard API key |
9 |
| -# -o <org name> : Your Dashboard Organization name |
10 |
| -# Optional arguments to use SNMPv3: |
11 |
| -# -a <snmp auth key> : SNMPv3 authentication key. Required for SNMPv3 |
12 |
| -# -p <snmp priv key> : SNMPv3 privacy key. Required for SNMPv3 |
13 |
| -# |
14 |
| -# Example: |
15 |
| -# python deviceupdownstatus.py -k 1234 -o "Meraki Inc" -a authpass123 -p privpass123 |
16 |
| -# |
17 |
| -# This script was developed using Python 3.6.4. You will need the Requests and PySNMP modules to run it. You can install |
18 |
| -# these modules via pip: |
19 |
| -# pip install requests |
20 |
| -# pip install pysnmp |
21 |
| -# |
22 |
| -# More info on these modules: |
23 |
| -# http://python-requests.org |
24 |
| -# http://pysnmp.sourceforge.net |
25 |
| -# |
26 |
| -# To make script chaining easier, all lines containing informational messages to the user |
27 |
| -# start with the character @ |
28 |
| -# |
29 |
| -# This file was last modified on 2018-03-01 |
| 1 | +readMe = '''This is a script to print a list of all devices in a organization's inventory and their up/down status. |
| 2 | + The script will not return up/down status for MV security cameras, as this was not supported at time of writing. |
| 3 | +
|
| 4 | +To run the script, enter: |
| 5 | + python deviceupdownstatus.py -k <api key> -o <org name> [-a <snmp auth key> -p <snmp priv key>] |
| 6 | +
|
| 7 | +Mandatory arguments: |
| 8 | + -k <api key> : Your Meraki Dashboard API key |
| 9 | + -o <org name> : Your Dashboard Organization name |
| 10 | +Optional arguments to use SNMPv3: |
| 11 | + -a <snmp auth key> : SNMPv3 authentication key. Required for SNMPv3 |
| 12 | + -p <snmp priv key> : SNMPv3 privacy key. Required for SNMPv3 |
| 13 | +
|
| 14 | +Example: |
| 15 | + python deviceupdownstatus.py -k 1234 -o "Meraki Inc" -a authpass123 -p privpass123 |
| 16 | +
|
| 17 | +This script was developed using Python 3.6.4. You will need the Requests and PySNMP modules to run it. You can install |
| 18 | + these modules via pip: |
| 19 | + pip install requests |
| 20 | + pip install pysnmp |
| 21 | +
|
| 22 | +More info on these modules: |
| 23 | + http://python-requests.org |
| 24 | + http://pysnmp.sourceforge.net''' |
30 | 25 |
|
31 | 26 | import sys, getopt, requests, json, time
|
32 | 27 | from pysnmp.hlapi import *
|
@@ -71,25 +66,7 @@ def printusertext(p_message):
|
71 | 66 |
|
72 | 67 |
|
73 | 68 | def printhelp():
|
74 |
| - #prints help text |
75 |
| - |
76 |
| - printusertext('This is a script to print a list of all devices in a organization\'s inventory and their up/down status.') |
77 |
| - printusertext(' The script will not return up/down status for MV security cameras, as this was not supported at time of writing.') |
78 |
| - printusertext('') |
79 |
| - printusertext('To run the script, enter:') |
80 |
| - printusertext(' python deviceupdownstatus.py -k <api key> -o <org name> [-a <snmp auth key> -p <snmp priv key>]') |
81 |
| - printusertext('') |
82 |
| - printusertext('Mandatory argument:s') |
83 |
| - printusertext(' -k <key> : Your Meraki Dashboard API key') |
84 |
| - printusertext(' -o <org name> : Your Dashboard Organization name') |
85 |
| - printusertext('Optional arguments to use SNMPv3:') |
86 |
| - printusertext(' -a <snmp auth key> : SNMPv3 authentication key. Required for SNMPv3') |
87 |
| - printusertext(' -p <snmp priv key> : SNMPv3 privacy key. Required for SNMPv3') |
88 |
| - printusertext('') |
89 |
| - printusertext('Example:') |
90 |
| - printusertext(' python deviceupdownstatus.py -k 1234 -o "Meraki Inc" -a authpass123 -p privpass123') |
91 |
| - printusertext('') |
92 |
| - printusertext('Use double quotes ("") in Windows to pass arguments containing spaces. Names are case-sensitive.') |
| 69 | + print(readMe) |
93 | 70 |
|
94 | 71 |
|
95 | 72 | def snmppolldevicestatuses (p_shardhost, p_usercommunity, p_authkey = '', p_privkey = ''):
|
@@ -279,7 +256,7 @@ def getinventory(p_apikey, p_shardhost, p_orgid):
|
279 | 256 |
|
280 | 257 | merakirequestthrottler()
|
281 | 258 | try:
|
282 |
| - r = requests.get('https://%s/api/v0/organizations/%s/inventory' % (p_shardhost, p_orgid), headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'}, timeout=(REQUESTS_CONNECT_TIMEOUT, REQUESTS_READ_TIMEOUT) ) |
| 259 | + r = requests.get('https://api.meraki.com/api/v0/organizations/%s/inventory' % p_orgid, headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'}, timeout=(REQUESTS_CONNECT_TIMEOUT, REQUESTS_READ_TIMEOUT) ) |
283 | 260 | except:
|
284 | 261 | printusertext('ERROR 09: Unable to contact Meraki cloud')
|
285 | 262 | sys.exit(2)
|
@@ -311,7 +288,7 @@ def getdevicename(p_apikey, p_shardhost, p_nwid, p_serial):
|
311 | 288 |
|
312 | 289 | merakirequestthrottler()
|
313 | 290 | try:
|
314 |
| - r = requests.get('https://%s/api/v0/networks/%s/devices/%s' % (p_shardhost, p_nwid, p_serial), headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'}, timeout=(REQUESTS_CONNECT_TIMEOUT, REQUESTS_READ_TIMEOUT) ) |
| 291 | + r = requests.get('https://api.meraki.com/api/v0/networks/%s/devices/%s' % (p_nwid, p_serial), headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'}, timeout=(REQUESTS_CONNECT_TIMEOUT, REQUESTS_READ_TIMEOUT) ) |
315 | 292 | except:
|
316 | 293 | printusertext('ERROR 10: Unable to contact Meraki cloud')
|
317 | 294 | sys.exit(2)
|
|
0 commit comments