Beispiel #1
0
 def check(self):
     netloc = ""
     code = 0
     reason = ""
     length = 0
     elapsed = 0
     try:
         start = time.time()
         o = urlparse(self._url)
         netloc = o.netloc
         if (o.scheme == "https"):
             if self._port != False:
                 port = int(self._port)
             else:
                 port = 443
             connection = HTTPSConnection(o.netloc, port, self._timeout)
         else:
             if self._port != False:
                 port = int(self._port)
             else:
                 port = 80
             connection = HTTPConnection(o.netloc, port, self._timeout)
         connection.timeout = self._timeout
         connection.request("GET", o.path)
         #netloc = o.netloc
         result = connection.getresponse()
         data = result.read()
         elapsed = (time.time() - start)
         length = str(len(data))
         code = result.status
         reason = result.reason
         if (int(result.status) == 200 or int(result.status) == 302 or int(result.status) == 301) and not (length == 0 or elapsed >= self._timeout):
             self._lastCheck = netloc + ":OK: code: " + str(code) + " " + reason + ", length: " +  str(length) + ", time: " + str(elapsed)
             logging.info(self._lastCheck)
             return True
     except socket.gaierror:
         reason = "Address not resolvable"
     except socket.error as e:
         reason = "Socket " + str(e)
     except Exception as e:
         reason = str(e)
     self._lastCheck = netloc + ":ERROR: code: " + str(code) + " " + reason + ", length: " +  str(length) + ", time: " + str(elapsed)
     logging.error(self._lastCheck)
     return False