Skip to content

Commit fccc494

Browse files
authored
Fix: GET SNMP no longer returns shard
1 parent 35052b3 commit fccc494

File tree

1 file changed

+27
-50
lines changed

1 file changed

+27
-50
lines changed

deviceupdownstatus.py

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
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'''
3025

3126
import sys, getopt, requests, json, time
3227
from pysnmp.hlapi import *
@@ -71,25 +66,7 @@ def printusertext(p_message):
7166

7267

7368
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)
9370

9471

9572
def snmppolldevicestatuses (p_shardhost, p_usercommunity, p_authkey = '', p_privkey = ''):
@@ -279,7 +256,7 @@ def getinventory(p_apikey, p_shardhost, p_orgid):
279256

280257
merakirequestthrottler()
281258
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) )
283260
except:
284261
printusertext('ERROR 09: Unable to contact Meraki cloud')
285262
sys.exit(2)
@@ -311,7 +288,7 @@ def getdevicename(p_apikey, p_shardhost, p_nwid, p_serial):
311288

312289
merakirequestthrottler()
313290
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) )
315292
except:
316293
printusertext('ERROR 10: Unable to contact Meraki cloud')
317294
sys.exit(2)

0 commit comments

Comments
 (0)