def updateNetworkStatus(foo=0, bar=0): #logger.warning("updateNetworkStatus called") try: sock = None servers = [ dict(name= 'twitter.com' ), dict(name= 'google.com' ), dict(name= 'cocomsp.com' ), dict(name= 'github.com' ), dict(name= 'reddit.com' ), dict(name= 'facebook.com' ), # dict(name= 'expertocrede.com' ), ] import subprocess import re def do_ping(addr): try: cmdStr = "/bin/ping -c 1 -w 1 %s " % addr p = subprocess.Popen(cmdStr, shell=True, stdout=subprocess.PIPE) p.wait() line = p.stdout.read() match = re.search('(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+) ms', line) if match is None: return -1 return match.group(1) except Exception, e: print 'foo ' + str(e) return -1 for s in servers: s['delay'] = do_ping(s['name']) red = chr(30) green = chr(29) amber = chr(31) # sock = board.get_connection() curRowNum = 0 for s in servers: msg = s['name'] + ": " board.write_line_split(sock, 0, curRowNum, 0, msg ) delayNum = float(s['delay']) colorStr = green if delayNum > 250: colorStr = red elif delayNum > 125: colorStr = amber elif delayNum < 0: colorStr = red s['delay'] = "DOWN" delayStr = colorStr + str(s['delay']) + " " board.write_line_split(sock, 0, curRowNum, 20, delayStr ) curRowNum += 1 board.write_line_split(sock, 0, curRowNum, 0, " " )
def updateNetworkStatus(foo=0, bar=0): #logger.warning("updateNetworkStatus called") try: sock = None servers = [ dict(name='twitter.com'), dict(name='google.com'), dict(name='cocomsp.com'), dict(name='github.com'), dict(name='reddit.com'), dict(name='facebook.com'), # dict(name= 'expertocrede.com' ), ] import subprocess import re def do_ping(addr): try: cmdStr = "/bin/ping -c 1 -w 1 %s " % addr p = subprocess.Popen(cmdStr, shell=True, stdout=subprocess.PIPE) p.wait() line = p.stdout.read() match = re.search('(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+) ms', line) if match is None: return -1 return match.group(1) except Exception, e: print 'foo ' + str(e) return -1 for s in servers: s['delay'] = do_ping(s['name']) red = chr(30) green = chr(29) amber = chr(31) # sock = board.get_connection() curRowNum = 0 for s in servers: msg = s['name'] + ": " board.write_line_split(sock, 0, curRowNum, 0, msg) delayNum = float(s['delay']) colorStr = green if delayNum > 250: colorStr = red elif delayNum > 125: colorStr = amber elif delayNum < 0: colorStr = red s['delay'] = "DOWN" delayStr = colorStr + str(s['delay']) + " " board.write_line_split(sock, 0, curRowNum, 20, delayStr) curRowNum += 1 board.write_line_split(sock, 0, curRowNum, 0, " ")
msg = s['name'] + ": " board.write_line_split(sock, 0, curRowNum, 0, msg ) delayNum = float(s['delay']) colorStr = green if delayNum > 250: colorStr = red elif delayNum > 125: colorStr = amber elif delayNum < 0: colorStr = red s['delay'] = "DOWN" delayStr = colorStr + str(s['delay']) + " " board.write_line_split(sock, 0, curRowNum, 20, delayStr ) curRowNum += 1 board.write_line_split(sock, 0, curRowNum, 0, " " ) except Exception, e: print "Unexpected error:", sys.exc_info()[0] board.write_line_split(sock, 0, curRowNum, 0, "--errors, could not finish" ) finally: if sock is not None: board.close_connection(sock) return 0
board.write_line_split(sock, 0, curRowNum, 0, msg) delayNum = float(s['delay']) colorStr = green if delayNum > 250: colorStr = red elif delayNum > 125: colorStr = amber elif delayNum < 0: colorStr = red s['delay'] = "DOWN" delayStr = colorStr + str(s['delay']) + " " board.write_line_split(sock, 0, curRowNum, 20, delayStr) curRowNum += 1 board.write_line_split(sock, 0, curRowNum, 0, " ") except Exception, e: print "Unexpected error:", sys.exc_info()[0] board.write_line_split(sock, 0, curRowNum, 0, "--errors, could not finish") finally: if sock is not None: board.close_connection(sock) return 0