Author: viol Date: Thu Aug 11 14:28:58 2011 New Revision: 2718 Log: handle possible error send by the uhttpd on AP info request Modified: apps/ap-monitor/ap-mond.py Modified: apps/ap-monitor/ap-mond.py ============================================================================== --- apps/ap-monitor/ap-mond.py Wed Aug 10 15:26:18 2011 (r2717) +++ apps/ap-monitor/ap-mond.py Thu Aug 11 14:28:58 2011 (r2718) @@ -106,16 +106,21 @@ return " " def getClientHit(clientPisaIp): # returns the coresponding client hit of a client pisa IP - pisasdconf = subprocess.Popen(['pisasdconf', 'get_endpoints', clientPisaIp], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (pisasdconfOut, pisasdconfErr) = pisasdconf.communicate() - # INFO: pisasdconf writes to stderr - pisasdconfList = pisasdconfErr.split('\n') - if (len(pisasdconfList) > 0): - for elm in pisasdconfList: - if 'Endpoint:' in elm: - return elm.split(': ')[1] - else: - return '' + try: + pisasdconf = subprocess.Popen(['pisasdconf', 'get_endpoints', clientPisaIp], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (pisasdconfOut, pisasdconfErr) = pisasdconf.communicate() + # INFO: pisasdconf writes to stderr + pisasdconfList = pisasdconfErr.split('\n') + if (len(pisasdconfList) > 0): + for elm in pisasdconfList: + if 'Endpoint:' in elm: + return elm.split(': ')[1] + else: + return '' + pass + except: + print "Error executing pisascconf" + pass return '' pass @@ -123,19 +128,23 @@ clientIp = '' serviceIp = '' serviceHit = '' - hipconf = subprocess.Popen(['hipconf', 'get', 'ha', clientHit], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (hipconfOut,hipconfErr) = hipconf.communicate() - # INFO: hipconf writes to stderr - hipconfList = hipconfErr.split('\n') - if (len(hipconfList) >0): - for elm in hipconfList: - if 'Peer IP:' in elm: - clientIp = elm.split(': ')[1] - elif 'Local IP:' in elm: - serviceIp = elm.split(': ')[1] - elif 'Local HIT:' in elm: - serviceHit = elm.split(': ')[1] + try: + hipconf = subprocess.Popen(['hipconf', 'get', 'ha', clientHit], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (hipconfOut,hipconfErr) = hipconf.communicate() + # INFO: hipconf writes to stderr + hipconfList = hipconfErr.split('\n') + if (len(hipconfList) >0): + for elm in hipconfList: + if 'Peer IP:' in elm: + clientIp = elm.split(': ')[1] + elif 'Local IP:' in elm: + serviceIp = elm.split(': ')[1] + elif 'Local HIT:' in elm: + serviceHit = elm.split(': ')[1] + pass pass + except: + print "Error executing hipconf" pass return (clientIp, serviceIp, serviceHit) pass @@ -147,6 +156,11 @@ return False pass +def uhttpdErrorParser(rawString): + if rawString.startswith("{"): + return rawString + else: # remove everything before the JSON object + return ''.join(rawString.partition("{")[1:]) #AP-MON getApInfoHist = {} #apId:{'time':0,'apInfo':{}] @@ -185,6 +199,15 @@ pass try: page = json.load(urllib2.urlopen('http://192.168.5.' + apId + ':29868/request_ap_info', timeout=SOCKET_TIMEOUT)) + pass + except urllib2.HTTPError, error: + page = json.loads(uhttpdErrorParser(error.read())) + pass + except: + print "error requesting info from AP", apId + page = {} + pass + finally: if (len(infoTags) == 0): for tagName in INFO_TAGS: try: @@ -199,12 +222,6 @@ pass pass pass - except: #urllib2.HTTPError, error: - print "error requesting AP info" - #no info service - #print error.read() - #raise - pass pass getApInfoHist[apId] = {'time':time.time(),'apInfo':apInfo, 'requestDone':True} -- This is the pisa developer mailing list. Please also subscribe to the main pisa list at: //www.freelists.org/list/pisa