<?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 Pre Processing script for dropping multiple similar incidents in Cortex XSOAR Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/pre-processing-script-for-dropping-multiple-similar-incidents/m-p/1226191#M3977</link>
    <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to find a way to drop similar events (by eventnames field)&amp;nbsp; from QRadar when they are mirrored in in XSOAR&amp;nbsp; by using a pre process rule &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have checked for a native approach in Cortex Xsoar to do it but it seems that &lt;BR /&gt;Pre-processing rules in XSOAR &lt;STRONG data-start="451" data-end="494"&gt;cannot natively count similar incidents&lt;/STRONG&gt; based on a dynamic field like "eventnames over a time window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have created a script to do it for me but it doesn't seem to be working as expected (disregard the indentation in the body - can't properly copy it here)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have put some fail safe check because&amp;nbsp; in XSOAR it says"&lt;STRONG&gt;In order for the script to be dropped, script must return false&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;U&gt;Here is the Script:&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;"""&lt;BR /&gt;Pre-processing script to drop newly mirrored in 'Qradar Generic' incidents&lt;BR /&gt;if 5 or more similar incidents with the same event name exist in the last 20 minutes.&lt;BR /&gt;"""&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;def should_drop_incident(incident):&lt;BR /&gt;incident_type = incident.get('type')&lt;BR /&gt;current_id = incident.get('id')&lt;/P&gt;
&lt;P&gt;eventnames = incident.get('eventnames', [])&lt;BR /&gt;if isinstance(eventnames, list):&lt;BR /&gt;description = eventnames[0].strip() if eventnames else ''&lt;BR /&gt;else:&lt;BR /&gt;description = str(eventnames).strip()&lt;/P&gt;
&lt;P&gt;if incident_type != 'Qradar Generic' or not description:&lt;BR /&gt;return True # keep it&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;query = f'type:"Qradar Generic" and eventnames:"{description}" and created:&amp;gt;=\"20 minutes ago\"'&lt;/P&gt;
&lt;P&gt;populate_fields = ['id', 'eventnames']&lt;BR /&gt;res = demisto.executeCommand('GetIncidentsByQuery', {&lt;BR /&gt;'query': query,&lt;BR /&gt;'pageSize': 100,&lt;BR /&gt;'populateFields': ','.join(populate_fields)&lt;BR /&gt;})&lt;/P&gt;
&lt;P&gt;if isError(res[0]):&lt;BR /&gt;return_results({"Error": res[0].get("Contents", "Unknown error")})&lt;BR /&gt;return True # fail-safe: keep incident&lt;/P&gt;
&lt;P&gt;contents = res[0].get('Contents', '')&lt;BR /&gt;if isinstance(contents, str):&lt;BR /&gt;try:&lt;BR /&gt;incidents = json.loads(contents)&lt;BR /&gt;except Exception as e:&lt;BR /&gt;return_results({"ParseError": str(e)})&lt;BR /&gt;return True # fail-safe: keep incident&lt;BR /&gt;else:&lt;BR /&gt;incidents = contents.get('data', []) if isinstance(contents, dict) else []&lt;/P&gt;
&lt;P&gt;matched_ids = [i.get('id') for i in incidents if isinstance(i, dict) and i.get('id') != current_id]&lt;BR /&gt;matching_count = len(matched_ids)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;return matching_count &amp;lt; 5 # True = keep, False = drop&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;# Run main logic&lt;BR /&gt;drop_incident = should_drop_incident(demisto.incidents()[0])&lt;BR /&gt;return_results(drop_incident)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will appreciate any tips on this&amp;nbsp; or another way to achieve similar effect&amp;nbsp; in XSoar&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Yuri&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Apr 2025 08:51:50 GMT</pubDate>
    <dc:creator>ymaslovski</dc:creator>
    <dc:date>2025-04-10T08:51:50Z</dc:date>
    <item>
      <title>Pre Processing script for dropping multiple similar incidents</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/pre-processing-script-for-dropping-multiple-similar-incidents/m-p/1226191#M3977</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to find a way to drop similar events (by eventnames field)&amp;nbsp; from QRadar when they are mirrored in in XSOAR&amp;nbsp; by using a pre process rule &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have checked for a native approach in Cortex Xsoar to do it but it seems that &lt;BR /&gt;Pre-processing rules in XSOAR &lt;STRONG data-start="451" data-end="494"&gt;cannot natively count similar incidents&lt;/STRONG&gt; based on a dynamic field like "eventnames over a time window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have created a script to do it for me but it doesn't seem to be working as expected (disregard the indentation in the body - can't properly copy it here)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have put some fail safe check because&amp;nbsp; in XSOAR it says"&lt;STRONG&gt;In order for the script to be dropped, script must return false&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;U&gt;Here is the Script:&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;"""&lt;BR /&gt;Pre-processing script to drop newly mirrored in 'Qradar Generic' incidents&lt;BR /&gt;if 5 or more similar incidents with the same event name exist in the last 20 minutes.&lt;BR /&gt;"""&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;def should_drop_incident(incident):&lt;BR /&gt;incident_type = incident.get('type')&lt;BR /&gt;current_id = incident.get('id')&lt;/P&gt;
&lt;P&gt;eventnames = incident.get('eventnames', [])&lt;BR /&gt;if isinstance(eventnames, list):&lt;BR /&gt;description = eventnames[0].strip() if eventnames else ''&lt;BR /&gt;else:&lt;BR /&gt;description = str(eventnames).strip()&lt;/P&gt;
&lt;P&gt;if incident_type != 'Qradar Generic' or not description:&lt;BR /&gt;return True # keep it&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;query = f'type:"Qradar Generic" and eventnames:"{description}" and created:&amp;gt;=\"20 minutes ago\"'&lt;/P&gt;
&lt;P&gt;populate_fields = ['id', 'eventnames']&lt;BR /&gt;res = demisto.executeCommand('GetIncidentsByQuery', {&lt;BR /&gt;'query': query,&lt;BR /&gt;'pageSize': 100,&lt;BR /&gt;'populateFields': ','.join(populate_fields)&lt;BR /&gt;})&lt;/P&gt;
&lt;P&gt;if isError(res[0]):&lt;BR /&gt;return_results({"Error": res[0].get("Contents", "Unknown error")})&lt;BR /&gt;return True # fail-safe: keep incident&lt;/P&gt;
&lt;P&gt;contents = res[0].get('Contents', '')&lt;BR /&gt;if isinstance(contents, str):&lt;BR /&gt;try:&lt;BR /&gt;incidents = json.loads(contents)&lt;BR /&gt;except Exception as e:&lt;BR /&gt;return_results({"ParseError": str(e)})&lt;BR /&gt;return True # fail-safe: keep incident&lt;BR /&gt;else:&lt;BR /&gt;incidents = contents.get('data', []) if isinstance(contents, dict) else []&lt;/P&gt;
&lt;P&gt;matched_ids = [i.get('id') for i in incidents if isinstance(i, dict) and i.get('id') != current_id]&lt;BR /&gt;matching_count = len(matched_ids)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;return matching_count &amp;lt; 5 # True = keep, False = drop&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;# Run main logic&lt;BR /&gt;drop_incident = should_drop_incident(demisto.incidents()[0])&lt;BR /&gt;return_results(drop_incident)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will appreciate any tips on this&amp;nbsp; or another way to achieve similar effect&amp;nbsp; in XSoar&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Yuri&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 08:51:50 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/pre-processing-script-for-dropping-multiple-similar-incidents/m-p/1226191#M3977</guid>
      <dc:creator>ymaslovski</dc:creator>
      <dc:date>2025-04-10T08:51:50Z</dc:date>
    </item>
  </channel>
</rss>

