def configure_tenant_group(logger, tenant): destination = get_tenant_configuration_destination(tenant) name = 'tenant:{tenant}'.format(tenant=tenant) description = 'Monitored components for tenant {tenant}'.format( tenant=tenant, ) make_config_subdir(os.path.dirname(destination)) deploy_configuration_file( logger, source='hostgroup.template', destination=destination, template_params={ 'name': name, 'description': description, }, reload_service=False, use_pkg_data=False, )
def create_group_instance(logger, group_name, group_type, tenant, reaction_target): logger.info('Creating instance {name} of {group_type}'.format( name=group_name, group_type=group_type, )) logger.debug('Loading group check configuration') with open(get_group_config_location(group_type)) as config_handle: group_config = json.load(config_handle) check_config = group_config['check_configuration'] logger.debug( 'Check configuration loaded: {conf}'.format(conf=str(check_config)) ) logger.debug('Setting reaction target to {target}'.format( target=reaction_target, )) reaction_target_path = get_group_check_reaction_target_path(group_type, group_name, tenant) make_config_subdir(os.path.dirname(reaction_target_path)) deploy_file( data=reaction_target, destination=reaction_target_path, sudo=False, ) logger.info('Creating supporting hostgroups') configure_tenant_group(logger, tenant) logger.debug('Deploying group tenant configuration') group_config_destination = get_group_host_configuration_destination( group_type, tenant, ) make_config_subdir( os.path.dirname( os.path.join( BASE_OBJECTS_DIR, group_config_destination, ) ) ) deploy_configuration_file( logger, source='group.template', destination=group_config_destination, template_params={ 'group_type': group_type, 'tenant': tenant, }, reload_service=False, use_pkg_data=False, ) logger.debug('Deploying group instance configuration') instance_config_destination = get_group_check_configuration_destination( group_type, group_name, tenant, ) make_config_subdir( os.path.dirname( os.path.join( BASE_OBJECTS_DIR, instance_config_destination, ) ) ) check_config.update({ 'group_type': group_type, 'group_name': group_name, 'tenant': tenant, }) logger.debug( 'Full check configuration: {conf}'.format(conf=str(check_config)) ) deploy_configuration_file( logger, source='group_check.template', destination=instance_config_destination, template_params=check_config, reload_service=True, use_pkg_data=False, )
def create_meta_group(logger, group_instance_prefix, group_type, tenant, approach, unknown, check_interval, low_warning_threshold, low_critical_threshold, high_warning_threshold, high_critical_threshold, reaction_target, low_reaction, high_reaction): logger.info( 'Creating meta group for prefix {prefix} ' 'for group {group_type}'.format( prefix=group_instance_prefix, group_type=group_type, ) ) logger.debug('Creating reaction configuration') reaction_conf = { 'reactions': {} } if low_reaction: reaction_conf['reactions']['low'] = { 'workflow': low_reaction, } if high_reaction: reaction_conf['reactions']['high'] = { 'workflow': high_reaction, } reaction_conf_path = get_meta_group_reaction_configuration_path( group_type=group_type, group_instance_prefix=group_instance_prefix, tenant=tenant, ) make_config_subdir(os.path.dirname(reaction_conf_path)) deploy_file( data=json.dumps(reaction_conf), destination=reaction_conf_path, sudo=False, ) logger.debug('Setting reaction target') reaction_target_path = get_meta_group_reaction_target_path( group_type=group_type, group_instance_prefix=group_instance_prefix, tenant=tenant, ) make_config_subdir(os.path.dirname(reaction_target_path)) deploy_file( data=reaction_target, destination=reaction_target_path, sudo=False, ) logger.debug('Deploying meta group check configuration') meta_group_config_destination = get_meta_group_configuration_destination( group_type, group_instance_prefix, tenant, ) make_config_subdir( os.path.dirname( os.path.join( BASE_OBJECTS_DIR, meta_group_config_destination, ) ) ) check_config = { 'group_type': group_type, 'group_instance_prefix': group_instance_prefix, 'tenant': tenant, 'unknown': unknown, 'approach': approach, 'low_warning_threshold': low_warning_threshold, 'low_critical_threshold': low_critical_threshold, 'high_warning_threshold': high_warning_threshold, 'high_critical_threshold': high_critical_threshold, 'check_interval': check_interval, } logger.debug( 'Full check configuration: {conf}'.format(conf=str(check_config)) ) deploy_configuration_file( logger, source='meta_group_check.template', destination=meta_group_config_destination, template_params=check_config, reload_service=True, use_pkg_data=False, )
def create_target(logger, instance_id, instance_ip, tenant, deployment, target_type): configure_tenant_group(logger, tenant) supporting_hostgroups = [ { 'params': { 'tenant': tenant, 'deployment': deployment, }, 'destmethod': get_tenant_deployment_configuration_destination, 'name': 'tenant:{tenant}/deployment:{deployment}', 'description': ('Monitored hosts in deployment {deployment} for tenant ' '{tenant}'), }, { 'params': { 'tenant': tenant, 'target_type': target_type, }, 'destmethod': get_tenant_target_type_configuration_destination, 'name': 'tenant:{tenant}/target_type:{target_type}', 'description': ('Monitored hosts of type {target_type} for tenant {tenant}'), }, ] for hostgroup in supporting_hostgroups: params = hostgroup['params'] hostgroup_destination = hostgroup['destmethod'](**params) hostgroup_name = hostgroup['name'].format(**params) hostgroup_description = hostgroup['description'].format(**params) make_config_subdir(os.path.dirname(hostgroup_destination)) deploy_configuration_file( logger, source='hostgroup.template', destination=hostgroup_destination, template_params={ 'name': hostgroup_name, 'description': hostgroup_description, }, reload_service=False, use_pkg_data=False, ) node = get_node_id(instance_id) node_destination = get_node_configuration_destination( tenant, deployment, node, ) make_config_subdir(os.path.dirname(node_destination)) # Deploy node pseudo host deploy_configuration_file( logger, source='node.template', destination=node_destination, template_params={ 'node_id': node, 'deployment': deployment, 'tenant': tenant, 'target_type': target_type, }, reload_service=False, use_pkg_data=False, ) deploy_configuration_file( logger, source='target.template', destination=get_target_configuration_destination(instance_id), template_params={ 'instance_id': instance_id, 'instance_ip': instance_ip, 'deployment': deployment, 'tenant': tenant, 'target_type': target_type, }, use_pkg_data=False, )