def test_proxy_url_has_default_port(self): hm = HTTPMonitor("10.20.30.40", "tester.test", "http://www.tester.test:80") hm._hostnameIp.append("192.168.20.100") hm.makeURL() self.assertEqual(hm._reqURL, "http://www.tester.test") self.assertEqual(hm._proxyIp, "10.20.30.40")
def test_noproxy_url_nondefault_port(self): hm = HTTPMonitor("192.168.20.100", "tester.test", "http://www.tester.test:8050") hm._hostnameIp.append("192.168.20.100") hm.makeURL() self.assertEqual(hm._reqURL, "http://www.tester.test:8050") self.assertIsNone(hm._proxyIp)
def test_regex_caseSensitive(self): body = "Hello Web!" hm = HTTPMonitor("10.20.30.40", "tester.test", "/path") hm.regex("hello", caseSensitive=True, invert=False) self.assertEqual(hm._checkRegex(body), { 'status': 'CRITICAL', 'msg': 'pattern not found' })
def test_regex_wrong_expression(self): body = "Hello Web!" hm = HTTPMonitor("10.20.30.40", "tester.test", "/path") hm.regex("[]*", caseSensitive=False, invert=False) self.assertEqual( hm._checkRegex(body), { 'status': 'CRITICAL', 'msg': "Could not compile regular expression: '[]*'" })
def test_redirect_stickyport_443(self): location = "http://example.org/" hm = HTTPMonitor("10.20.30.40", "tester.test", "/path", 443) hm._follow = "stickyport" hm._proxyIp = "" hm._hostnameIp.append("10.20.30.40") hm.makeURL() agent = RedirectAgentZ(Agent, onRedirect=hm._follow, port=hm._port, proxy=hm._proxyIp) self.assertEqual(agent._resolveLocation(hm._reqURL, location), "http://example.org:443/")
def test_redirect_sticky_with_proxy(self): location = "http://example.org/" hm = HTTPMonitor("10.20.30.40", "tester.test", "http://tester.test:8888/path", 3128) hm._follow = "sticky" hm._proxyIp = "10.10.10.10" hm._hostnameIp.append("10.20.30.50") hm.makeURL() agent = RedirectAgentZ(Agent, onRedirect=hm._follow, port=hm._port, proxy=hm._proxyIp) self.assertEqual(agent._resolveLocation(hm._reqURL, location), "http://tester.test/")
def collect(self, config): ds0 = config.datasources[0] hostname = ds0.params['hostname'] timeout = int(ds0.params['timeout']) port = int(ds0.params['port']) useSsl = ast.literal_eval(ds0.params['useSsl']) url = ds0.params['url'] ipaddress = ds0.params['ipAddress'] regex = ds0.params['regex'] caseSensitive = ds0.params['caseSensitive'] invert = ds0.params['invert'] onRedirect = ds0.params['onRedirect'] onRedirect = str(onRedirect) if onRedirect in ('False', ''): onRedirect = "fail" elif onRedirect == "True": onRedirect = "follow" basicAuthUser = ds0.params['basicAuthUser'] basicAuthPass = ds0.params['basicAuthPass'] proxyAuthUser = ds0.params['proxyAuthUser'] proxyAuthPassword = ds0.params['proxyAuthPassword'] log.info("HTTPMonitor collecting started for: {}".format(hostname or ipaddress or url)) chttp = HTTPMonitor(ipAddr=ipaddress, hostname=hostname, url=url, port=port, timeout=timeout, ssl=useSsl, follow=onRedirect) if proxyAuthUser: chttp.useProxy(proxyAuthUser, proxyAuthPassword) if basicAuthUser: chttp.useAuth(basicAuthUser, basicAuthPass) if regex: chttp.regex(regex, ast.literal_eval(caseSensitive), ast.literal_eval(invert)) return chttp.connect()
def collect(self, config): ds0 = config.datasources[0] hostname = ds0.params['hostname'] timeout = int(ds0.params['timeout']) port = int(ds0.params['port']) useSsl = ast.literal_eval(ds0.params['useSsl']) url = ds0.params['url'] ipaddress = ds0.params['ipAddress'] onRedirect = ast.literal_eval(ds0.params['onRedirect']) basicAuthUser = ds0.params['basicAuthUser'] basicAuthPass = ds0.params['basicAuthPass'] proxyAuthUser = ds0.params['proxyAuthUser'] proxyAuthPassword = ds0.params['proxyAuthPassword'] log.info("HTTPMonitor collecting started for a host: {}".format(hostname)) chttp = HTTPMonitor(ipAddr=ipaddress, hostname=hostname, url=url, port=port, timeout=timeout, ssl=useSsl, follow=onRedirect) if proxyAuthUser: chttp.useProxy(proxyAuthUser, proxyAuthPassword) if basicAuthUser: chttp.useAuth(basicAuthUser, basicAuthPass) return chttp.connect()
def test_proxy_nourl_nondefault_port(self): hm = HTTPMonitor("10.20.30.40", "tester.test", port=8050) hm._hostnameIp.append("192.168.20.100") hm.makeURL() self.assertEqual(hm._reqURL, "http://tester.test/") self.assertEqual(hm._proxyIp, "10.20.30.40")
def test_noproxy_pathonlyurl(self): hm = HTTPMonitor("192.168.20.100", "tester.test", "/path") hm._hostnameIp.append("192.168.20.100") hm.makeURL() self.assertEqual(hm._reqURL, "http://tester.test/path") self.assertIsNone(hm._proxyIp)
def test_regex_caseSensitive_invert(self): body = "Hello Web!" hm = HTTPMonitor("10.20.30.40", "tester.test", "/path") hm.regex("hello", caseSensitive=True, invert=True) self.assertEqual(hm._checkRegex(body), None)
def test_regex_found(self): body = "Hello Web!" hm = HTTPMonitor("10.20.30.40", "tester.test", "/path") hm.regex("Web", caseSensitive=False, invert=False) self.assertEqual(hm._checkRegex(body), None)