From 6b94e7b22ff4a7a3dacb1b718028e28f77d995c6 Mon Sep 17 00:00:00 2001 From: Charish Patel Date: Tue, 9 Apr 2019 15:47:43 -0400 Subject: [PATCH] Corrected some of the port functionality (PoE and Port status in two separate functions). --- meraki_api.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/meraki_api.py b/meraki_api.py index 8c6825d..1208fc5 100755 --- a/meraki_api.py +++ b/meraki_api.py @@ -15,7 +15,7 @@ requiredNamed = parser.add_argument_group('required arguments') optionalNamed = parser.add_argument_group('supplemental arguments') requiredNamed.add_argument('-k', '--api-key', required=True, help='''API key obtained from Meraki Dashboard admin account''') requiredNamed.add_argument('-d', '--device', choices=['switch', 'ap'], required=True, help='''Device type to be queried (Wireless AP or Switch)''') -requiredNamed.add_argument('-t', '--type', choices=['license', 'uplink', 'port', 'latency', 'ssid', 'failconn', 'connassoc', 'connauth', 'conndhcp', 'conndns', 'connsucc', 'clients'], required=True, help=''' +requiredNamed.add_argument('-t', '--type', choices=['license', 'uplink', 'port', 'poe', 'latency', 'ssid', 'failconn', 'connassoc', 'connauth', 'conndhcp', 'conndns', 'connsucc', 'clients'], required=True, help=''' -=EXPLANATION & USAGE=- I. All devices @@ -25,7 +25,9 @@ uplink: Status of Meraki device connection to the cloud -t uplink -n -s II. Switch Options -port: Get status on an individual switchport +port: Get status on an individual switchport (Enabled/Disabled) + -t port -s -p +poe: Get POE status on an individual switchport (Enabled/Disabled) -t port -s -p III. AP Options @@ -109,6 +111,22 @@ def uplinkstatus(args): exit(2) def portstat(args): # To be completed once switch ships in + "Returns the status of an individual port on a switch" + httpreq = merapi_url + "/devices/" + str(args.serial) + "/switchPorts/" + str(args.port) + try: + port_info = requests.get(httpreq, headers=headers).json() + except: + print("Unable to connect to Meraki Dashboard API.") + exit(3) + port_enabled = (port_info['enabled']) + if port_enabled == 'True': + print("enabled: " + str(port_enabled)) + exit(0) + elif port_enabled == 'False': + print("disabled: " + str(port_enabled)) + exit(2) + +def poeport(args): # To be completed once switch ships in "Returns the status of an individual port on a switch" httpreq = merapi_url + "/devices/" + str(args.serial) + "/switchPorts/" + str(args.port) try: @@ -123,14 +141,7 @@ def portstat(args): # To be completed once switch ships in elif port_poeEnabled == 'False': print("disabled: " + str(port_poeEnabled)) exit(2) - port_enabled = (port_info['enabled']) - if port_enabled == 'True': - print("enabled: " + str(port_poeEnabled)) - exit(0) - elif port_enabled == 'False': - print("disabled: " + str(port_poeEnabled)) - exit(2) - print(port_info) + def ssidstatus(args): "Retrieves configured SSID status (enabled or not)" httpreq = merapi_url + "/networks/" + str(args.networkid) + "/ssids/" + str(args.ssid) @@ -326,6 +337,8 @@ if args.device == 'switch': uplinkstatus(args) elif args.type == 'port': portstat(args) + elif args.type == 'poe': + poeport(args) elif args.device == 'ap': if args.type == 'license': licensestate(args)