def spark_get_top_talkers_cmd(api_key, net_id, room_id): client_traffic = {} sn_list = get_ap_list(api_key, net_id) table = PrettyTable(["Client", "Usage - kbytes past hour"]) for sn in sn_list: result = merakiapi.getclients(api_key, sn, timestamp=3600) for row in result: traf_sum = row['usage']['sent'] + row['usage']['recv'] description = row['description'].lower().replace(' ', '_').replace( '.', '_') if description not in client_traffic: client_traffic[description] = traf_sum elif description in client_traffic: client_traffic[ description] = client_traffic[description] + traf_sum else: continue for row in client_traffic: client_name = row client_usage = client_traffic[row] table_row = [client_name, client_usage] table.add_row(table_row) table.reversesort = True print(str(table.get_string(sortby="Usage - kbytes past hour"))) payload = { 'roomId': str(room_id), 'text': str(table.get_string(sortby="Usage - kbytes past hour")) } requests.post(spark_url, data=json.dumps(payload), headers=spark_header)
def spark_get_guest_clients_cmd(api_key, net_id, room_id): """ Creates a list of MR's with the 'guest_wireless' tag Counts clients on guest ip subnet """ sn_list = get_guest_ap_list(api_key, net_id) client_count = 0 table = PrettyTable(["Description", "IP", "MAC"]) for sn in sn_list: result = merakiapi.getclients(my_api_key, sn, timestamp=900) for row in result: subnet_regex = re.compile('10.4.17') match = subnet_regex.search(str(row['ip'])) if match is not None: client_count += 1 client_name = row['description'] client_ip = row['ip'] client_mac = row['mac'] table_row = [client_name, client_ip, client_mac] table.add_row(table_row) else: continue msg = "There are {0} users on the guest wireless network".format( str(client_count)) payload = {'roomId': str(room_id), 'text': str(msg)} payload2 = {'roomId': str(room_id), 'text': str(table)} requests.post(spark_url, data=json.dumps(payload), headers=spark_header) requests.post(spark_url, data=json.dumps(payload2), headers=spark_header)
def get_client_info(): print('Get Client list') for row in networkinfo: # print(row['name']) # Print statement to make sure there was data data_usage = m.getclients(apikey, row['serial'], timestamp=total_time, suppressprint=True) if data_usage is None: print('Nothing to see here') else: for i in data_usage: # print(data_usage) # Print statement to make sure there was data clientinfo.append( {'name': row['name'], \ 'description': i['description'], \ 'mac': i['mac'], \ 'vlan': i['vlan'], \ 'sent': i['usage']['sent'], \ 'recv': i['usage']['recv']})
def get_guest_count(): session_attributes = {} card_title = "Guest WiFi User Count" sn_list = get_guest_ap_list() client_count = 0 for sn in sn_list: result = merakiapi.getclients(my_api_key, sn, timestamp=900) for row in result: # simple regex filtering on a specific ip subnet subnet_regex = re.compile('10.4.17') match = subnet_regex.search(str(row['ip'])) if match is not None: client_count += 1 else: continue speech_output = "There are {0} users on the guest wifi".format(client_count) reprompt_text = "" should_end_session = True return build_response(session_attributes, build_speechlet_response( card_title, speech_output, reprompt_text, should_end_session))
def spark_get_mr_clients_cmd(api_key, net_id, room_id): """ Creates a list of MR's with the 'guest_wireless' tag Counts clients on guest ip subnet """ sn_list = get_ap_list(api_key, net_id) client_count = 0 mr_count = 0 table = PrettyTable(["Description", "IP", "MAC"]) for sn in sn_list: mr_count += 1 result = merakiapi.getclients(my_api_key, sn, timestamp=900) for row in result: client_count += 1 client_name = row['description'] client_ip = row['ip'] client_mac = row['mac'] table_row = [client_name, client_ip, client_mac] table.add_row(table_row) msg = "There are {0} users on the wireless network across {1} MR devices".format( str(client_count), str(mr_count)) payload = {'roomId': str(room_id), 'text': str(msg)} payload2 = {'roomId': str(room_id), 'text': str(table)} requests.post(spark_url, data=json.dumps(payload), headers=spark_header) requests.post(spark_url, data=json.dumps(payload2), headers=spark_header)
device_name = str(value) elif key == 'serial': device_serial = str(value) elif key == 'model': device_model = str(value) else: continue # For combined networks, only look at MX if 'MS' in device_model: device_id_list.append(device_serial) print ("SWITCHES TO MODIFY") print (device_id_list) for dev in device_id_list: switch_clients = merakiapi.getclients(api_key,dev) #print (switch_clients) for c in switch_clients: for key,value in c.items(): if key == 'switchport': c_port = str(value) elif key == 'ip': c_ip = str(value) elif key == 'vlan': c_vlan = str(value) elif key == 'dhcpHostname': c_name = str(value) else: continue if meraki_info.ip_address_string in c_ip and c_vlan == meraki_info.source_vlan: if c_port == meraki_info.uplink1 or c_port == meraki_info.uplink2: # SPECIFY UPLINK PORTS TO PROTECT