<?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 to count a number of  keys in json object for each event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459136#M191297</link>
    <description>&lt;P&gt;didnt understand your expected output and also what you get when you apply an spath..can you clarify a bit more?&lt;/P&gt;</description>
    <pubDate>Thu, 22 Aug 2019 10:50:35 GMT</pubDate>
    <dc:creator>Sukisen1981</dc:creator>
    <dc:date>2019-08-22T10:50:35Z</dc:date>
    <item>
      <title>How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459135#M191296</link>
      <description>&lt;P&gt;Hi, I am trying to create a table witch show number of fields in json object:&lt;/P&gt;

&lt;P&gt;Event example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{  
   "project": "my_project_name",
   "vulnerabilities":{  
      "paragonie/random_compat":{  
         "version":"v1.4.3",
         "advisories":[  
            {  
               "title":"Uses insecure CSPRNG (openssl_random_pseudo_bytes())",
               "link":"https://github.com/paragonie/random_compat/issues/96",
               "cve":""
            }
         ]
      },
      "symfony/http-foundation":{  
         "version":"v2.8.49",
         "advisories":[  
            {  
               "title":"CVE-2019-10913: Reject invalid HTTP method overrides",
               "link":"https://symfony.com/cve-2019-10913",
               "cve":"CVE-2019-10913"
            }
         ]
      },
      "symfony/polyfill-php55":{  
         "version":"v1.4.0",
         "advisories":[  
            {  
               "title":"Possible DOS attack with long user-submitted passwords (correct fix for CVE-2013-5958)",
               "link":"https://github.com/symfony/polyfill/pull/155",
               "cve":"CVE-2013-5958"
            }
         ]
      },
      "symfony/symfony":{  
         "version":"v2.3.41",
         "advisories":[  
            {  
               "title":"CVE-2018-11385: Session Fixation Issue for Guard Authentication",
               "link":"https://symfony.com/cve-2018-11385",
               "cve":"CVE-2018-11385"
            },
            {  
               "title":"CVE-2018-11386: Denial of service when using PDOSessionHandler",
               "link":"https://symfony.com/cve-2018-11386",
               "cve":"CVE-2018-11386"
            },
            {  
               "title":"CVE-2018-11406: CSRF Token Fixation",
               "link":"https://symfony.com/cve-2018-11406",
               "cve":"CVE-2018-11406"
            },
            {  
               "title":"CVE-2018-14773: Remove support for legacy and risky HTTP headers",
               "link":"https://symfony.com/blog/cve-2018-14773-remove-support-for-legacy-and-risky-http-headers",
               "cve":"CVE-2018-14773"
            }
         ]
      },
      "twig/twig":{  
         "version":"v1.23.1",
         "advisories":[  
            {  
               "title":"Sandbox Information Disclosure",
               "link":"https://symfony.com/blog/twig-sandbox-information-disclosure",
               "cve":""
            }
         ]
      },
      "zendframework/zend-diactoros":{  
         "version":"1.2.0",
         "advisories":[  
            {  
               "title":"URL Rewrite vulnerability",
               "link":"https://framework.zend.com/security/advisory/ZF2018-01",
               "cve":""
            }
         ]
      }
   }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Expected result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;______________________________________________
|   timestamp    |  vulnerable_dependencies  |
|  timestamp_1   |               6           |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example, there are 5 different projects scanned every day. Scan results are sent to splunk. I want to get a table, which shows the date of last scan and number of vulnerabilities in last scan for each project.&lt;/P&gt;

&lt;P&gt;I guess it can be something like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="http:vulns_scan" | stats last(_time), "query which give me vulnerabilities number" by project
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried to use this example: &lt;A href="https://answers.splunk.com/answers/735442/how-do-i-count-fields-inside-a-json-array.html"&gt;https://answers.splunk.com/answers/735442/how-do-i-count-fields-inside-a-json-array.html&lt;/A&gt;, but probably it works for arrays only. Could someone advise the search query, please?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 10:32:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459135#M191296</guid>
      <dc:creator>a_r1em</dc:creator>
      <dc:date>2019-08-22T10:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459136#M191297</link>
      <description>&lt;P&gt;didnt understand your expected output and also what you get when you apply an spath..can you clarify a bit more?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 10:50:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459136#M191297</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-08-22T10:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459137#M191298</link>
      <description>&lt;P&gt;where are you picking the timestamp from? if you pick _time and you are ingesting this api say once every hour, you will get ALL vulnerabilities at the same timestamp...there would be a reported/created field in this api against each vulnerability, you further want to group them by day or something like that? please clarify&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 10:59:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459137#M191298</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-08-22T10:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459138#M191299</link>
      <description>&lt;P&gt;For example, there are 5 different projects scanned every day. Scan results are sent to splunk. I want to get a table, which shows the date of last scan and number of vulnerabilities in last scan for each project.&lt;/P&gt;

&lt;P&gt;I guess it can be something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="http:vulns_scan" | stats last(_time), "query which give me vulnerabilities number" by project
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Aug 2019 11:56:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459138#M191299</guid>
      <dc:creator>a_r1em</dc:creator>
      <dc:date>2019-08-22T11:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459139#M191300</link>
      <description>&lt;P&gt;you are basically counting the cve , if a cve id exists you consider it to be a vulnerability.&lt;BR /&gt;
try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | rex field=_raw "\"+cve\"+\:+\"(?&amp;lt;cve&amp;gt;.*?)\"" max_match=0 
    | mvexpand cve
    | where len(cve)!=0
    | stats count(cve) by _time,source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As far as splitting by project goes you will have to determine what that field is..it has to be something unique to the 5 projects you mention - maybe source, sourcetype or something else&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 12:20:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459139#M191300</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-08-22T12:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459140#M191301</link>
      <description>&lt;P&gt;Thanks for your help, it is useful. I changed rex expression and have some results. &lt;/P&gt;

&lt;P&gt;The result table included time and cve number for all scans for each project. However, I need only the last result for each project.&lt;/P&gt;

&lt;P&gt;My data has uniqe field "project", which I can use to group results instead source.&lt;/P&gt;

&lt;P&gt;Your method to count cve looks interesting, however to count keys in json['vulnerabilities'] object more universal if it is possible at all.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:49:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459140#M191301</guid>
      <dc:creator>a_r1em</dc:creator>
      <dc:date>2019-08-22T13:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459141#M191302</link>
      <description>&lt;P&gt;hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/199975"&gt;@a_r1em&lt;/a&gt; &lt;BR /&gt;
It is possible of course but then you would not get a count of 6 as in your example. My suggestion is based on getting 6 vulnerabilities as in your expected output.&lt;BR /&gt;
We can write 5-6 regex(extract the url,version , title and so on..) or 1 single regex and fetch everything between say &lt;BR /&gt;
:{&lt;BR /&gt;&lt;BR /&gt;
       "paragonie/random_compat":{&lt;BR /&gt;&lt;BR /&gt;
          "version":"v1.4.3",&lt;BR /&gt;
          "advisories":[&lt;BR /&gt;&lt;BR /&gt;
             {&lt;BR /&gt;&lt;BR /&gt;
                "title":"Uses insecure CSPRNG (openssl_random_pseudo_bytes())",&lt;BR /&gt;
                "link":"&lt;A href="https://github.com/paragonie/random_compat/issues/96" target="_blank"&gt;https://github.com/paragonie/random_compat/issues/96&lt;/A&gt;",&lt;BR /&gt;
                "cve":""&lt;BR /&gt;
             }&lt;BR /&gt;
          ]&lt;BR /&gt;
this will give m 9 occurrences. it really depends on your use case&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:51:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459141#M191302</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2020-09-30T01:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to count a number of  keys in json object for each event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459142#M191303</link>
      <description>&lt;P&gt;hi @a_r1em &lt;BR /&gt;
 Any updates?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 18:51:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-number-of-keys-in-json-object-for-each-event/m-p/459142#M191303</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2019-08-23T18:51:37Z</dc:date>
    </item>
  </channel>
</rss>

