<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to create dynamic custom functions? in Splunk SOAR</title>
    <link>https://community.splunk.com/t5/Splunk-SOAR/How-to-create-dynamic-custom-functions/m-p/605820#M895</link>
    <description>&lt;P&gt;Hoping someone can help me get past the last hurdle.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm trying to create a custom function that dynamically calls other custom functions.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've got the part of generating the list of desired functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand how to make sure the datapath into the dynamically selected custom function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to pass the results out to a filter object, but it seems to be coming out only as a single variable. not an array.&lt;/P&gt;
&lt;P&gt;What am I missing?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def rule_check(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
    phantom.debug('rule_check() called')
    
    custom_function_results_data_1 = phantom.collect2(container=container, datapath=['build:custom_function_result.data.data_packets.*.packet'], action_results=results)
    custom_function_results_data_2 = phantom.collect2(container=container, datapath=['get_funcs:custom_function_result.data.found_functions.*.function_path'], action_results=results)
    custom_function_results_item_1_0 = [item[0] for item in custom_function_results_data_1]
    custom_function_results_item_2_0 = [item[0] for item in custom_function_results_data_2]

    rule_check__data = None

    ################################################################################
    ## Custom Code Start
    ################################################################################

    # Write your custom code here...

    parameters = []

    for item0 in custom_function_results_data_1:
        parameters.append({
            'data_w_fields': item0[0],
        })        
        
    for func in custom_function_results_item_2_0:
        a = phantom.custom_function(custom_function=func, parameters=parameters, name='rule_check')

    ################################################################################
    ## Custom Code End
    ################################################################################

    phantom.save_run_data(key='rule_check:data', value=json.dumps(rule_check__data))
    filter_1(container=container)

    return&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jul 2022 16:58:02 GMT</pubDate>
    <dc:creator>Dave_Burns</dc:creator>
    <dc:date>2022-07-15T16:58:02Z</dc:date>
    <item>
      <title>How to create dynamic custom functions?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/How-to-create-dynamic-custom-functions/m-p/605820#M895</link>
      <description>&lt;P&gt;Hoping someone can help me get past the last hurdle.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm trying to create a custom function that dynamically calls other custom functions.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've got the part of generating the list of desired functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand how to make sure the datapath into the dynamically selected custom function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to pass the results out to a filter object, but it seems to be coming out only as a single variable. not an array.&lt;/P&gt;
&lt;P&gt;What am I missing?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def rule_check(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
    phantom.debug('rule_check() called')
    
    custom_function_results_data_1 = phantom.collect2(container=container, datapath=['build:custom_function_result.data.data_packets.*.packet'], action_results=results)
    custom_function_results_data_2 = phantom.collect2(container=container, datapath=['get_funcs:custom_function_result.data.found_functions.*.function_path'], action_results=results)
    custom_function_results_item_1_0 = [item[0] for item in custom_function_results_data_1]
    custom_function_results_item_2_0 = [item[0] for item in custom_function_results_data_2]

    rule_check__data = None

    ################################################################################
    ## Custom Code Start
    ################################################################################

    # Write your custom code here...

    parameters = []

    for item0 in custom_function_results_data_1:
        parameters.append({
            'data_w_fields': item0[0],
        })        
        
    for func in custom_function_results_item_2_0:
        a = phantom.custom_function(custom_function=func, parameters=parameters, name='rule_check')

    ################################################################################
    ## Custom Code End
    ################################################################################

    phantom.save_run_data(key='rule_check:data', value=json.dumps(rule_check__data))
    filter_1(container=container)

    return&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 16:58:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/How-to-create-dynamic-custom-functions/m-p/605820#M895</guid>
      <dc:creator>Dave_Burns</dc:creator>
      <dc:date>2022-07-15T16:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic custom functions?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/How-to-create-dynamic-custom-functions/m-p/606889#M919</link>
      <description>&lt;P&gt;I'll post a reply to myself, in case someone else wonders the same thing.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;In this particular case, you've got literally just run a for loop of all the custom functions, w/ the callback baked in. Then add in the return. This forces it to ignore the custom code end.&amp;nbsp; (Making it abit of a dead path)&lt;BR /&gt;&lt;BR /&gt;Not ideal programmatically, but it works.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 15:41:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/How-to-create-dynamic-custom-functions/m-p/606889#M919</guid>
      <dc:creator>Dave_Burns</dc:creator>
      <dc:date>2022-07-25T15:41:44Z</dc:date>
    </item>
  </channel>
</rss>

