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()
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()
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()
def test_check(aggregator, dd_run_check): """ Returns the right metrics and service checks """ instance = WIN_SERVICES_CONFIG c = IIS(CHECK_NAME, {}, [instance]) dd_run_check(c) 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()
def test_basic_check(aggregator, dd_run_check): instance = MINIMAL_INSTANCE c = IIS(CHECK_NAME, {}, [instance]) dd_run_check(c) 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()
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])
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()
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()
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')])
def test_service_check_with_invalid_host(aggregator, dd_run_check): instance = INVALID_HOST_INSTANCE c = IIS(CHECK_NAME, {}, [instance]) dd_run_check(c) 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])
def test_check_all(aggregator, dd_default_hostname, dd_run_check, mock_performance_objects): mock_performance_objects(PERFORMANCE_OBJECTS) check = IIS('iis', {}, [{'host': dd_default_hostname}]) check.hostname = dd_default_hostname dd_run_check(check) global_tags = ['iis_host:{}'.format(dd_default_hostname)] aggregator.assert_service_check('iis.windows.perf.health', ServiceCheck.OK, count=1, tags=global_tags) app_pool_metrics_data, site_metrics_data = get_metrics_data() for app_pool, value in (('foo-pool', 9000), ('bar-pool', 0)): tags = ['app_pool:{}'.format(app_pool)] tags.extend(global_tags) aggregator.assert_service_check( 'iis.app_pool_up', ServiceCheck.CRITICAL if value == 0 else ServiceCheck.OK, count=1, tags=tags) for metric_name, metric_type in app_pool_metrics_data: aggregator.assert_metric(metric_name, value, metric_type=getattr( aggregator, metric_type.upper()), count=1, tags=tags) for site, value in (('foo.site', 9000), ('bar.site', 0)): tags = ['site:{}'.format(site)] tags.extend(global_tags) aggregator.assert_service_check( 'iis.site_up', ServiceCheck.CRITICAL if value == 0 else ServiceCheck.OK, count=1, tags=tags) for metric_name, metric_type in site_metrics_data: aggregator.assert_metric(metric_name, value, metric_type=getattr( aggregator, metric_type.upper()), count=1, tags=tags) aggregator.assert_all_metrics_covered() aggregator.assert_metrics_using_metadata(get_metadata_metrics())
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()
def test_check_on_specific_websites_and_app_pools(aggregator, dd_run_check): instance = INSTANCE c = IIS(CHECK_NAME, {}, [instance]) dd_run_check(c) 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()
def test_check_without_sites_specified(aggregator, dd_run_check): """ Returns the right metrics and service checks for the `_Total` site """ # Run check instance = WIN_SERVICES_MINIMAL_CONFIG c = IIS(CHECK_NAME, {}, [instance]) dd_run_check(c) 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()
def test_additional_metrics(aggregator, caplog, dd_run_check): instance = copy.deepcopy(MINIMAL_INSTANCE) instance['additional_metrics'] = [[ 'HTTP Service Request Queues', 'none', 'RejectedRequests', 'iis.httpd_service_request_queues.rejectedrequests', 'gauge', ]] c = IIS(CHECK_NAME, {}, [instance]) with caplog.at_level(logging.DEBUG): dd_run_check(c) aggregator.assert_metric( 'iis.httpd_service_request_queues.rejectedrequests') assert 'Unknown IIS counter: HTTP Service Request Queues. Falling back to default submission' in caplog.text
def check(): return lambda instance: IIS('iis', {}, [instance])