<?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 Re: How do i stop a running playbook when the case changed to closed? in Splunk SOAR</title>
    <link>https://community.splunk.com/t5/Splunk-SOAR/How-do-i-stop-a-running-playbook-when-the-case-changed-to-closed/m-p/661273#M1290</link>
    <description>&lt;P&gt;As of version 6 we're able to run playbooks when a container is closed. That's the easy part. Canceling running playbooks takes a few custom API calls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    # Pulls the id for this playbook. It shouldn't be hardcoded because the ID changes with each version and may not increment as expected
    my_id_url = phantom.build_phantom_rest_url('playbook') + '?_filter_name="my_playbook_name"'
    my_id_resp_json = phantom.requests.get(my_id_url, verify=False).json()
    my_id = my_id_resp_json['data'][0]['id']
    
    # Runs a query to pull the audit data of the current container
    audit_url = phantom.build_phantom_rest_url('container', container_id, 'audit')
    audit_resp_json = phantom.requests.get(audit_url, verify=False).json()

    for i in audit_resp_json:
        # Looks for any playbook that has run in the container
         if i['AUDIT SOURCE'] == 'Playbook Run':

                # Runs a query to find details on each run
                runs_url = phantom.build_phantom_rest_url('playbook_run', i['AUDIT ID'])
                runs_resp_json = phantom.requests.get(runs_url, verify=False).json()
                

		# Finds any playbook that is currently running which isn't this one
                if runs_resp_json['status'] == 'running' and runs_resp_json['playbook'] != my_id:
                    
                    #Sends a POST to cancel any that match the above criteria
                    cancel_url = phantom.build_phantom_rest_url('playbook_run', runs_resp_json['id'])
                    cancel_post = phantom.requests.post(cancel_url, data='{"cancel":true}', verify=False)

                    # If successful, up the succes count
                    if cancel_post.status_code == 200:
					    # Success
                    else:
                        # Failure
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2023 21:59:00 GMT</pubDate>
    <dc:creator>SOARt_of_Lost</dc:creator>
    <dc:date>2023-10-18T21:59:00Z</dc:date>
    <item>
      <title>How do i stop a running playbook when the case changed to closed?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/How-do-i-stop-a-running-playbook-when-the-case-changed-to-closed/m-p/645546#M1195</link>
      <description>&lt;P&gt;I have an active playbook that runs on most event types, but some get auto-closed and I would like to know if there's a way to end the playbook run if it the case gets closed before it finishes the playbook run.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 12:25:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/How-do-i-stop-a-running-playbook-when-the-case-changed-to-closed/m-p/645546#M1195</guid>
      <dc:creator>kblaine</dc:creator>
      <dc:date>2023-06-02T12:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do i stop a running playbook when the case changed to closed?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/How-do-i-stop-a-running-playbook-when-the-case-changed-to-closed/m-p/661273#M1290</link>
      <description>&lt;P&gt;As of version 6 we're able to run playbooks when a container is closed. That's the easy part. Canceling running playbooks takes a few custom API calls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    # Pulls the id for this playbook. It shouldn't be hardcoded because the ID changes with each version and may not increment as expected
    my_id_url = phantom.build_phantom_rest_url('playbook') + '?_filter_name="my_playbook_name"'
    my_id_resp_json = phantom.requests.get(my_id_url, verify=False).json()
    my_id = my_id_resp_json['data'][0]['id']
    
    # Runs a query to pull the audit data of the current container
    audit_url = phantom.build_phantom_rest_url('container', container_id, 'audit')
    audit_resp_json = phantom.requests.get(audit_url, verify=False).json()

    for i in audit_resp_json:
        # Looks for any playbook that has run in the container
         if i['AUDIT SOURCE'] == 'Playbook Run':

                # Runs a query to find details on each run
                runs_url = phantom.build_phantom_rest_url('playbook_run', i['AUDIT ID'])
                runs_resp_json = phantom.requests.get(runs_url, verify=False).json()
                

		# Finds any playbook that is currently running which isn't this one
                if runs_resp_json['status'] == 'running' and runs_resp_json['playbook'] != my_id:
                    
                    #Sends a POST to cancel any that match the above criteria
                    cancel_url = phantom.build_phantom_rest_url('playbook_run', runs_resp_json['id'])
                    cancel_post = phantom.requests.post(cancel_url, data='{"cancel":true}', verify=False)

                    # If successful, up the succes count
                    if cancel_post.status_code == 200:
					    # Success
                    else:
                        # Failure
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 21:59:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/How-do-i-stop-a-running-playbook-when-the-case-changed-to-closed/m-p/661273#M1290</guid>
      <dc:creator>SOARt_of_Lost</dc:creator>
      <dc:date>2023-10-18T21:59:00Z</dc:date>
    </item>
  </channel>
</rss>

