def _get_config(service, stanza='console'): """Get non-credential Code42 configuration settings entity""" config_endpoint = client.Collection(service, 'code42/config/%s' % stanza) configs = config_endpoint.list() return configs[0] if len(configs) > 0 else None
def __init__(self, scriptMode, ctxInfo): admin.MConfigHandler.__init__(self, scriptMode, ctxInfo) self._service = LocalServiceManager( DEFAULT_APP_NAME, DEFAULT_OWNER, self.getSessionKey()).get_local_service() self._collection = client.Collection(self._service, DATAMODEL_REST) self.shouldAutoList = False
def save(self, request): """Saves this form's persisted state.""" service = request.service settings = self.cleaned_data first_password_settings = { 'realm': settings['api_key'], 'name': settings['access_token'], 'password': \ settings['api_secret'] + ':' + settings['access_token_secret'] } # Replace old password entity with new one passwords_endpoint = client.Collection(service, 'storage/passwords') passwords = passwords_endpoint.list() if len(passwords) > 0: first_password = passwords[0] first_password.delete() first_password = passwords_endpoint.create(**first_password_settings) # Update state of the Twitter input twitter_input = SetupForm._get_twitter_scripted_input(service) twitter_input.update( **{'disabled': '0' if settings['enabled'] else '1'})
def get_by_name(self, name): inputs = client.Collection(self.service, INPUT_PATH % "snow") snow_inputs = inputs.list() for snow_input in snow_inputs: if snow_input.name == name: return snow_input return None
def get_by_name(self, name): snow_account_collection = client.Collection(self._service, SETUP_ACCOUNT_URL) accounts = snow_account_collection.list() for account in accounts: if account.name == name: return account return None
def _get_credentials(service): """Get the correct, properly filtered Code42 Server credentials entity""" passwords_endpoint = client.Collection(service, 'storage/passwords') def _password_match(credential): """Determine whether a credential matches this app namespace""" try: return credential['access']['app'] == 'code42' except AttributeError: return False passwords = [ x for x in passwords_endpoint.list() if _password_match(x) ] credential = passwords[0] if len(passwords) > 0 else None return credential
def save(self, request): """Saves this form's persisted state.""" service = request.service settings = self.cleaned_data first_password_settings = { 'name': settings['username'], 'password': settings['password'] } # Replace old password entity with new one passwords_endpoint = client.Collection(service, 'storage/passwords') passwords = passwords_endpoint.list() if len(passwords) > 0: first_password = passwords[0] first_password.delete() first_password = passwords_endpoint.create(**first_password_settings)
def load(cls, request): """Loads this form's persisted state, returning a new Form.""" service = request.service # Locate the storage/passwords entity that contains the Twitter # credentials, if available. # # It is only stored in storage/passwords because older versions of # this app put it there. If writing this app from scratch, # I'd probably put it in a conf file instead because it # is a lot easier to access. passwords_endpoint = client.Collection(service, 'storage/passwords') passwords = passwords_endpoint.list() first_password = passwords[0] if len(passwords) > 0 else None # Locate the scripted input that extracts events from Twitter. # # If writing this app from scratch I would probably use a modular # input instead because they are easier to configure. twitter_input = SetupForm._get_twitter_scripted_input(service) settings = {} # Read credentials from the password entity. # NOTE: Reading from 'password' setting just gives a bunch of asterisks, # so we need to read from the 'clear_password' setting instead. # NOTE: Reading from 'name' setting gives back a string in the form # '<realm>:<username>', when we only want the username. # So we need to read from the 'username' setting instead. settings['api_key'] = \ first_password['realm'] if first_password else '' settings['api_secret'] = \ first_password['clear_password'].split(':')[0] if first_password else '' settings['access_token'] = \ first_password['username'] if first_password else '' settings['access_token_secret'] = \ first_password['clear_password'].split(':')[1] if first_password else '' # Read state of the Twitter input settings['enabled'] = (twitter_input['disabled'] == '0') # Create a SetupForm with the settings return cls(settings)
def create(self, name, exclude="", index="main", host="splunk", duration="", timefield="sys_updated_on", since_when=""): inputs = client.Collection(self.service, INPUT_PATH % "snow") props = { "host": host, "index": index, "timefield": timefield, "duration": duration, "app": SNOW_TA_NAME, "owner": self.service.namespace.get('owner') } if exclude: props["exclude"] = exclude if since_when: props["since_when"] = since_when inputs.create(name, **props)
def _upgrade_datamodel(service, results): collection = client.Collection(service, DATAMODEL_REST) models = collection.list(search='name=Detailed_Billing') result = '' if len(models) == 1: detailed_model = models[0] origin_description = detailed_model.content.description updated_description = upgrade_421(origin_description) updated_description = upgrade_500(updated_description) updated_description = upgrade_510(updated_description) if origin_description != updated_description: detailed_model.update(**{'description': updated_description}) result += 'Detailed_Billing' models = collection.list(search='name=Instance_Hour') if len(models) == 1: instance_hour_model = models[0] origin_description = instance_hour_model.content.description updated_description = instance_hour_upgrade_510(origin_description) if origin_description != updated_description: instance_hour_model.update(**{'description': updated_description}) result += 'Instance_Hour' if result == '': result = 'Nothing needs to be migrated' results.append({ 'name': 'Detailed Billing/Instance Hour', 'description': result }) return results
def __init__(self, *args, **kwargs): """ Raises: NotImplementedError: in case there is any mandantory param that haven't been set """ for arg in FIELDS: if not hasattr(self, arg): logger.error('Missing variable %s for handler %s. Please implement __init__ ' 'and set these variables to self: %s' % (self.input_name, arg, ', '.join(FIELDS))) raise NotImplementedError('Please implement __init__ and set these variables to self') admin.MConfigHandler.__init__( self, *args, **kwargs ) # Origin endpoint is generated by UCC and renamed by build.py # Refer to both build.py and restmap.conf self._origin_endpoint = getattr(self, 'origin_endpoint') if hasattr(self, 'origin_endpoint') else self.input_name + '_inputs_rh_ucc' self._service = LocalServiceManager(app=tac.splunk_ta_aws, session_key=self.getSessionKey()).get_local_service() self._collection = client.Collection(self._service, self._origin_endpoint)
def load(cls, request): """Loads this form's persisted state, returning a new Form.""" service = request.service # Locate the storage/passwords entity that contains the # credentials, if available. passwords_endpoint = client.Collection(service, 'storage/passwords') passwords = passwords_endpoint.list() first_password = passwords[0] if len(passwords) > 0 else None settings = {} # Read credentials from the password entity. # NOTE: Reading from 'password' setting just gives a bunch of asterisks, # so we need to read from the 'clear_password' setting instead. # NOTE: Reading from 'name' setting gives back a string in the form # '<realm>:<username>', when we only want the username. # So we need to read from the 'username' setting instead. settings['password'] = first_password['clear_password'].split(':')[0] if first_password else '' settings['username'] = first_password['username'] if first_password else '' # Create a SetupForm with the settings return cls(settings)
def _set_config(cls, service, stanza='console', **kwargs): """Set non-credential Code42 configuration settings entity""" config_endpoint = client.Collection(service, 'code42/config/%s' % stanza) config_endpoint.post(**kwargs)
def _get_snow_default(self, service): collection = client.Collection(service,"service_now_setup/snow_account").list() for item in collection: if item.name == "snow_default": return item
def _set_credentials(service, **kwargs): """Set new Code42 Server credentials entity""" passwords_endpoint = client.Collection(service, 'storage/passwords') passwords_endpoint.create(**kwargs)
def list(self): inputs = client.Collection(self.service, INPUT_PATH % "snow") return inputs.list(*["snow"])
import dbx_bootstrap_env import splunk.Intersplunk as interSplunk from dbx2.splunk_client.splunk_service_factory import SplunkServiceFactory import splunklib.client as client # get data volume per source type results, dummy_results, settings = interSplunk.getOrganizedResults() splunk_service = SplunkServiceFactory.create(session_key=settings['sessionKey'], app=settings['namespace'], owner=settings['owner']) all_inputs = client.Collection(splunk_service, 'configs/conf-db_inputs').list() # get all source types. source_types = set([x.content.get('sourcetype') for x in all_inputs if 'splunk_app_db_connect' == x.content.get('eai:appName')]) # get data volume per source type. output = [x for x in results if x.get('series') in source_types] # return result interSplunk.outputResults(output)