Пример #1
0
    def testHTTPHeaders(self):
        agentConfig = {
            'version': AGENT_VERSION,
            'api_key': 'toto'
        }

        config = {
            'init_config': {},
            'instances': [{
                'url': 'https://google.com',
                'name': 'UpService',
                'timeout': 1,
                'headers': {"X-Auth-Token": "SOME-AUTH-TOKEN"}
            }]
        }

        self.load_check(config, agentConfig)
        url, username, password, http_response_status_code, timeout,\
            include_content, headers, response_time, content_match,\
            tags, ssl, ssl_expiration,\
            instance_ca_certs = self.check._load_conf(config['instances'][0])

        self.assertEqual(headers["X-Auth-Token"], "SOME-AUTH-TOKEN", headers)
        expected_headers = agent_headers(agentConfig).get('User-Agent')
        self.assertEqual(expected_headers, headers.get('User-Agent'), headers)
Пример #2
0
    def _load_conf(self, instance):
        # Fetches the conf
        tags = instance.get("tags", [])
        username = instance.get("username")
        password = instance.get("password")
        http_response_status_code = instance.get("http_response_status_code", "(1|2|3)\d\d")
        timeout = int(instance.get("timeout", 10))
        config_headers = instance.get("headers", {})
        headers = agent_headers(self.agentConfig)
        headers.update(config_headers)
        url = instance.get("url")
        content_match = instance.get("content_match")
        response_time = _is_affirmative(instance.get("collect_response_time", True))
        if not url:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(instance.get("include_content", False))
        ssl = _is_affirmative(instance.get("disable_ssl_validation", True))
        ssl_expire = _is_affirmative(instance.get("check_certificate_expiration", True))

        return (
            url,
            username,
            password,
            http_response_status_code,
            timeout,
            include_content,
            headers,
            response_time,
            content_match,
            tags,
            ssl,
            ssl_expire,
        )
Пример #3
0
    def _load_conf(self, instance):
        # Fetches the conf
        tags = instance.get('tags', [])
        username = instance.get('username')
        password = instance.get('password')
        http_response_status_code = str(instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
        timeout = int(instance.get('timeout', 10))
        config_headers = instance.get('headers', {})
        headers = agent_headers(self.agentConfig)
        headers.update(config_headers)
        url = instance.get('url')
        content_match = instance.get('content_match')
        response_time = _is_affirmative(instance.get('collect_response_time', True))
        if not url:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(instance.get('include_content', False))
        ssl = _is_affirmative(instance.get('disable_ssl_validation', True))
        ssl_expire = _is_affirmative(instance.get('check_certificate_expiration', True))
        instance_ca_certs = instance.get('ca_certs', self.ca_certs)
        weakcipher = _is_affirmative(instance.get('weakciphers', False))
        ignore_ssl_warning = _is_affirmative(instance.get('ignore_ssl_warning', False))
        skip_proxy = _is_affirmative(instance.get('no_proxy', False))

        return url, username, password, http_response_status_code, timeout, include_content,\
            headers, response_time, content_match, tags, ssl, ssl_expire, instance_ca_certs,\
            weakcipher, ignore_ssl_warning, skip_proxy
Пример #4
0
    def _load_conf(self, instance):
        # Fetches the conf
        tags = instance.get('tags', [])
        username = instance.get('username')
        password = instance.get('password')
        http_response_status_code = str(
            instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
        timeout = int(instance.get('timeout', 10))
        config_headers = instance.get('headers', {})
        headers = agent_headers(self.agentConfig)
        headers.update(config_headers)
        url = instance.get('url')
        content_match = instance.get('content_match')
        response_time = _is_affirmative(
            instance.get('collect_response_time', True))
        if not url:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(
            instance.get('include_content', False))
        ssl = _is_affirmative(instance.get('disable_ssl_validation', True))
        ssl_expire = _is_affirmative(
            instance.get('check_certificate_expiration', True))
        instance_ca_certs = instance.get('ca_certs', self.ca_certs)
        weakcipher = _is_affirmative(instance.get('weakciphers', False))
        ignore_ssl_warning = _is_affirmative(
            instance.get('ignore_ssl_warning', False))

        return url, username, password, http_response_status_code, timeout, include_content,\
            headers, response_time, content_match, tags, ssl, ssl_expire, instance_ca_certs,\
            weakcipher, ignore_ssl_warning
Пример #5
0
    def test_http_headers(self):
        """
        Headers format.
        """
        # Run the check
        self.load_check(CONFIG_HTTP_HEADERS, AGENT_CONFIG)
        headers = self.check._load_conf(CONFIG_HTTP_HEADERS['instances'][0])[8]

        self.assertEqual(headers["X-Auth-Token"], "SOME-AUTH-TOKEN", headers)
        expected_headers = agent_headers(AGENT_CONFIG).get('User-Agent')
        self.assertEqual(expected_headers, headers.get('User-Agent'), headers)
Пример #6
0
    def test_http_headers(self):
        """
        Headers format.
        """
        # Run the check
        self.load_check(CONFIG_HTTP_HEADERS, AGENT_CONFIG)
        headers = self.check._load_conf(CONFIG_HTTP_HEADERS['instances'][0])[8]

        self.assertEqual(headers["X-Auth-Token"], "SOME-AUTH-TOKEN", headers)
        expected_headers = agent_headers(AGENT_CONFIG).get('User-Agent')
        self.assertEqual(expected_headers, headers.get('User-Agent'), headers)
Пример #7
0
    def test_http_headers(self):
        """
        Headers format.
        """
        # Run the check
        self.load_check(CONFIG_HTTP_HEADERS, AGENT_CONFIG)

        url, username, password, http_response_status_code, timeout,\
            include_content, headers, response_time, content_match,\
            tags, ssl, ssl_expiration,\
            instance_ca_certs = self.check._load_conf(CONFIG_HTTP_HEADERS['instances'][0])

        self.assertEqual(headers["X-Auth-Token"], "SOME-AUTH-TOKEN", headers)
        expected_headers = agent_headers(AGENT_CONFIG).get('User-Agent')
        self.assertEqual(expected_headers, headers.get('User-Agent'), headers)
Пример #8
0
    def test_http_headers(self):
        """
        Headers format.
        """
        # Run the check
        self.load_check(CONFIG_HTTP_HEADERS, AGENT_CONFIG)

        url, username, password, http_response_status_code, timeout,\
            include_content, headers, response_time, content_match,\
            tags, ssl, ssl_expiration,\
            instance_ca_certs = self.check._load_conf(CONFIG_HTTP_HEADERS['instances'][0])

        self.assertEqual(headers["X-Auth-Token"], "SOME-AUTH-TOKEN", headers)
        expected_headers = agent_headers(AGENT_CONFIG).get('User-Agent')
        self.assertEqual(expected_headers, headers.get('User-Agent'), headers)
Пример #9
0
 def _load_conf(self, instance):
     # Fetches the conf
     tags = instance.get('tags', [])
     username = instance.get('username', None)
     password = instance.get('password', None)
     timeout = int(instance.get('timeout', 10))
     config_headers = instance.get('headers',{})
     headers = agent_headers(self.agentConfig)
     headers.update(config_headers)
     url = instance.get('url', None)
     response_time = instance.get('collect_response_time', True)
     if url is None:
         raise Exception("Bad configuration. You must specify a url")
     include_content = instance.get('include_content', False)
     ssl = instance.get('disable_ssl_validation', True)
     return url, username, password, timeout, include_content, headers, response_time, tags, ssl
    def testHTTPHeaders(self):
        config = {
            'init_config': {},
            'instances': [{
                'url': 'https://google.com',
                'name': 'UpService',
                'timeout': 1,
                'headers': { "X-Auth-Token": "SOME-AUTH-TOKEN"}
            }]
        }

        self.init_check(config, 'http_check')
        url, username, password, timeout, include_content, headers, response_time, tags, ssl = self.check._load_conf(config['instances'][0])

        self.assertTrue(headers["X-Auth-Token"] == "SOME-AUTH-TOKEN", headers)
        self.assertTrue(headers.get('User-Agent') == agent_headers(self.agentConfig).get('User-Agent'), headers)
Пример #11
0
    def _load_conf(self, instance):
        # Fetches the conf
        method = instance.get('method', 'get')
        data = instance.get('data', {})
        tags = instance.get('tags', [])
        username = instance.get('username')
        password = instance.get('password')
        client_cert = instance.get('client_cert')
        client_key = instance.get('client_key')
        http_response_status_code = str(
            instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
        timeout = int(instance.get('timeout', 10))
        config_headers = instance.get('headers', {})
        default_headers = _is_affirmative(
            instance.get("include_default_headers", True))
        if default_headers:
            headers = agent_headers(self.agentConfig)
        else:
            headers = {}
        headers.update(config_headers)
        url = instance.get('url')
        content_match = instance.get('content_match')
        reverse_content_match = _is_affirmative(
            instance.get('reverse_content_match', False))
        response_time = _is_affirmative(
            instance.get('collect_response_time', True))
        if not url:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(
            instance.get('include_content', False))
        disable_ssl_validation = _is_affirmative(
            instance.get('disable_ssl_validation', True))
        ssl_expire = _is_affirmative(
            instance.get('check_certificate_expiration', True))
        instance_ca_certs = instance.get('ca_certs', self.ca_certs)
        weakcipher = _is_affirmative(instance.get('weakciphers', False))
        ignore_ssl_warning = _is_affirmative(
            instance.get('ignore_ssl_warning', False))
        check_hostname = _is_affirmative(instance.get('check_hostname', True))
        skip_proxy = _is_affirmative(
            instance.get('skip_proxy', instance.get('no_proxy', False)))
        allow_redirects = _is_affirmative(instance.get('allow_redirects',
                                                       True))

        return url, username, password, client_cert, client_key, method, data, http_response_status_code, timeout, include_content,\
            headers, response_time, content_match, reverse_content_match, tags, disable_ssl_validation, ssl_expire, instance_ca_certs,\
            weakcipher, check_hostname, ignore_ssl_warning, skip_proxy, allow_redirects
Пример #12
0
    def testHTTPHeaders(self):
        config = {
            'init_config': {},
            'instances': [{
                'url': 'https://google.com',
                'name': 'UpService',
                'timeout': 1,
                'headers': {"X-Auth-Token": "SOME-AUTH-TOKEN"}
            }]
        }

        self.init_check(config, 'http_check')
        url, username, password, timeout, http_response_status_code, include_content, headers, \
            response_time, content_match, tags, ssl, \
            ssl_expiration = self.check._load_conf(config['instances'][0])

        self.assertTrue(headers["X-Auth-Token"] == "SOME-AUTH-TOKEN", headers)
        self.assertTrue(headers.get('User-Agent') == agent_headers(self.agentConfig).get('User-Agent'), headers)
Пример #13
0
    def _load_conf(self, instance):
        # Fetches the conf
        tags = instance.get("tags", [])
        username = instance.get("username")
        password = instance.get("password")
        http_response_status_code = str(instance.get("http_response_status_code", DEFAULT_EXPECTED_CODE))
        timeout = int(instance.get("timeout", 10))
        config_headers = instance.get("headers", {})
        headers = agent_headers(self.agentConfig)
        headers.update(config_headers)
        url = instance.get("url")
        content_match = instance.get("content_match")
        response_time = _is_affirmative(instance.get("collect_response_time", True))
        if not url:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(instance.get("include_content", False))
        ssl = _is_affirmative(instance.get("disable_ssl_validation", True))
        ssl_expire = _is_affirmative(instance.get("check_certificate_expiration", True))
        instance_ca_certs = instance.get("ca_certs", self.ca_certs)
        weakcipher = _is_affirmative(instance.get("weakciphers", False))
        ignore_ssl_warning = _is_affirmative(instance.get("ignore_ssl_warning", False))
        skip_proxy = _is_affirmative(instance.get("no_proxy", False))
        allow_redirects = _is_affirmative(instance.get("allow_redirects", True))

        return (
            url,
            username,
            password,
            http_response_status_code,
            timeout,
            include_content,
            headers,
            response_time,
            content_match,
            tags,
            ssl,
            ssl_expire,
            instance_ca_certs,
            weakcipher,
            ignore_ssl_warning,
            skip_proxy,
            allow_redirects,
        )
Пример #14
0
    def testHTTPHeaders(self):
        config = {
            "init_config": {},
            "instances": [
                {
                    "url": "https://google.com",
                    "name": "UpService",
                    "timeout": 1,
                    "headers": {"X-Auth-Token": "SOME-AUTH-TOKEN"},
                }
            ],
        }

        self.init_check(config, "http_check")
        url, username, password, timeout, include_content, headers, response_time, tags, ssl, ssl_expiration = self.check._load_conf(
            config["instances"][0]
        )

        self.assertTrue(headers["X-Auth-Token"] == "SOME-AUTH-TOKEN", headers)
        self.assertTrue(headers.get("User-Agent") == agent_headers(self.agentConfig).get("User-Agent"), headers)
Пример #15
0
    def _load_conf(self, instance):
        # Fetches the conf
        tags = instance.get('tags', [])
        username = instance.get('username', None)
        password = instance.get('password', None)
        timeout = int(instance.get('timeout', 10))
        config_headers = instance.get('headers', {})
        headers = agent_headers(self.agentConfig)
        headers.update(config_headers)
        url = instance.get('url', None)
        response_time = _is_affirmative(
            instance.get('collect_response_time', True))
        if url is None:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(
            instance.get('include_content', False))
        ssl = _is_affirmative(instance.get('disable_ssl_validation', True))
        ssl_expire = _is_affirmative(
            instance.get('check_certificate_expiration', True))

        return url, username, password, timeout, include_content, headers, response_time, tags, ssl, ssl_expire
Пример #16
0
    def _load_conf(self, instance):
        # Fetches the conf
        tags = instance.get('tags', [])
        username = instance.get('username')
        password = instance.get('password')
        http_response_status_code = str(instance.get('http_response_status_code', "(1|2|3)\d\d"))
        timeout = int(instance.get('timeout', 10))
        config_headers = instance.get('headers', {})
        headers = agent_headers(self.agentConfig)
        headers.update(config_headers)
        url = instance.get('url')
        content_match = instance.get('content_match')
        response_time = _is_affirmative(instance.get('collect_response_time', True))
        if not url:
            raise Exception("Bad configuration. You must specify a url")
        include_content = _is_affirmative(instance.get('include_content', False))
        ssl = _is_affirmative(instance.get('disable_ssl_validation', True))
        ssl_expire = _is_affirmative(instance.get('check_certificate_expiration', True))

        return url, username, password, http_response_status_code, timeout, include_content,\
            headers, response_time, content_match, tags, ssl, ssl_expire
Пример #17
0
    def testHTTPHeaders(self):
        agentConfig = {'version': AGENT_VERSION, 'api_key': 'toto'}

        config = {
            'init_config': {},
            'instances': [{
                'url': 'https://google.com',
                'name': 'UpService',
                'timeout': 1,
                'headers': {
                    "X-Auth-Token": "SOME-AUTH-TOKEN"
                }
            }]
        }

        self.load_check(config, agentConfig)
        url, username, password, http_response_status_code, timeout,\
            include_content, headers, response_time, content_match,\
            tags, ssl, ssl_expiration = self.check._load_conf(config['instances'][0])

        self.assertEqual(headers["X-Auth-Token"], "SOME-AUTH-TOKEN", headers)
        expected_headers = agent_headers(agentConfig).get('User-Agent')
        self.assertEqual(expected_headers, headers.get('User-Agent'), headers)