def get_metrics_for_subscription(inputs, credentials, ew):
    '\n        top level function\n        given subscription id and credentials, get metrics for all resources with the right tags\n        splunk sends an array of inputs, but only one element, hence the [0]\n    '
    metadata = inputs.metadata
    (input_name, input_item) = inputs.inputs.popitem()
    stanza = input_name.split('://')
    instance_name = stanza[1]
    try:
        locale = 'checkpoint file data'
        checkpoint_dir = metadata['checkpoint_dir']
        checkpoint_dict = {'checkpoint_dir': checkpoint_dir, 'instance_name': instance_name}
        locale = 'put_time_window'
        put_time_window(ew, checkpoint_dict)
        locale = 'put_time_checkpoint'
        put_time_checkpoint(ew, checkpoint_dict)
        tenant_id = input_item.get('SPNTenantID')
        spn_client_id = credentials.get('app_id')
        spn_client_secret = credentials.get('app_key')
        subscription_id = input_item.get('SubscriptionId')
        key_vault_name = input_item.get('vaultName')
        secret_name = input_item.get('secretName')
        secret_version = input_item.get('secretVersion')
        input_sourcetype = input_item.get('sourcetype')
        arm_creds = {}
        if ((spn_client_id is not None) and (spn_client_secret is not None)):
            locale = 'get_access_token for key vault SPN'
            authentication_endpoint = 'https://login.windows.net/'
            resource = 'https://vault.azure.net'
            kv_bearer_token = get_access_token(tenant_id, spn_client_id, spn_client_secret, authentication_endpoint, resource)
            locale = 'get_secret_from_keyvault'
            arm_creds = get_secret_from_keyvault(ew, kv_bearer_token, key_vault_name, secret_name, secret_version)
        locale = 'get_access_token'
        authentication_endpoint = get_azure_environment('Azure')['activeDirectoryEndpointUrl']
        resource = get_azure_environment('Azure')['activeDirectoryResourceId']
        bearer_token = get_access_token(tenant_id, arm_creds.get('spn_client_id'), arm_creds.get('spn_client_secret'), authentication_endpoint, resource)
        locale = 'get_azure_environment'
        resource_mgr_endpoint_url = get_azure_environment('Azure')['resourceManagerEndpointUrl']
        locale = 'get_subscription_segment'
        sub_url = (resource_mgr_endpoint_url + get_subscription_segment(subscription_id))
        locale = 'get_resources'
        resource_groups = get_resources(ew, bearer_token, sub_url)
        locale = 'get_resources_for_rgs'
        get_resources_for_rgs(ew, bearer_token, sub_url, resource_groups, input_sourcetype, checkpoint_dict)
    except:
        ew.log('ERROR', 'Error caught in get_metrics_for_subscription, type: {0}, value: {1}, locale = {2}'.format(sys.exc_info()[0], sys.exc_info()[1], locale))
top level function
given subscription id and credentials, get metrics for all resources with the right tags
splunk sends an array of inputs, but only one element, hence the [0]
def get_metrics_for_subscription(inputs, credentials, ew):
    '\n        top level function\n        given subscription id and credentials, get metrics for all resources with the right tags\n        splunk sends an array of inputs, but only one element, hence the [0]\n    '
    metadata = inputs.metadata
    (input_name, input_item) = inputs.inputs.popitem()
    stanza = input_name.split('://')
    instance_name = stanza[1]
    try:
        locale = 'checkpoint file data'
        checkpoint_dir = metadata['checkpoint_dir']
        checkpoint_dict = {'checkpoint_dir': checkpoint_dir, 'instance_name': instance_name}
        locale = 'put_time_window'
        put_time_window(ew, checkpoint_dict)
        locale = 'put_time_checkpoint'
        put_time_checkpoint(ew, checkpoint_dict)
        tenant_id = input_item.get('SPNTenantID')
        spn_client_id = credentials.get('app_id')
        spn_client_secret = credentials.get('app_key')
        subscription_id = input_item.get('SubscriptionId')
        key_vault_name = input_item.get('vaultName')
        secret_name = input_item.get('secretName')
        secret_version = input_item.get('secretVersion')
        input_sourcetype = input_item.get('sourcetype')
        arm_creds = {}
        if ((spn_client_id is not None) and (spn_client_secret is not None)):
            locale = 'get_access_token for key vault SPN'
            authentication_endpoint = 'https://login.windows.net/'
            resource = 'https://vault.azure.net'
            kv_bearer_token = get_access_token(tenant_id, spn_client_id, spn_client_secret, authentication_endpoint, resource)
            locale = 'get_secret_from_keyvault'
            arm_creds = get_secret_from_keyvault(ew, kv_bearer_token, key_vault_name, secret_name, secret_version)
        locale = 'get_access_token'
        authentication_endpoint = get_azure_environment('Azure')['activeDirectoryEndpointUrl']
        resource = get_azure_environment('Azure')['activeDirectoryResourceId']
        bearer_token = get_access_token(tenant_id, arm_creds.get('spn_client_id'), arm_creds.get('spn_client_secret'), authentication_endpoint, resource)
        locale = 'get_azure_environment'
        resource_mgr_endpoint_url = get_azure_environment('Azure')['resourceManagerEndpointUrl']
        locale = 'get_subscription_segment'
        sub_url = (resource_mgr_endpoint_url + get_subscription_segment(subscription_id))
        locale = 'get_resources'
        resource_groups = get_resources(ew, bearer_token, sub_url)
        locale = 'get_resources_for_rgs'
        get_resources_for_rgs(ew, bearer_token, sub_url, resource_groups, input_sourcetype, checkpoint_dict)
    except:
        ew.log('ERROR', 'Error caught in get_metrics_for_subscription, type: {0}, value: {1}, locale = {2}'.format(sys.exc_info()[0], sys.exc_info()[1], locale))