def test_service_check_connection_issues(aggregator, instance, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance)

    for metric in METRICS:
        aggregator.assert_metric(metric)

    for metric in OPTIONAL_METRICS:
        aggregator.assert_metric(metric, at_least=0)

    aggregator.assert_all_metrics_covered()

    tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'mq_host:{}'.format(common.HOST),
        'port:{}'.format(common.PORT),
    ]

    channel_tags = tags + ['channel:{}'.format(common.CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.OK,
                                    tags=channel_tags)
    bad_channel_tags = tags + ['channel:{}'.format(common.BAD_CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.CRITICAL,
                                    tags=bad_channel_tags)
def test_ssl_connection_creation(instance):
    """
    Test that we are not getting unicode/bytes type error.
    """
    # Late import to not require it for e2e
    import pymqi

    instance['ssl_auth'] = 'yes'
    instance['ssl_cipher_spec'] = 'TLS_RSA_WITH_AES_256_CBC_SHA256'
    instance['ssl_key_repository_location'] = '/dummy'

    check = IbmMqCheck('ibm_mq', {}, [instance])

    with pytest.raises(pymqi.MQMIError) as excinfo:
        check.check(instance)

    assert excinfo.value.reason == pymqi.CMQC.MQRC_KEY_REPOSITORY_ERROR

    assert len(check.warnings) == 1
    warning = check.warnings[0]

    # Check that we are not getting a unicode/bytes type error but a MQRC_KEY_REPOSITORY_ERROR (dummy location)
    assert 'bytes' not in warning
    assert 'unicode' not in warning
    assert 'MQRC_KEY_REPOSITORY_ERROR' in warning
Beispiel #3
0
def test_channel_status_service_check_custom_mapping_invalid_config(
        aggregator, instance, channel_status_mapping):
    instance['channel_status_mapping'] = channel_status_mapping
    check = IbmMqCheck('ibm_mq', {}, [instance])

    with pytest.raises(ConfigurationError):
        check.check(instance)
Beispiel #4
0
def test_check_metrics_and_service_checks(aggregator, instance, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance)

    _assert_all_metrics(aggregator)

    tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'mq_host:{}'.format(common.HOST),
        'port:{}'.format(common.PORT),
    ]

    channel_tags = tags + ['channel:{}'.format(common.CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.OK,
                                    tags=channel_tags,
                                    count=1)

    bad_channel_tags = tags + ['channel:{}'.format(common.BAD_CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.CRITICAL,
                                    tags=bad_channel_tags,
                                    count=1)

    discoverable_tags = tags + ['channel:*']
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.OK,
                                    tags=discoverable_tags,
                                    count=1)
Beispiel #5
0
def test_integration_custom_mapping(aggregator, instance, channel_status_mapping, expected_service_check_status):
    instance['channel_status_mapping'] = channel_status_mapping
    check = IbmMqCheck('ibm_mq', {}, [instance])

    check.check(instance)

    aggregator.assert_service_check('ibm_mq.channel.status', expected_service_check_status)
Beispiel #6
0
def test_check_metrics_and_service_checks(aggregator, instance, seed_data):
    instance['mqcd_version'] = os.getenv('IBM_MQ_VERSION')
    check = IbmMqCheck('ibm_mq', {}, [instance])

    check.check(instance)

    assert_all_metrics(aggregator)

    tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'mq_host:{}'.format(common.HOST),
        'port:{}'.format(common.PORT),
        'connection_name:{}({})'.format(common.HOST, common.PORT),
        'foo:bar',
    ]

    channel_tags = tags + ['channel:{}'.format(common.CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.OK,
                                    tags=channel_tags,
                                    count=1)

    bad_channel_tags = tags + ['channel:{}'.format(common.BAD_CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.CRITICAL,
                                    tags=bad_channel_tags,
                                    count=1)

    discoverable_tags = tags + ['channel:*']
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.OK,
                                    tags=discoverable_tags,
                                    count=1)
Beispiel #7
0
def test_check_connection_names_multi(aggregator, instance_with_connection_name):
    instance = instance_with_connection_name
    instance['mqcd_version'] = os.getenv('IBM_MQ_VERSION')
    instance['connection_name'] = "localhost(9999),{}".format(instance['connection_name'])

    check = IbmMqCheck('ibm_mq', {}, [instance])
    check.check(instance)

    assert_all_metrics(aggregator)
def test_stats_metrics(aggregator, instance):
    instance['mqcd_version'] = os.getenv('IBM_MQ_VERSION')

    check = IbmMqCheck('ibm_mq', {}, [instance])

    # make sure time is before fixture messages start time
    check.config.instance_creation_datetime = ensure_aware_datetime(
        dt.datetime(year=2000, month=1, day=1))

    with open(os.path.join(common.HERE, 'fixtures', 'statistics_channel.data'),
              'rb') as channel_file, open(
                  os.path.join(common.HERE, 'fixtures',
                               'statistics_queue.data'), 'rb') as queue_file:
        channel_data = channel_file.read()
        queue_data = queue_file.read()
        with mock.patch(
                'datadog_checks.ibm_mq.collectors.stats_collector.Queue'
        ) as queue:
            queue().get.side_effect = [
                channel_data,
                queue_data,
                MQMIError(MQCC_FAILED, MQRC_NO_MSG_AVAILABLE),
            ]
            check.check(instance)

    common_tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'mq_host:{}'.format(common.HOST),
        'port:{}'.format(common.PORT),
        'connection_name:{}({})'.format(common.HOST, common.PORT),
        'foo:bar',
    ]
    channel_tags = common_tags + [
        'channel:GCP.A',
        'channel_type:clusrcvr',
        'remote_q_mgr_name:QM2',
        'connection_name:192.168.32.2',
    ]
    for metric, metric_type in common.CHANNEL_STATS_METRICS:
        aggregator.assert_metric(metric,
                                 metric_type=getattr(aggregator,
                                                     metric_type.upper()),
                                 tags=channel_tags)

    queue_tags = common_tags + [
        'definition_type:predefined',
        'queue:SYSTEM.CHLAUTH.DATA.QUEUE',
        'queue_type:local',
    ]
    for metric, metric_type in common.QUEUE_STATS_METRICS:
        aggregator.assert_metric(metric,
                                 metric_type=getattr(aggregator,
                                                     metric_type.upper()),
                                 tags=queue_tags)

    assert_all_metrics(aggregator)
    aggregator.assert_metrics_using_metadata(get_metadata_metrics())
Beispiel #9
0
def test_check_all(aggregator, instance_collect_all, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance_collect_all)

    for metric in METRICS:
        aggregator.assert_metric(metric)

    for metric in OPTIONAL_METRICS:
        aggregator.assert_metric(metric, at_least=0)

    aggregator.assert_all_metrics_covered()
Beispiel #10
0
def test_check_connection_name_one(aggregator, instance_with_connection_name):
    instance_with_connection_name['mqcd_version'] = os.getenv('IBM_MQ_VERSION')

    check = IbmMqCheck('ibm_mq', {}, [instance_with_connection_name])
    check.check(instance_with_connection_name)

    assert_all_metrics(aggregator)

    tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'connection_name:{}({})'.format(common.HOST, common.PORT),
    ]

    channel_tags = tags + ['channel:{}'.format(common.CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel', check.OK, tags=channel_tags, count=1)
Beispiel #11
0
def test_check_regex_tag(aggregator, instance_queue_regex_tag, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance_queue_regex_tag)

    tags = [
        'queue_manager:{}'.format(common.QUEUE_MANAGER),
        'mq_host:{}'.format(common.HOST),
        'port:{}'.format(common.PORT),
        'channel:{}'.format(common.CHANNEL),
        'queue:{}'.format(common.QUEUE),
        'foo:bar',
    ]

    for metric, _ in QUEUE_METRICS:
        aggregator.assert_metric(metric, tags=tags)
Beispiel #12
0
def test_metadata(instance, datadog_agent):
    check = IbmMqCheck('ibm_mq', {}, [instance])
    check.check_id = 'test:123'
    check.check(instance)

    raw_version = MQ_VERSION_RAW
    major, minor, mod, fix = raw_version.split('.')
    version_metadata = {
        'version.scheme': 'ibm_mq',
        'version.major': major,
        'version.minor': minor,
        'version.mod': mod,
        'version.fix': fix,
        'version.raw': raw_version,
    }

    datadog_agent.assert_metadata('test:123', version_metadata)
def test_ssl_connection_creation(instance):
    """
    Test that we are not getting unicode/bytes type error.

    TODO: We should test SSL in e2e
    """
    instance['ssl_auth'] = 'yes'
    instance['ssl_cipher_spec'] = 'TLS_RSA_WITH_AES_256_CBC_SHA256'
    instance['ssl_key_repository_location'] = '/dummy'

    check = IbmMqCheck('ibm_mq', {}, [instance])

    check.check(instance)

    assert len(check.warnings) == 1
    warning = check.warnings[0]

    # Check that we are not getting a unicode/bytes type error but a MQRC_KEY_REPOSITORY_ERROR (dummy location)
    assert 'bytes' not in warning
    assert 'unicode' not in warning
    assert 'MQRC_KEY_REPOSITORY_ERROR' in warning
Beispiel #14
0
def test_check(aggregator, instance, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance)

    for metric in METRICS:
        aggregator.assert_metric(metric)

    for metric in OPTIONAL_METRICS:
        aggregator.assert_metric(metric, at_least=0)

    aggregator.assert_all_metrics_covered()

    tags = ['queue_manager:datadog', 'host:localhost', 'port:11414']

    channel_tags = tags + ['channel:{}'.format(common.CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.OK,
                                    tags=channel_tags)
    bad_channel_tags = tags + ['channel:{}'.format(common.BAD_CHANNEL)]
    aggregator.assert_service_check('ibm_mq.channel',
                                    check.CRITICAL,
                                    tags=bad_channel_tags)
Beispiel #15
0
def test_check_queue_pattern(aggregator, instance_queue_pattern, seed_data):
    check = IbmMqCheck('ibm_mq', {}, [instance_queue_pattern])
    check.check(instance_queue_pattern)

    assert_all_metrics(aggregator)
Beispiel #16
0
def test_check_all(aggregator, instance_collect_all, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance_collect_all)

    _assert_all_metrics(aggregator)
Beispiel #17
0
def test_check_queue_regex(aggregator, instance_queue_regex, seed_data):
    check = IbmMqCheck('ibm_mq', {}, {})
    check.check(instance_queue_regex)

    _assert_all_metrics(aggregator)