Exemplo n.º 1
0
def test_check_without_sites_specified(aggregator):
    """
    Returns the right metrics and service checks for the `_Total` site
    """
    # Run check
    instance = WIN_SERVICES_MINIMAL_CONFIG
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    site_tags = ['Default_Web_Site', 'Exchange_Back_End', 'Total']
    for metric_def in DEFAULT_COUNTERS:
        mname = metric_def[3]

        for site_tag in site_tags:
            aggregator.assert_metric(mname,
                                     tags=[
                                         "mytag1", "mytag2",
                                         "site:{0}".format(site_tag), iis_host
                                     ],
                                     count=1)

    for site_tag in site_tags:
        aggregator.assert_service_check(
            'iis.site_up',
            status=IIS.OK,
            tags=["mytag1", "mytag2", "site:{0}".format(site_tag), iis_host],
            count=1)
    aggregator.assert_all_metrics_covered()
Exemplo n.º 2
0
def test_check_on_specific_websites(aggregator):
    instance = INSTANCE
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    site_tags = ['Default_Web_Site', 'Exchange_Back_End', 'Total']
    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        for site_tag in site_tags:
            aggregator.assert_metric(
                metric, tags=["site:{0}".format(site_tag), iis_host], count=1)

    for site_tag in site_tags:
        aggregator.assert_service_check(
            'iis.site_up',
            IIS.OK,
            tags=["site:{0}".format(site_tag), iis_host],
            count=1)

    aggregator.assert_service_check(
        'iis.site_up',
        IIS.CRITICAL,
        tags=["site:{0}".format('Non_Existing_Website'), iis_host],
        count=1)

    aggregator.assert_all_metrics_covered()
Exemplo n.º 3
0
def test_check_on_specific_websites(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = INSTANCE
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    site_tags = ['Default_Web_Site', 'Exchange_Back_End', 'Total']
    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        for site_tag in site_tags:
            Aggregator.assert_metric(metric,
                                     tags=["site:{0}".format(site_tag)],
                                     count=1)

    for site_tag in site_tags:
        Aggregator.assert_service_check('iis.site_up',
                                        IIS.OK,
                                        tags=["site:{0}".format(site_tag)],
                                        count=1)

    Aggregator.assert_service_check(
        'iis.site_up',
        IIS.CRITICAL,
        tags=["site:{0}".format('Non_Existing_Website')],
        count=1)

    Aggregator.assert_all_metrics_covered()
Exemplo n.º 4
0
def test_check(aggregator, pdh_mocks_fixture):  # noqa: F811
    """
    Returns the right metrics and service checks
    """
    instance = WIN_SERVICES_CONFIG
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    # Test metrics
    # ... normalize site-names
    default_site_name = re.sub(r"[,\+\*\-/()\[\]{}\s]", "_", WIN_SERVICES_CONFIG['sites'][0])
    ok_site_name = re.sub(r"[,\+\*\-/()\[\]{}\s]", "_", WIN_SERVICES_CONFIG['sites'][1])
    fail_site_name = re.sub(r"[,\+\*\-/()\[\]{}\s]", "_", WIN_SERVICES_CONFIG['sites'][2])

    for site_name in [default_site_name, ok_site_name, 'Total']:
        for metric_def in DEFAULT_COUNTERS:
            mname = metric_def[3]
            aggregator.assert_metric(mname, tags=["mytag1", "mytag2", "site:{0}".format(site_name)], count=1)

        aggregator.assert_service_check('iis.site_up', status=IIS.OK,
                                        tags=["mytag1", "mytag2", "site:{0}".format(site_name)], count=1)

    aggregator.assert_service_check('iis.site_up', status=IIS.CRITICAL,
                                    tags=["mytag1", "mytag2", "site:{0}".format(fail_site_name)], count=1)

    # Check completed with no warnings
    # self.assertFalse(logger.warning.called)

    aggregator.assert_all_metrics_covered()
Exemplo n.º 5
0
def test_service_check_with_invalid_host(aggregator):
    instance = INVALID_HOST_INSTANCE
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)
    iis_host = c.get_iishost(instance)

    aggregator.assert_service_check('iis.site_up', IIS.CRITICAL, tags=["site:{0}".format('Total'), iis_host])
Exemplo n.º 6
0
def test_basic_check(aggregator):
    instance = MINIMAL_INSTANCE
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    namespace_data = ((SITE_METRICS, IIS.SITE, DEFAULT_SITES),
                      (APP_POOL_METRICS, IIS.APP_POOL, DEFAULT_APP_POOLS))
    for metrics, namespace, values in namespace_data:
        for metric in metrics:
            for value in values:
                aggregator.assert_metric(
                    metric,
                    tags=['{}:{}'.format(namespace, value), iis_host],
                    count=1)

    for _, namespace, values in namespace_data:
        for value in values:
            aggregator.assert_service_check(
                'iis.{}_up'.format(namespace),
                IIS.OK,
                tags=['{}:{}'.format(namespace, value), iis_host],
                count=1)

    aggregator.assert_all_metrics_covered()
Exemplo n.º 7
0
def test_check_without_sites_specified(Aggregator, pdh_mocks_fixture):
    """
    Returns the right metrics and service checks for the `_Total` site
    """
    # Run check
    initialize_pdh_tests()
    instance = WIN_SERVICES_MINIMAL_CONFIG
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    site_tags = ['Default_Web_Site', 'Exchange_Back_End', 'Total']
    for metric_def in DEFAULT_COUNTERS:
        mname = metric_def[3]

        for site_tag in site_tags:
            Aggregator.assert_metric(
                mname,
                tags=["mytag1", "mytag2", "site:{0}".format(site_tag)],
                count=1)

    for site_tag in site_tags:
        Aggregator.assert_service_check(
            'iis.site_up',
            status=IIS.OK,
            tags=["mytag1", "mytag2", "site:{0}".format(site_tag)],
            count=1)
    Aggregator.assert_all_metrics_covered()
Exemplo n.º 8
0
def test_check(aggregator):
    """
    Returns the right metrics and service checks
    """
    instance = WIN_SERVICES_CONFIG
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    # Test tag name normalization
    sites = ['Total']
    for site in instance['sites']:
        sites.append(re.sub(r'[,+*\-/()\[\]{}\s]', '_', site))
    app_pools = ['Total']
    for app_pool in instance['app_pools']:
        app_pools.append(re.sub(r'[,+*\-/()\[\]{}\s]', '_', app_pool))

    # Exclude `Failing site` and `Failing app pool`
    namespace_data_ok = ((SITE_METRICS, IIS.SITE, sites[:-1]),
                         (APP_POOL_METRICS, IIS.APP_POOL, app_pools[:-1]))
    for metrics, namespace, values in namespace_data_ok:
        for metric in metrics:
            for value in values:
                aggregator.assert_metric(metric,
                                         tags=[
                                             'mytag1', 'mytag2',
                                             '{}:{}'.format(namespace,
                                                            value), iis_host
                                         ],
                                         count=1)

    for _, namespace, values in namespace_data_ok:
        # Exclude `Total`
        for value in values[1:]:
            aggregator.assert_service_check(
                'iis.{}_up'.format(namespace),
                IIS.OK,
                tags=[
                    'mytag1', 'mytag2', '{}:{}'.format(namespace, value),
                    iis_host
                ],
                count=1,
            )

    # Only `Failing site` and `Failing app pool`
    namespace_data_failed = ((SITE_METRICS, IIS.SITE, sites[-1:]),
                             (APP_POOL_METRICS, IIS.APP_POOL, app_pools[-1:]))
    for _, namespace, values in namespace_data_failed:
        for value in values:
            aggregator.assert_service_check(
                'iis.{}_up'.format(namespace),
                IIS.CRITICAL,
                tags=[
                    'mytag1', 'mytag2', '{}:{}'.format(namespace, value),
                    iis_host
                ],
                count=1,
            )

    aggregator.assert_all_metrics_covered()
Exemplo n.º 9
0
def test_service_check_with_invalid_host(aggregator, pdh_mocks_fixture):
    instance = INVALID_HOST_INSTANCE
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    aggregator.assert_service_check('iis.site_up',
                                    IIS.CRITICAL,
                                    tags=["site:{0}".format('Total')])
Exemplo n.º 10
0
def test_service_check_with_invalid_host(aggregator):
    instance = INVALID_HOST_INSTANCE
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    aggregator.assert_service_check('iis.site_up',
                                    IIS.CRITICAL,
                                    tags=['site:Total', iis_host])
    aggregator.assert_service_check('iis.app_pool_up',
                                    IIS.CRITICAL,
                                    tags=['app_pool:Total', iis_host])
Exemplo n.º 11
0
def test_basic_check(aggregator, pdh_mocks_fixture):  # noqa: F811
    instance = MINIMAL_INSTANCE
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    site_tags = ['Default_Web_Site', 'Exchange_Back_End', 'Total']
    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        for site_tag in site_tags:
            aggregator.assert_metric(metric, tags=["site:{0}".format(site_tag)], count=1)

    for site_tag in site_tags:
        aggregator.assert_service_check('iis.site_up', IIS.OK,
                                        tags=["site:{0}".format(site_tag)], count=1)

    aggregator.assert_all_metrics_covered()
Exemplo n.º 12
0
def test_check_on_specific_websites_and_app_pools(aggregator):
    instance = INSTANCE
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    namespace_data = (
        (SITE_METRICS, IIS.SITE,
         ['Default_Web_Site', 'Exchange_Back_End', 'Total']),
        (APP_POOL_METRICS, IIS.APP_POOL,
         ['DefaultAppPool', 'MSExchangeServicesAppPool', 'Total']),
    )
    for metrics, namespace, values in namespace_data:
        for metric in metrics:
            for value in values:
                aggregator.assert_metric(
                    metric,
                    tags=['{}:{}'.format(namespace, value), iis_host],
                    count=1)

    for _, namespace, values in namespace_data:
        for value in values:
            aggregator.assert_service_check(
                'iis.{}_up'.format(namespace),
                IIS.OK,
                tags=['{}:{}'.format(namespace, value), iis_host],
                count=1)

    aggregator.assert_service_check(
        'iis.site_up',
        IIS.CRITICAL,
        tags=['site:Non_Existing_Website', iis_host],
        count=1)
    aggregator.assert_service_check(
        'iis.app_pool_up',
        IIS.CRITICAL,
        tags=['app_pool:Non_Existing_App_Pool', iis_host],
        count=1)

    aggregator.assert_all_metrics_covered()
Exemplo n.º 13
0
def test_check_without_sites_specified(aggregator):
    """
    Returns the right metrics and service checks for the `_Total` site
    """
    # Run check
    instance = WIN_SERVICES_MINIMAL_CONFIG
    c = IIS(CHECK_NAME, {}, [instance])
    c.check(None)
    iis_host = c.get_iishost()

    namespace_data = ((SITE_METRICS, IIS.SITE, DEFAULT_SITES),
                      (APP_POOL_METRICS, IIS.APP_POOL, DEFAULT_APP_POOLS))
    for metrics, namespace, values in namespace_data:
        for metric in metrics:
            for value in values:
                aggregator.assert_metric(metric,
                                         tags=[
                                             'mytag1', 'mytag2',
                                             '{}:{}'.format(namespace,
                                                            value), iis_host
                                         ],
                                         count=1)

    for _, namespace, values in namespace_data:
        for value in values:
            aggregator.assert_service_check(
                'iis.{}_up'.format(namespace),
                IIS.OK,
                tags=[
                    'mytag1', 'mytag2', '{}:{}'.format(namespace, value),
                    iis_host
                ],
                count=1,
            )

    aggregator.assert_all_metrics_covered()