def processStationMsg(cnt,msg): global conn station = msg.station utctimestamp = msg.timestamp - timezoneOffsetInSeconds timestamp = datetime.datetime.fromtimestamp(utctimestamp).strftime('%Y-%m-%d %H:%M:%S') macaddr = str(":".join("%02x" % ord(a) for a in station.sta_eth_mac.addr)) username = station.username role = station.role bssid = str(":".join("%02x" % ord(a) for a in station.bssid.addr)) device_type = station.device_type ip_addr = (".".join("%d" % ord(a) for a in station.sta_ip_address.addr)) if verbose >= 1: print "---- STATION [record %.5d : %s] ------------" % (cnt, macaddr) if verbose >=2: print "Timestamp: %s (UTC)" % (timestamp) print "Station Mac: %s" % (macaddr) print "Username: %s" % (username) print "Role: %s" % (role) print "BSSID: %s" % (bssid) print "Device Type: %s" % (device_type) print "IP Address: %s" % (ip_addr) if storeInDB: endpoint_id = ale_dbi.updateEndpointByMac(conn,macaddr,'station') ale_dbi.updateEndpointDetails(conn,endpoint_id,username,role,bssid,device_type,ip_addr) return('SUCCESS','')
def processProximityMsg(cnt,msg): global conn proximity = msg.proximity utctimestamp = msg.timestamp - timezoneOffsetInSeconds timestamp = datetime.datetime.fromtimestamp(utctimestamp).strftime('%Y-%m-%d %H:%M:%S') macaddr = str(":".join("%02x" % ord(a) for a in proximity.sta_eth_mac.addr)) ap_name = None try: ap_name = proximity.ap_name except AttributeError: pass # print "ap_name=", ap_name radio_mac = None rssi = 0 try: rssi = proximity.rssi_val except AttributeError: pass try: radio_mac = str(":".join("%02x" % ord(a) for a in proximity.radio_mac.addr)) except AttributeError: pass if storeInDB and radio_mac: radio_id = ale_dbi.getAPIdByRadioMac(conn,radio_mac) if verbose >= 1: print "---- PROXIMITY [record %.5d : %s] ------------" % (cnt, macaddr) if verbose >= 2: print "Timestamp: %s (UTC)" % (timestamp) print "Station Mac: %s" % (macaddr) if radio_mac: print "Radio Mac: %s" % (radio_mac) if rssi: print "RSSI: %3d" % (rssi) if ap_name: ap_name = ap_name.encode('utf-8') print "Detecting AP: %s" % (ap_name,) print "PROXIMITY Summary,%s,%s,%d,%s" % (timestamp,macaddr,rssi,ap_name) else: print "PROXIMITY Summary,%s,%s,%d" % (timestamp,macaddr,rssi) if storeInDB: radio_id = ale_dbi.getAPIdByRadioMac(conn,radio_mac) # print "radio_id = ", radio_mac, radio_id endpoint_id = ale_dbi.updateEndpointByMac(conn,macaddr,'proximity',None,rssi) if storeProximityInDB: ale_dbi.addPresence(conn,endpoint_id,timestamp,isAssociated=None,ap_name=ap_name,radio_id=radio_id,server_id=server_id,rssi=rssi) return('SUCCESS','')
def processPresenceMsg(cnt,msg): global conn presence = msg.presence utctimestamp = msg.timestamp - timezoneOffsetInSeconds timestamp = datetime.datetime.fromtimestamp(utctimestamp).strftime('%Y-%m-%d %H:%M:%S') macaddr = str(":".join("%02x" % ord(a) for a in presence.sta_eth_mac.addr)) isAssociated = presence.associated ap_name = None try: ap_name = presence.ap_name except AttributeError: pass # print "ap_name=", ap_name radio_mac = None try: radio_mac = str(":".join("%02x" % ord(a) for a in presence.radio_mac.addr)) except AttributeError: pass if storeInDB and radio_mac: radio_id = ale_dbi.getAPIdByRadioMac(conn,radio_mac) if verbose >= 1: print "---- PRESENCE [record %.5d : %s] ------------" % (cnt, macaddr) if verbose >= 2: print "Timestamp: %s (UTC)" % (timestamp) print "Station Mac: %s" % (macaddr) print "Associated: %s" % (isAssociated) if radio_mac: print "Radio Mac: %s" % (radio_mac) if ap_name: ap_name = ap_name.encode('utf-8') print "Detecting AP Name: %s" % (ap_name,) print "PRESENCE Summary,%s,%s,%s" % (timestamp,macaddr,presence.associated) else: print "PRESENCE Summary,%s,%s,%s" % (timestamp,macaddr,presence.associated) if storeInDB: radio_id = ale_dbi.getAPIdByRadioMac(conn,radio_mac) # print "radio_id = ", radio_mac, radio_id endpoint_id = ale_dbi.updateEndpointByMac(conn,macaddr,'presence',isAssociated) if storePresenceInDB: ale_dbi.addPresence(conn,endpoint_id,timestamp,isAssociated,ap_name,radio_id,server_id) return('SUCCESS','')
def processRSSIMsg(cnt,msg): global conn rssi = msg.rssi # In ALE 1.x, the message is 'rssi', in ALE 2.0 message is 'sta_rssi' msgType = 'rssi' # For ALE 2.0, the message for Station RSSI has changed from 'rssi' to 'sta_rssi' if not rssi.HasField('sta_eth_mac'): rssi = msg.sta_rssi utctimestamp = msg.timestamp - timezoneOffsetInSeconds timestamp = datetime.datetime.fromtimestamp(utctimestamp).strftime('%Y-%m-%d %H:%M:%S') macaddr = str(":".join("%02x" % ord(a) for a in rssi.sta_eth_mac.addr)) isAssociated = rssi.associated # ap_mac = gn.access_point_info.ap_mac # print ap_mac # ap_mac_addr = ap_mac.addr # print ap_mac_addr radio_mac = str(":".join("%02x" % ord(a) for a in rssi.radio_mac.addr)) rssi_val = rssi.rssi_val if rssi_val > 100: # Something is wrong from ALE. Ignore the value rssi_val = 0; # ALE 2.0 has these extra fields age = None noise_floor = None assoc_bssid = None try: rssi.HasField('age') age = rssi.age except ValueError: pass try: rssi.HasField('noise_floor') noise_floor = rssi.noise_floor except ValueError: pass try: rssi.HasField('assoc_bssid') assoc_bssid = str(":".join("%02x" % ord(a) for a in rssi.assoc_bssid.addr)) except ValueError: pass if storeInDB: ap_id = ale_dbi.getAPIdByRadioMac(conn,radio_mac) (ap_wired_mac,ap_name) = ale_dbi.getAPNameById(conn,ap_id) else: ap_id = 0 ap_wired_mac = "" ap_name = "" if verbose >= 1: print "---- RSSI [record %.5d : %s] ------------" % (cnt, macaddr) if verbose >= 2: print "Timestamp: %s (UTC)" % (timestamp) print "Station Mac: %s" % (macaddr) print "Associated: %s" % (isAssociated) print "Radio Mac: %s" % (radio_mac) if storeInDB: print "AP Wired Mac: %s (%s)" % (ap_wired_mac,ap_name) print "RSSI: %4d" % (rssi_val) if age: print "Age: %4d" % (age) if noise_floor: print "Noise Floor: %4d" % (noise_floor) if assoc_bssid: print "Associated BSSID: %s (%s)" % (assoc_bssid,oui.getVendor(assoc_bssid)) if storeInDB: endpoint_id = ale_dbi.updateEndpointByMac(conn,macaddr,'rssi',isAssociated,rssi_val) if storeRSSIInDB: radio_id = ale_dbi.getRadioIdByMac(conn,radio_mac) ale_dbi.addRSSI(conn,endpoint_id,timestamp,radio_id,rssi_val,isAssociated,age,noise_floor,assoc_bssid) return('SUCCESS','')
def processLocationMsg(cnt, msg): global conn location = msg.location # unpack mac address macaddr = str(":".join("%02x" % ord(a) for a in location.sta_eth_mac.addr)) try: measured_x = float(location.sta_location_x) except ValueError: measured_x = 0.0 try: measured_y = float(location.sta_location_y) except ValueError: measured_y = 0.0 isAssociated = location.associated utctimestamp = msg.timestamp - timezoneOffsetInSeconds timestamp = datetime.datetime.fromtimestamp(utctimestamp).strftime('%Y-%m-%d %H:%M:%S') algo_str = "Unknown" algo_str = ale_enums.algorithm[location.loc_algorithm] # for hex encoded strings, use <thing>.encode("hex") floor_id = location.floor_id.encode("hex").upper() building_id = location.building_id.encode("hex").upper() campus_id = location.campus_id.encode("hex").upper() if location.HasField("unit"): unit = location.unit else: unit = None if storeInDB: floor_db_id = ale_dbi.floorIDToDBID(conn,floor_id) building_db_id = ale_dbi.buildingIDToDBID(conn,building_id) campus_db_id = ale_dbi.campusIDToDBID(conn,campus_id) if campus_db_id == 0: campus_db_id = ale_dbi.updateCampus(conn,campus_id,"UNKNOWN",server_id) if building_db_id == 0: building_db_id = ale_dbi.updateBuilding(conn,building_id,"UNKNOWN",campus_db_id) if floor_db_id == 0: floor_db_id = ale_dbi.updateFloor(conn,floor_id,"UNKNOWN",None,None,None,None,None,building_db_id,None,None,None) else: floor_db_id = 0 building_db_id = 0 campus_db_id = 0 if verbose >= 1: print "---- LOCATION [record %.5d : %s] ------------" % (cnt, macaddr) if verbose >= 2: print "Timestamp: %s (UTC)" % timestamp print "Coordinates: (%.1f, %.1f) " % (measured_x, measured_y) if unit != None: print "Unit: %s " % (ale_enums.measurement_unit[unit]) print "Algorithm: %s" % (algo_str) print "Station Mac: %s" % (macaddr) print "Associated: %s" % (isAssociated) print "FloorID: %s (%d)" % (floor_id, floor_db_id) print "BuildingID: %s (%d)" % (building_id, building_db_id) print "CampusID: %s (%d)" % (campus_id, campus_db_id) if storeInDB: endpoint_id = ale_dbi.updateEndpointByMac(conn,macaddr,'location',isAssociated) if storeLocationInDB: ale_dbi.addLocation(conn,endpoint_id,timestamp, ale_dbi.campusIDToDBID(conn,campus_id), ale_dbi.buildingIDToDBID(conn,building_id), ale_dbi.floorIDToDBID(conn,floor_id), measured_x, measured_y, location.loc_algorithm) return('SUCCESS','')