예제 #1
0
def test_check_keypair(aggregator, instance):
    instance['private_key_file'] = PRIVATE_KEY_FILE
    instance['password'] = '******'
    check = CheckSSH('ssh_check', {}, [instance])
    check.check(instance)
    common._test_check(aggregator, instance)
    common.wait_for_threads()
예제 #2
0
def test_collect_metadata(version, metadata, datadog_agent):
    client = MagicMock()
    client.get_transport = MagicMock(
        return_value=namedtuple('Transport', ['remote_version'])(version))

    ssh = CheckSSH('ssh_check', {}, {}, list(common.INSTANCES.values()))
    ssh.check_id = 'test:123'
    ssh._collect_metadata(client)
    datadog_agent.assert_metadata('test:123', metadata)
예제 #3
0
def test_collect_bad_metadata(datadog_agent):
    client = MagicMock()
    client.get_transport = MagicMock(return_value=namedtuple(
        'Transport', ['remote_version'])('Cannot parse this'))

    ssh = CheckSSH('ssh_check', {}, {}, list(common.INSTANCES.values()))
    ssh.check_id = 'test:123'
    ssh._collect_metadata(client)
    datadog_agent.assert_metadata_count(1)
    datadog_agent.assert_metadata('test:123', {'flavor': 'unknown'})
예제 #4
0
    def test_ssh(self, aggregator):
        c = CheckSSH('ssh_check', {}, {}, list(self.INSTANCES.values()))

        nb_threads = threading.active_count()

        c.check(self.INSTANCES['main'])

        for sc in aggregator.service_checks(CheckSSH.SSH_SERVICE_CHECK_NAME):
            assert sc.status == CheckSSH.OK
            for tag in sc.tags:
                assert tag in ('instance:io.netgarage.org-22', 'optional:tag1')

        # Check that we've closed all connections, if not we're leaking threads
        assert nb_threads == threading.active_count()
예제 #5
0
def test_ssh(aggregator):
    check = CheckSSH('ssh_check', {}, [common.INSTANCES['main']])

    nb_threads = threading.active_count()

    check.check(common.INSTANCES['main'])

    for sc in aggregator.service_checks(CheckSSH.SSH_SERVICE_CHECK_NAME):
        assert sc.status == CheckSSH.OK
        for tag in sc.tags:
            assert tag in ('instance:io.netgarage.org-22', 'optional:tag1')

    # Check that we've closed all connections, if not we're leaking threads
    common.wait_for_threads()
    assert nb_threads == threading.active_count()
예제 #6
0
def test_metadata(aggregator, instance, datadog_agent):
    check = CheckSSH('ssh_check', {}, [instance])
    check.check_id = 'test:123'
    check.check(instance)

    _, _, flavor, raw_version = re.split(r'[-_]', common.SSH_SERVER_VERSION)
    major, minor = raw_version.split(".")

    version_metadata = {
        'version.scheme': 'ssh_check',
        'version.major': major,
        'version.minor': minor,
        'version.raw': common.SSH_SERVER_VERSION,
        'flavor': flavor,
    }

    datadog_agent.assert_metadata('test:123', version_metadata)

    common.wait_for_threads(
    )  # needed, otherwise the next won't count correctly threads
예제 #7
0
def test_ssh_bad_config(aggregator):

    nb_threads = threading.active_count()

    with pytest.raises(Exception):
        check = CheckSSH('ssh_check', {}, [common.INSTANCES['bad_auth']])
        check.check(common.INSTANCES['bad_auth'])

    with pytest.raises(Exception):
        check = CheckSSH('ssh_check', {}, [common.INSTANCES['bad_hostname']])
        check.check(common.INSTANCES['bad_hostname'])

    for sc in aggregator.service_checks(CheckSSH.SSH_SERVICE_CHECK_NAME):
        assert sc.status == CheckSSH.CRITICAL

    # Check that we've closed all connections, if not we're leaking threads
    common.wait_for_threads()
    assert nb_threads == threading.active_count()
예제 #8
0
    def test_ssh_bad_config(self, aggregator):
        c = CheckSSH('ssh_check', {}, {}, list(self.INSTANCES.values()))

        nb_threads = threading.active_count()

        with pytest.raises(Exception):
            c.check(self.INSTANCES['bad_auth'])

        with pytest.raises(Exception):
            c.check(self.INSTANCES['bad_hostname'])

        for sc in aggregator.service_checks(CheckSSH.SSH_SERVICE_CHECK_NAME):
            assert sc.status == CheckSSH.CRITICAL

        # Check that we've closed all connections, if not we're leaking threads
        assert nb_threads == threading.active_count()
예제 #9
0
def check():
    return CheckSSH("ssh_check", {}, {})
예제 #10
0
def test_check(aggregator, instance):
    check = CheckSSH('ssh_check', {}, [instance])
    check.check(instance)
    common._test_check(aggregator, instance)
    common.wait_for_threads()