def get(self, request, format=None): '''Return various sitewide configuration settings''' if request.user.is_superuser or request.user.is_system_auditor: license_data = get_license(show_key=True) else: license_data = get_license(show_key=False) if not license_data.get('valid_key', False): license_data = {} if license_data and 'features' in license_data and 'activity_streams' in license_data[ 'features']: # FIXME: Make the final setting value dependent on the feature? license_data['features'][ 'activity_streams'] &= settings.ACTIVITY_STREAM_ENABLED pendo_state = settings.PENDO_TRACKING_STATE if settings.PENDO_TRACKING_STATE in ( 'off', 'anonymous', 'detailed') else 'off' data = dict( time_zone=settings.TIME_ZONE, license_info=license_data, version=get_awx_version(), ansible_version=get_ansible_version(), eula=render_to_string("eula.md") if license_data.get('license_type', 'UNLICENSED') != 'open' else '', analytics_status=pendo_state, analytics_collectors=all_collectors(), become_methods=PRIVILEGE_ESCALATION_METHODS, ) # If LDAP is enabled, user_ldap_fields will return a list of field # names that are managed by LDAP and should be read-only for users with # a non-empty ldap_dn attribute. if getattr(settings, 'AUTH_LDAP_SERVER_URI', None): user_ldap_fields = ['username', 'password'] user_ldap_fields.extend( getattr(settings, 'AUTH_LDAP_USER_ATTR_MAP', {}).keys()) user_ldap_fields.extend( getattr(settings, 'AUTH_LDAP_USER_FLAGS_BY_GROUP', {}).keys()) data['user_ldap_fields'] = user_ldap_fields if request.user.is_superuser \ or request.user.is_system_auditor \ or Organization.accessible_objects(request.user, 'admin_role').exists() \ or Organization.accessible_objects(request.user, 'auditor_role').exists() \ or Organization.accessible_objects(request.user, 'project_admin_role').exists(): data.update( dict(project_base_dir=settings.PROJECTS_ROOT, project_local_paths=Project.get_local_path_choices(), custom_virtualenvs=get_custom_venv_choices())) elif JobTemplate.accessible_objects(request.user, 'admin_role').exists(): data['custom_virtualenvs'] = get_custom_venv_choices() return Response(data)
def config(since, **kwargs): license_info = get_license() install_type = 'traditional' if os.environ.get('container') == 'oci': install_type = 'openshift' elif 'KUBERNETES_SERVICE_PORT' in os.environ: install_type = 'k8s' return { 'platform': { 'system': platform.system(), 'dist': platform.dist(), 'release': platform.release(), 'type': install_type, }, 'install_uuid': settings.INSTALL_UUID, 'instance_uuid': settings.SYSTEM_UUID, 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'free_instances': license_info.get('free_instances', 0), 'total_licensed_instances': license_info.get('instance_count', 0), 'license_expiry': license_info.get('time_remaining', 0), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'authentication_backends': settings.AUTHENTICATION_BACKENDS, 'logging_aggregators': settings.LOG_AGGREGATOR_LOGGERS, 'external_logger_enabled': settings.LOG_AGGREGATOR_ENABLED, 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', None), }
def get_awx_http_client_headers(): license = get_license().get('license_type', 'UNLICENSED') headers = { 'Content-Type': 'application/json', 'User-Agent': '{} {} ({})'.format('AWX' if license == 'open' else 'Red Hat Ansible Automation Platform', get_awx_version(), license), } return headers
def _valid_license(): try: if get_license().get('license_type', 'UNLICENSED') == 'open': return False access_registry[Job](None).check_license() except PermissionDenied: logger.exception("A valid license was not found:") return False return True
def get_setting_field(self, setting, mixin_class=None, for_user=False, **kwargs): from rest_framework.fields import empty field_kwargs = {} field_kwargs.update(self._registry[setting]) field_kwargs.update(kwargs) field_class = original_field_class = field_kwargs.pop('field_class') if mixin_class: field_class = type(field_class.__name__, (mixin_class, field_class), {}) category_slug = field_kwargs.pop('category_slug', None) category = field_kwargs.pop('category', None) depends_on = frozenset(field_kwargs.pop('depends_on', None) or []) placeholder = field_kwargs.pop('placeholder', empty) feature_required = field_kwargs.pop('feature_required', empty) encrypted = bool(field_kwargs.pop('encrypted', False)) defined_in_file = bool(field_kwargs.pop('defined_in_file', False)) if getattr(field_kwargs.get('child', None), 'source', None) is not None: field_kwargs['child'].source = None field_instance = field_class(**field_kwargs) field_instance.category_slug = category_slug field_instance.category = category field_instance.depends_on = depends_on if placeholder is not empty: field_instance.placeholder = placeholder if feature_required is not empty: field_instance.feature_required = feature_required field_instance.defined_in_file = defined_in_file if field_instance.defined_in_file: field_instance.help_text = ( str(_('This value has been set manually in a settings file.')) + '\n\n' + str(field_instance.help_text) ) field_instance.encrypted = encrypted original_field_instance = field_instance if field_class != original_field_class: original_field_instance = original_field_class(**field_kwargs) if category_slug == 'user' and for_user: try: field_instance.default = original_field_instance.to_representation(getattr(self.settings, setting)) except Exception: logger.warning('Unable to retrieve default value for user setting "%s".', setting, exc_info=True) elif not field_instance.read_only or field_instance.default is empty or field_instance.defined_in_file: try: field_instance.default = original_field_instance.to_representation(self.settings._awx_conf_settings._get_default(setting)) except AttributeError: pass except Exception: logger.warning('Unable to retrieve default value for setting "%s".', setting, exc_info=True) # `PENDO_TRACKING_STATE` is disabled for the open source awx license if setting == 'PENDO_TRACKING_STATE' and get_license().get('license_type') == 'open': field_instance.read_only = True return field_instance
def config(since): license_info = get_license(show_key=False) return { 'system_uuid': settings.SYSTEM_UUID, 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'free_instances': license_info.get('free instances', 0), 'license_expiry': license_info.get('time_remaining', 0), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'authentication_backends': settings.AUTHENTICATION_BACKENDS, 'logging_aggregators': settings.LOG_AGGREGATOR_LOGGERS, 'external_logger_enabled': settings.LOG_AGGREGATOR_ENABLED, 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', None), }
def config(since, **kwargs): license_info = get_license() install_type = 'traditional' if os.environ.get('container') == 'oci': install_type = 'openshift' elif 'KUBERNETES_SERVICE_PORT' in os.environ: install_type = 'k8s' return { 'platform': { 'system': platform.system(), 'dist': distro.linux_distribution(), 'release': platform.release(), 'type': install_type, }, 'install_uuid': settings.INSTALL_UUID, 'instance_uuid': settings.SYSTEM_UUID, 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'license_date': license_info.get('license_date'), 'subscription_name': license_info.get('subscription_name'), 'sku': license_info.get('sku'), 'support_level': license_info.get('support_level'), 'product_name': license_info.get('product_name'), 'valid_key': license_info.get('valid_key'), 'satellite': license_info.get('satellite'), 'pool_id': license_info.get('pool_id'), 'current_instances': license_info.get('current_instances'), 'automated_instances': license_info.get('automated_instances'), 'automated_since': license_info.get('automated_since'), 'trial': license_info.get('trial'), 'grace_period_remaining': license_info.get('grace_period_remaining'), 'compliant': license_info.get('compliant'), 'date_warning': license_info.get('date_warning'), 'date_expired': license_info.get('date_expired'), 'free_instances': license_info.get('free_instances', 0), 'total_licensed_instances': license_info.get('instance_count', 0), 'license_expiry': license_info.get('time_remaining', 0), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'authentication_backends': settings.AUTHENTICATION_BACKENDS, 'logging_aggregators': settings.LOG_AGGREGATOR_LOGGERS, 'external_logger_enabled': settings.LOG_AGGREGATOR_ENABLED, 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', None), }
def metrics(): license_info = get_license(show_key=False) SYSTEM_INFO.info({ 'system_uuid': settings.SYSTEM_UUID, 'insights_analytics': str(settings.INSIGHTS_DATA_ENABLED), 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'ansible_version': get_ansible_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'free_instances': str(license_info.get('free instances', 0)), 'license_expiry': str(license_info.get('time_remaining', 0)), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'external_logger_enabled': str(settings.LOG_AGGREGATOR_ENABLED), 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', 'None') }) current_counts = counts(None) ORG_COUNT.set(current_counts['organization']) USER_COUNT.set(current_counts['user']) TEAM_COUNT.set(current_counts['team']) INV_COUNT.set(current_counts['inventory']) PROJ_COUNT.set(current_counts['project']) JT_COUNT.set(current_counts['job_template']) WFJT_COUNT.set(current_counts['workflow_job_template']) HOST_COUNT.labels(type='all').set(current_counts['host']) HOST_COUNT.labels(type='active').set(current_counts['active_host_count']) SCHEDULE_COUNT.set(current_counts['schedule']) INV_SCRIPT_COUNT.set(current_counts['custom_inventory_script']) CUSTOM_VENVS.set(current_counts['custom_virtualenvs']) USER_SESSIONS.labels(type='all').set(current_counts['active_sessions']) USER_SESSIONS.labels(type='user').set(current_counts['active_user_sessions']) USER_SESSIONS.labels(type='anonymous').set(current_counts['active_anonymous_sessions']) RUNNING_JOBS.set(current_counts['running_jobs']) instance_data = instance_info(None) for uuid in instance_data: INSTANCE_CAPACITY.labels(type=uuid).set(instance_data[uuid]['capacity']) INSTANCE_CPU.labels(type=uuid).set(instance_data[uuid]['cpu']) INSTANCE_MEMORY.labels(type=uuid).set(instance_data[uuid]['memory']) INSTANCE_INFO.labels(type=uuid).info({ 'enabled': str(instance_data[uuid]['enabled']), 'last_isolated_check': getattr(instance_data[uuid], 'last_isolated_check', 'None'), 'managed_by_policy': str(instance_data[uuid]['managed_by_policy']), 'version': instance_data[uuid]['version'] }) instance_data = job_instance_counts(None) for node in instance_data: # skipping internal execution node (for system jobs) # TODO: determine if we should exclude execution_node from instance count if node == '': continue types = instance_data[node].get('launch_type', {}) for launch_type, value in types.items(): INSTANCE_LAUNCH_TYPE.labels(node=node, launch_type=launch_type).set(value) statuses = instance_data[node].get('status', {}) for status, value in statuses.items(): INSTANCE_STATUS.labels(node=node, status=status).set(value) return generate_latest()
def metrics(): REGISTRY = CollectorRegistry() SYSTEM_INFO = Info('awx_system', 'AWX System Information', registry=REGISTRY) ORG_COUNT = Gauge('awx_organizations_total', 'Number of organizations', registry=REGISTRY) USER_COUNT = Gauge('awx_users_total', 'Number of users', registry=REGISTRY) TEAM_COUNT = Gauge('awx_teams_total', 'Number of teams', registry=REGISTRY) INV_COUNT = Gauge('awx_inventories_total', 'Number of inventories', registry=REGISTRY) PROJ_COUNT = Gauge('awx_projects_total', 'Number of projects', registry=REGISTRY) JT_COUNT = Gauge('awx_job_templates_total', 'Number of job templates', registry=REGISTRY) WFJT_COUNT = Gauge('awx_workflow_job_templates_total', 'Number of workflow job templates', registry=REGISTRY) HOST_COUNT = Gauge( 'awx_hosts_total', 'Number of hosts', [ 'type', ], registry=REGISTRY, ) SCHEDULE_COUNT = Gauge('awx_schedules_total', 'Number of schedules', registry=REGISTRY) INV_SCRIPT_COUNT = Gauge('awx_inventory_scripts_total', 'Number of invetory scripts', registry=REGISTRY) USER_SESSIONS = Gauge( 'awx_sessions_total', 'Number of sessions', [ 'type', ], registry=REGISTRY, ) CUSTOM_VENVS = Gauge('awx_custom_virtualenvs_total', 'Number of virtualenvs', registry=REGISTRY) RUNNING_JOBS = Gauge('awx_running_jobs_total', 'Number of running jobs on the Tower system', registry=REGISTRY) PENDING_JOBS = Gauge('awx_pending_jobs_total', 'Number of pending jobs on the Tower system', registry=REGISTRY) STATUS = Gauge( 'awx_status_total', 'Status of Job launched', [ 'status', ], registry=REGISTRY, ) INSTANCE_CAPACITY = Gauge( 'awx_instance_capacity', 'Capacity of each node in a Tower system', [ 'hostname', 'instance_uuid', ], registry=REGISTRY, ) INSTANCE_CPU = Gauge( 'awx_instance_cpu', 'CPU cores on each node in a Tower system', [ 'hostname', 'instance_uuid', ], registry=REGISTRY, ) INSTANCE_MEMORY = Gauge( 'awx_instance_memory', 'RAM (Kb) on each node in a Tower system', [ 'hostname', 'instance_uuid', ], registry=REGISTRY, ) INSTANCE_INFO = Info( 'awx_instance', 'Info about each node in a Tower system', [ 'hostname', 'instance_uuid', ], registry=REGISTRY, ) INSTANCE_LAUNCH_TYPE = Gauge( 'awx_instance_launch_type_total', 'Type of Job launched', [ 'node', 'launch_type', ], registry=REGISTRY, ) INSTANCE_STATUS = Gauge( 'awx_instance_status_total', 'Status of Job launched', [ 'node', 'status', ], registry=REGISTRY, ) INSTANCE_CONSUMED_CAPACITY = Gauge( 'awx_instance_consumed_capacity', 'Consumed capacity of each node in a Tower system', [ 'hostname', 'instance_uuid', ], registry=REGISTRY, ) INSTANCE_REMAINING_CAPACITY = Gauge( 'awx_instance_remaining_capacity', 'Remaining capacity of each node in a Tower system', [ 'hostname', 'instance_uuid', ], registry=REGISTRY, ) LICENSE_INSTANCE_TOTAL = Gauge('awx_license_instance_total', 'Total number of managed hosts provided by your license', registry=REGISTRY) LICENSE_INSTANCE_FREE = Gauge('awx_license_instance_free', 'Number of remaining managed hosts provided by your license', registry=REGISTRY) license_info = get_license() SYSTEM_INFO.info( { 'install_uuid': settings.INSTALL_UUID, 'insights_analytics': str(settings.INSIGHTS_TRACKING_STATE), 'tower_url_base': settings.TOWER_URL_BASE, 'tower_version': get_awx_version(), 'license_type': license_info.get('license_type', 'UNLICENSED'), 'license_expiry': str(license_info.get('time_remaining', 0)), 'pendo_tracking': settings.PENDO_TRACKING_STATE, 'external_logger_enabled': str(settings.LOG_AGGREGATOR_ENABLED), 'external_logger_type': getattr(settings, 'LOG_AGGREGATOR_TYPE', 'None'), } ) LICENSE_INSTANCE_TOTAL.set(str(license_info.get('instance_count', 0))) LICENSE_INSTANCE_FREE.set(str(license_info.get('free_instances', 0))) current_counts = counts(None) ORG_COUNT.set(current_counts['organization']) USER_COUNT.set(current_counts['user']) TEAM_COUNT.set(current_counts['team']) INV_COUNT.set(current_counts['inventory']) PROJ_COUNT.set(current_counts['project']) JT_COUNT.set(current_counts['job_template']) WFJT_COUNT.set(current_counts['workflow_job_template']) HOST_COUNT.labels(type='all').set(current_counts['host']) HOST_COUNT.labels(type='active').set(current_counts['active_host_count']) SCHEDULE_COUNT.set(current_counts['schedule']) INV_SCRIPT_COUNT.set(current_counts['custom_inventory_script']) CUSTOM_VENVS.set(current_counts['custom_virtualenvs']) USER_SESSIONS.labels(type='all').set(current_counts['active_sessions']) USER_SESSIONS.labels(type='user').set(current_counts['active_user_sessions']) USER_SESSIONS.labels(type='anonymous').set(current_counts['active_anonymous_sessions']) all_job_data = job_counts(None) statuses = all_job_data.get('status', {}) for status, value in statuses.items(): STATUS.labels(status=status).set(value) RUNNING_JOBS.set(current_counts['running_jobs']) PENDING_JOBS.set(current_counts['pending_jobs']) instance_data = instance_info(None, include_hostnames=True) for uuid, info in instance_data.items(): hostname = info['hostname'] INSTANCE_CAPACITY.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['capacity']) INSTANCE_CPU.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['cpu']) INSTANCE_MEMORY.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['memory']) INSTANCE_CONSUMED_CAPACITY.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['consumed_capacity']) INSTANCE_REMAINING_CAPACITY.labels(hostname=hostname, instance_uuid=uuid).set(instance_data[uuid]['remaining_capacity']) INSTANCE_INFO.labels(hostname=hostname, instance_uuid=uuid).info( { 'enabled': str(instance_data[uuid]['enabled']), 'last_isolated_check': getattr(instance_data[uuid], 'last_isolated_check', 'None'), 'managed_by_policy': str(instance_data[uuid]['managed_by_policy']), 'version': instance_data[uuid]['version'], } ) instance_data = job_instance_counts(None) for node in instance_data: # skipping internal execution node (for system jobs) if node == '': continue types = instance_data[node].get('launch_type', {}) for launch_type, value in types.items(): INSTANCE_LAUNCH_TYPE.labels(node=node, launch_type=launch_type).set(value) statuses = instance_data[node].get('status', {}) for status, value in statuses.items(): INSTANCE_STATUS.labels(node=node, status=status).set(value) return generate_latest(registry=REGISTRY)