<?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: Converting index query to data model query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669122#M229510</link>
    <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;That works for fields (like signature in this example) which are directly available from the data model.&lt;BR /&gt;&lt;BR /&gt;But if we want to create new fields within the search (like grouping_signature in this example) to perform some calculations using eval or string concatenations and use them to do a group by, how could we accomplish that in the tstats query?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example, I want to use eval to concatenate signature and file_name fields into a new field called grouping_signature and then use the new field for the group by. If the file_name is not present, then only use signature for the group by(that's why eval to perform that check).&lt;/P&gt;</description>
    <pubDate>Sun, 19 Nov 2023 19:27:44 GMT</pubDate>
    <dc:creator>north_star</dc:creator>
    <dc:date>2023-11-19T19:27:44Z</dc:date>
    <item>
      <title>Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669101#M229500</link>
      <description>&lt;P&gt;I have tried to simplify the query for better understanding and removing some unnecessary things.&lt;BR /&gt;&lt;BR /&gt;This query is to find out if the same malware has been found on more than 4 hosts (dest) in a given time span, something like a malware outbreak.&lt;/P&gt;&lt;P&gt;Below is the indexed based query that works fine. I am trying to convert this to a data model based query, but not getting the desired results. I am new to writing data model based queries. Thanks for all the help!&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(`cim_Malware_indexes`) tag=malware tag=attack&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| eval grouping_signature=if(isnotnull(file_name),signature . ":" . file_name,signature)&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&amp;gt; trying to create a new field called "grouping_signature" by concatenating signature and file_name fields&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| stats count dc(dest) as infected_device_count BY grouping_signature&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&amp;gt; trying to calculate the distinct count of hosts the have the same malware found on them by "grouping_signature" field&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| where infected_device_count &amp;gt; 4&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&amp;gt; trying to find events where number of infected devices is greater than 4&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| stats sum(count) AS "count" sum(infected_device_count) AS infected_device_count BY grouping_signature&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&amp;gt; trying to find the total number of infected hosts by "grouping_signature" field&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 17:22:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669101#M229500</guid>
      <dc:creator>north_star</dc:creator>
      <dc:date>2023-11-19T17:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669113#M229506</link>
      <description>&lt;P&gt;1. Why do the | eval dest=lower(dest) ? CIM is for normalizing your data. Do it properly - unify the case of your names.&lt;/P&gt;&lt;P&gt;2. if(isnotnull ... can be expressed more clearly with coalesce().&lt;/P&gt;&lt;P&gt;3. You're searching from CIM indexes but you're manually doing things like | rename computerDnsName as dest. You should have done that as calculated field to make your data CIM-compliant.&lt;/P&gt;&lt;P&gt;So first you should make your data CIM-compliant then tell us what you want to achieve.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 08:13:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669113#M229506</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-11-19T08:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669119#M229508</link>
      <description>&lt;P&gt;Ok, I have tried to simplify the query for better understanding and removing some unnecessary things.&lt;BR /&gt;&lt;BR /&gt;This query is to find out if the same malware has been found on more than 4 hosts (dest) in a given time span, something like a malware outbreak.&lt;/P&gt;&lt;P&gt;Below is the indexed based query that works fine. I am trying to convert this to a data model based query.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(`cim_Malware_indexes`) tag=malware tag=attack&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| eval grouping_signature=if(isnotnull(file_name),signature . ":" . file_name,signature)&lt;/STRONG&gt; =&amp;gt; trying to create a new field called "grouping_signature" by concatenating signature and file_name fields&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| stats count dc(dest) as infected_device_count BY grouping_signature&lt;/STRONG&gt; =&amp;gt; trying to calculate the distinct count of hosts the have the same malware found on them by "grouping_signature" field&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| where infected_device_count &amp;gt; 4&lt;/STRONG&gt; =&amp;gt; trying to find events where number of infected devices is greater than 4&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| stats sum(count) AS "count" sum(infected_device_count) AS infected_device_count BY grouping_signature&lt;/STRONG&gt; =&amp;gt; trying to find the total number of infected hosts by "grouping_signature" field&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 17:13:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669119#M229508</guid>
      <dc:creator>north_star</dc:creator>
      <dc:date>2023-11-19T17:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669121#M229509</link>
      <description>&lt;P&gt;OK. I never remember the proper syntax from tstatsing from datamodel so you might need to correct this a bit but you'd probably want something like this&lt;/P&gt;&lt;PRE&gt;| tstats values(Malware.dest) as hosts from datamodel=Malware.something by Malware.signature&lt;/PRE&gt;&lt;P&gt;This will give you list of hosts by each signature from a given period. Now you might want to put it through&lt;/P&gt;&lt;PRE&gt;| where mvcount(hosts)&amp;gt;4&lt;/PRE&gt;&lt;P&gt;or something like that.&lt;/P&gt;&lt;P&gt;You can't do complicated aggregations with tstats - that's why you should normalize your data. That's what the whole datamodel is for.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 17:48:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669121#M229509</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-11-19T17:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669122#M229510</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;That works for fields (like signature in this example) which are directly available from the data model.&lt;BR /&gt;&lt;BR /&gt;But if we want to create new fields within the search (like grouping_signature in this example) to perform some calculations using eval or string concatenations and use them to do a group by, how could we accomplish that in the tstats query?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example, I want to use eval to concatenate signature and file_name fields into a new field called grouping_signature and then use the new field for the group by. If the file_name is not present, then only use signature for the group by(that's why eval to perform that check).&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 19:27:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669122#M229510</guid>
      <dc:creator>north_star</dc:creator>
      <dc:date>2023-11-19T19:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669123#M229511</link>
      <description>&lt;P&gt;No. You can't do that using tstats.&lt;/P&gt;&lt;P&gt;You can do the search using&lt;/P&gt;&lt;PRE&gt;| datamodel Malware search&lt;/PRE&gt;&lt;P&gt;or&lt;/P&gt;&lt;PRE&gt;| from datamodel=Malware&lt;/PRE&gt;&lt;P&gt;and then do normal stats but this way you won't be able to leverage the acceleration of summaries.&lt;/P&gt;&lt;P&gt;You could try to append two separate tstats (one with filenames and one without) using tstats in prestats=t and append=t but that's some very confusing functionality.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 20:54:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669123#M229511</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-11-19T20:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting index query to data model query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669124#M229512</link>
      <description>&lt;P&gt;Ok, thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 21:22:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-index-query-to-data-model-query/m-p/669124#M229512</guid>
      <dc:creator>north_star</dc:creator>
      <dc:date>2023-11-19T21:22:22Z</dc:date>
    </item>
  </channel>
</rss>

