import sys, httplib def pingHost(host, port): """ Ping the node defined by the given host name/port number. host: Hostname (string). port: Port number (integer). Returns: 1 = host could be accessed, 0 host inaccessible (integer/0|1). """ try: httpObj = httplib.HTTPConnection(host, port) httpObj.request("GET", "/STATUS") respObj = httpObj.getresponse() respObj.read() return 1 except Exception, e: return 0 if __name__ == '__main__': """ Main program. """ try: host = sys.argv[1] port = int(sys.argv[2]) except Exception, e: raise Exception, "Correct usage: ngamsPingHost " stat = pingHost(host, port) if (stat): print "Status of pinging host: %s:%s: OK" % (host, str(port)) sys.exit(0) else: print "Status of pinging host: %s:%s: INACCESSIBLE" % (host, str(port)) sys.exit(1) # EOF