def check_last_time_ran(automation_name, authentication): search_filter = { 'Property': 'Name', 'SimpleOperator': 'equals', 'Value': automation_name } props = ['Name', 'CustomerKey', 'ProgramID', 'CompletedTime', 'Status'] instances = FuelSDK.ET_Get(auth_stub=authentication, obj_type='AutomationInstance', props=props, search_filter=search_filter) instances.results.sort(key=lambda automation: automation.CompletedTime) last_instance_completed_time = instances.results[-1].CompletedTime last_instance_status = instances.results[-1].StatusMessage if last_instance_status == "Error": print( f'{automation_name} last ran at {last_instance_completed_time} with status: {Fore.RED}{last_instance_status}{Style.RESET_ALL}' ) else: print( f'{automation_name} last ran at {last_instance_completed_time} with status: {Fore.BLUE}{last_instance_status}{Style.RESET_ALL}' )
def check_automation_is_turned_on(automation_name, authentication): search_filter = { 'Property': 'Name', 'SimpleOperator': 'equals', 'Value': automation_name } props = ["Name", "Status", "ScheduledTime", "CustomerKey"] automation = FuelSDK.ET_Get(auth_stub=authentication, obj_type="Automation", props=props, search_filter=search_filter) automation_status = automation.results[0].Status customer_key = automation.results[0].CustomerKey status = get_automation_status(automation_status) if automation_status == 6 or automation_status == 7: print( f'{Fore.GREEN}{automation_name} is set to: {status}{Style.RESET_ALL}' ) check_last_time_ran(automation_name, authentication) else: print( f'{Fore.RED}{automation_name} is currently set to: {status}{Style.RESET_ALL}' ) if status != "Running": check_last_time_ran(automation_name, authentication)
def search_queries(args): create_query_csv() with open(f"{Path.home()}/sfmc_cli_credentials.json", "r") as f: accounts = json.loads(f.read()) for account in accounts: print(f'{Fore.BLUE}==== Searching in {account["name"]} ====') auth_token = retrieve_auth_token(account["name"]) search_filter = { 'Property': 'QueryText', 'SimpleOperator': 'like', 'Value': args } props = ["Name", "Status", "QueryText"] queries = FuelSDK.ET_Get(auth_stub=auth_token, obj_type="QueryDefinition", props=props, search_filter=search_filter) for result in queries.results: query_name = result.Name automation_name = retrieve_automation_name_for_query( auth_token, query_name) print(f'{account["name"]},{result.Name},{automation_name}') write_to_query_csv( f'{account["name"]},{result.Name},{automation_name}\n') print( f'{Fore.GREEN}==== You can find the csv file at: ~/sfmc_cli_queries_result.csv ====' )
def get(self): self.getName() ''' if props and props.is_a? Array then @props = props end ''' if self.props is not None and type(self.props) is dict: # pylint:disable=unidiomatic-typecheck self.props = self.props.keys() ''' if filter and filter.is_a? Hash then @filter = filter end ''' # add 'options' parameter to set 'batch_size' obj = FuelSDK.ET_Get(self.auth_stub, "DataExtensionObject[{0}]".format(self.Name), self.props, self.search_filter, self.options) self.last_request_id = obj.request_id return obj
def get(self): ''' if props and props.is_a? Array then @props = props end ''' if self.props is not None and type(self.props) is dict: # pylint:disable=unidiomatic-typecheck self.props = self.props.keys() ''' if filter and filter.is_a? Hash then @filter = filter end ''' ''' fixCustomerKey = False if filter and filter.is_a? Hash then @filter = filter if @filter.has_key?("Property") && @filter["Property"] == "CustomerKey" then @filter["Property"] = "DataExtension.CustomerKey" fixCustomerKey = true end end ''' # add 'options' parameter to set 'batch_size' obj = FuelSDK.ET_Get(self.auth_stub, self.obj, self.props, self.search_filter, self.options) self.last_request_id = obj.request_id ''' if fixCustomerKey then @filter["Property"] = "CustomerKey" end ''' return obj