<?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 Searching based on a particular element of a JSON array in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408244#M72377</link>
    <description>&lt;P&gt;I have Splunk ingesting JSON output from a tool we have which processes SNMP traps, which for the most part works great. The problem I have is with accessing elements of the JSON arrays. An example of one of our log entries is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{   [-] 
  agent:     192.168.0.1    
  logs:  0&amp;gt; Queued for 3 targets
  0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public
  0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public

  pathname:  /Root/EMS
  pdu:  {   [-] 
    oids:   [   [-] 
      1.3.6.1.2.1.1.3.0 
      1.3.6.1.6.3.1.1.4.1.0 
      1.3.6.1.4.1.4998.1.1.10.1.1.2.0   
      1.3.6.1.4.1.4998.1.1.10.1.1.3.0   
      1.3.6.1.4.1.4115.1.9.1.2.9.1.1.2  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.1.61335  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.4.61335  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.3.61335  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.5.61335  
      1.3.6.1.6.3.18.1.3.0  
    ]   
    pduType:     TRAP   
    types:  [   [-] 
      TimeTicks 
      OID   
      Counter32 
      Integer32 
      Integer32 
      Integer32 
      OctetString   
      OctetString   
      Integer32 
      IpAddress 
    ]   
    variables:  [   [-] 
      1481974575    
      1.3.6.1.4.1.4115.1.9.1.2.15.0.3   
      134998    
      7 
      2 
      61335 
      ac:12:7a:25   
      00:00:00:00   
      51605 
      192.168.0.1   
    ]   
  } 
  peer:  192.168.0.1    
  securityName:  public
  securityNameIsPrintable:   true   
  timestamp:     1555347384005  
  version:   v2c    
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The raw event is: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"timestamp":1555347384005,"peer":"192.168.0.1","agent":"192.168.0.1","securityName":"public","version":"v2c","pdu":{"oids":["1.3.6.1.2.1.1.3.0","1.3.6.1.6.3.1.1.4.1.0","1.3.6.1.4.1.4998.1.1.10.1.1.2.0","1.3.6.1.4.1.4998.1.1.10.1.1.3.0","1.3.6.1.4.1.4115.1.9.1.2.9.1.1.2","1.3.6.1.4.1.4115.1.9.1.2.5.1.1.61335","1.3.6.1.4.1.4115.1.9.1.2.5.1.4.61335","1.3.6.1.4.1.4115.1.9.1.2.5.1.3.61335","1.3.6.1.4.1.4115.1.9.1.2.5.1.5.61335","1.3.6.1.6.3.18.1.3.0"],"variables":["1481974575","1.3.6.1.4.1.4115.1.9.1.2.15.0.3","134998","7","2","61335","ac:12:7a:25","00:00:00:00","51605","192.168.0.1"],"types":["TimeTicks","OID","Counter32","Integer32","Integer32","Integer32","OctetString","OctetString","Integer32","IpAddress"],"pduType":"TRAP"},"securityNameIsPrintable":true,"pathname":"/Root/EMS","logs":"0&amp;gt; Queued for 3 targets\n0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public\n0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public\n"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can easily search the top-level fields (such as agent or peer). I can also search the deeper fields that have a single value (such as pdu.pduType). The issue is with the nested array fields (e.g. pdu.variables). I can search for a value in that field if I use &lt;CODE&gt;pdu.variables{}=value&lt;/CODE&gt;, but that just tells me if &lt;EM&gt;any&lt;/EM&gt; field is that value. I want to be able to treat it like an array and use an index, such as &lt;CODE&gt;pdu.variables{0}=value&lt;/CODE&gt;, but that doesn't work.&lt;/P&gt;

&lt;P&gt;I have done some poking around on Splunk Answers and found &lt;A href="https://answers.splunk.com/answers/373925/how-to-refer-to-json-array-object-in-a-splunk-sear.html"&gt;this answer&lt;/A&gt; which suggested that I should use &lt;CODE&gt;mvIndex&lt;/CODE&gt; to get the value out, but &lt;CODE&gt;eval foo = mvIndex(pdu.variables, 0) | search foo=1481974575&lt;/CODE&gt; returns zero results, even though it should return the example I have included here. So I'm at a loss as to how to actually get Splunk to actually search in these fields correctly. I could do it pretty easily if I downloaded the raw data and wrote a script, but I imagine there has to be a way to have Splunk do the search I want.&lt;/P&gt;

&lt;P&gt;For what it's worth, my ultimate goal is to get a stats overview of SNMP trap types, so I can count which trap types are most prevalent in our environment. So what I need to do here is tag the second element of pdu.variables as a field called trapType, then do &lt;CODE&gt;| stats count by trapType&lt;/CODE&gt; to get the overview I want.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2019 17:21:48 GMT</pubDate>
    <dc:creator>cdrzewiecki</dc:creator>
    <dc:date>2019-04-15T17:21:48Z</dc:date>
    <item>
      <title>Searching based on a particular element of a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408244#M72377</link>
      <description>&lt;P&gt;I have Splunk ingesting JSON output from a tool we have which processes SNMP traps, which for the most part works great. The problem I have is with accessing elements of the JSON arrays. An example of one of our log entries is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{   [-] 
  agent:     192.168.0.1    
  logs:  0&amp;gt; Queued for 3 targets
  0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public
  0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public

  pathname:  /Root/EMS
  pdu:  {   [-] 
    oids:   [   [-] 
      1.3.6.1.2.1.1.3.0 
      1.3.6.1.6.3.1.1.4.1.0 
      1.3.6.1.4.1.4998.1.1.10.1.1.2.0   
      1.3.6.1.4.1.4998.1.1.10.1.1.3.0   
      1.3.6.1.4.1.4115.1.9.1.2.9.1.1.2  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.1.61335  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.4.61335  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.3.61335  
      1.3.6.1.4.1.4115.1.9.1.2.5.1.5.61335  
      1.3.6.1.6.3.18.1.3.0  
    ]   
    pduType:     TRAP   
    types:  [   [-] 
      TimeTicks 
      OID   
      Counter32 
      Integer32 
      Integer32 
      Integer32 
      OctetString   
      OctetString   
      Integer32 
      IpAddress 
    ]   
    variables:  [   [-] 
      1481974575    
      1.3.6.1.4.1.4115.1.9.1.2.15.0.3   
      134998    
      7 
      2 
      61335 
      ac:12:7a:25   
      00:00:00:00   
      51605 
      192.168.0.1   
    ]   
  } 
  peer:  192.168.0.1    
  securityName:  public
  securityNameIsPrintable:   true   
  timestamp:     1555347384005  
  version:   v2c    
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The raw event is: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"timestamp":1555347384005,"peer":"192.168.0.1","agent":"192.168.0.1","securityName":"public","version":"v2c","pdu":{"oids":["1.3.6.1.2.1.1.3.0","1.3.6.1.6.3.1.1.4.1.0","1.3.6.1.4.1.4998.1.1.10.1.1.2.0","1.3.6.1.4.1.4998.1.1.10.1.1.3.0","1.3.6.1.4.1.4115.1.9.1.2.9.1.1.2","1.3.6.1.4.1.4115.1.9.1.2.5.1.1.61335","1.3.6.1.4.1.4115.1.9.1.2.5.1.4.61335","1.3.6.1.4.1.4115.1.9.1.2.5.1.3.61335","1.3.6.1.4.1.4115.1.9.1.2.5.1.5.61335","1.3.6.1.6.3.18.1.3.0"],"variables":["1481974575","1.3.6.1.4.1.4115.1.9.1.2.15.0.3","134998","7","2","61335","ac:12:7a:25","00:00:00:00","51605","192.168.0.1"],"types":["TimeTicks","OID","Counter32","Integer32","Integer32","Integer32","OctetString","OctetString","Integer32","IpAddress"],"pduType":"TRAP"},"securityNameIsPrintable":true,"pathname":"/Root/EMS","logs":"0&amp;gt; Queued for 3 targets\n0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public\n0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public\n"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can easily search the top-level fields (such as agent or peer). I can also search the deeper fields that have a single value (such as pdu.pduType). The issue is with the nested array fields (e.g. pdu.variables). I can search for a value in that field if I use &lt;CODE&gt;pdu.variables{}=value&lt;/CODE&gt;, but that just tells me if &lt;EM&gt;any&lt;/EM&gt; field is that value. I want to be able to treat it like an array and use an index, such as &lt;CODE&gt;pdu.variables{0}=value&lt;/CODE&gt;, but that doesn't work.&lt;/P&gt;

&lt;P&gt;I have done some poking around on Splunk Answers and found &lt;A href="https://answers.splunk.com/answers/373925/how-to-refer-to-json-array-object-in-a-splunk-sear.html"&gt;this answer&lt;/A&gt; which suggested that I should use &lt;CODE&gt;mvIndex&lt;/CODE&gt; to get the value out, but &lt;CODE&gt;eval foo = mvIndex(pdu.variables, 0) | search foo=1481974575&lt;/CODE&gt; returns zero results, even though it should return the example I have included here. So I'm at a loss as to how to actually get Splunk to actually search in these fields correctly. I could do it pretty easily if I downloaded the raw data and wrote a script, but I imagine there has to be a way to have Splunk do the search I want.&lt;/P&gt;

&lt;P&gt;For what it's worth, my ultimate goal is to get a stats overview of SNMP trap types, so I can count which trap types are most prevalent in our environment. So what I need to do here is tag the second element of pdu.variables as a field called trapType, then do &lt;CODE&gt;| stats count by trapType&lt;/CODE&gt; to get the overview I want.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 17:21:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408244#M72377</guid>
      <dc:creator>cdrzewiecki</dc:creator>
      <dc:date>2019-04-15T17:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Searching based on a particular element of a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408245#M72378</link>
      <description>&lt;P&gt;Post your raw event (what you gave us has collapsed areas represented by the &lt;CODE&gt;[-]&lt;/CODE&gt; string sprinkled throughout.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 19:23:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408245#M72378</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-15T19:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Searching based on a particular element of a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408246#M72379</link>
      <description>&lt;P&gt;I updated my post to show the raw event as well.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 19:49:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/408246#M72379</guid>
      <dc:creator>cdrzewiecki</dc:creator>
      <dc:date>2019-04-16T19:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Searching based on a particular element of a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/505228#M86091</link>
      <description>&lt;P&gt;For the specific search above, the problem is in the field name used.&amp;nbsp; For field names with special characters in them in eval and where commands use single tick/quote.&amp;nbsp;&lt;/P&gt;&lt;P&gt;... | eval foo = mvIndex('pdu.variables{}', 0) |search foo=1481974575&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 17:23:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/505228#M86091</guid>
      <dc:creator>jnapier</dc:creator>
      <dc:date>2020-06-19T17:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Searching based on a particular element of a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/505301#M86100</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{\"timestamp\":1555347384005,\"peer\":\"192.168.0.1\",\"agent\":\"192.168.0.1\",\"securityName\":\"public\",\"version\":\"v2c\",\"pdu\":{\"oids\":[\"1.3.6.1.2.1.1.3.0\",\"1.3.6.1.6.3.1.1.4.1.0\",\"1.3.6.1.4.1.4998.1.1.10.1.1.2.0\",\"1.3.6.1.4.1.4998.1.1.10.1.1.3.0\",\"1.3.6.1.4.1.4115.1.9.1.2.9.1.1.2\",\"1.3.6.1.4.1.4115.1.9.1.2.5.1.1.61335\",\"1.3.6.1.4.1.4115.1.9.1.2.5.1.4.61335\",\"1.3.6.1.4.1.4115.1.9.1.2.5.1.3.61335\",\"1.3.6.1.4.1.4115.1.9.1.2.5.1.5.61335\",\"1.3.6.1.6.3.18.1.3.0\"],\"variables\":[\"1481974575\",\"1.3.6.1.4.1.4115.1.9.1.2.15.0.3\",\"134998\",\"7\",\"2\",\"61335\",\"ac:12:7a:25\",\"00:00:00:00\",\"51605\",\"192.168.0.1\"],\"types\":[\"TimeTicks\",\"OID\",\"Counter32\",\"Integer32\",\"Integer32\",\"Integer32\",\"OctetString\",\"OctetString\",\"Integer32\",\"IpAddress\"],\"pduType\":\"TRAP\"},\"securityNameIsPrintable\":true,\"pathname\":\"/Root/EMS\",\"logs\":\"0&amp;gt; Queued for 3 targets\n0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public\n0&amp;gt; v2c TRAP -&amp;gt; 192.168.0.2/162, sec-name=public\n\"}" 
| spath 
| eval tmp=mvzip('pdu.oids{}',mvzip('pdu.types{}','pdu.variables{}')) 
| stats values(*) as * by tmp 
| rex field=tmp "(?&amp;lt;oids&amp;gt;[^,]+),(?&amp;lt;types&amp;gt;[^,]+),(?&amp;lt;variables&amp;gt;\S+)" 
| fields - pdu.* _raw tmp&lt;/LI-CODE&gt;&lt;P&gt;I made the table, so you can search it.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 01:02:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Searching-based-on-a-particular-element-of-a-JSON-array/m-p/505301#M86100</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-06-20T01:02:35Z</dc:date>
    </item>
  </channel>
</rss>

