{"id":70447,"date":"2023-02-06T16:23:51","date_gmt":"2023-02-06T16:23:51","guid":{"rendered":"https:\/\/merikebi.warrenmyers.com\/?p=70447"},"modified":"2023-02-06T16:23:51","modified_gmt":"2023-02-06T16:23:51","slug":"answer-by-warren-for-extracting-a-count-from-raw-splunk-data-by-id","status":"publish","type":"post","link":"https:\/\/merikebi.warrenmyers.com\/?p=70447","title":{"rendered":"Answer by warren for Extracting a count from raw splunk data by id"},"content":{"rendered":"<p>Presuming the pin status and ID have not been extracted:<\/p>\n<pre><code>index=ndx sourcetype=srctp &quot;pin&quot; &quot;match&quot; OR &quot;mismatched&quot;\n| rex field=_raw &quot;pin (?&lt;pin_status&gt;\\w+)&quot;\n| rex field=_raw &quot;id (?&lt;id&gt;\\S+)&quot;\n| eval status_time=pin_status+&quot;|&quot;+_time\n| stats earliest(status_time) as beginning latest(status_time) as ending by id\n| eval beginning=split(beginning,&quot;|&quot;), ending=split(ending,&quot;|&quot;)\n| eval begining=mvindex(beginning,-1), ending=mvindex(ending,-1)\n| table id beginning ending\n| sort 0 id\n| eval beginning=strftime(beginning,&quot;%c&quot;), ending=strftime(ending,&quot;%c&quot;)\n<\/code><\/pre>\n<p>After extracting the status (&quot;match&quot; or &quot;mismatched&quot;) and the id, append the individual event&#8217;s <code>_time<\/code> to the end of the status &#8211; we&#8217;ll pull that value back out after <code>stats<\/code>ing<\/p>\n<p>Using <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/stats\" rel=\"nofollow noreferrer\"><code>stats<\/code><\/a>, find the earliest and latest <code>status_time<\/code> entries (fields just created on the previous line) by <code>id<\/code>, saving them into new fields <code>beginning<\/code> and <code>ending<\/code><\/p>\n<p>Next, <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/eval\" rel=\"nofollow noreferrer\"><code>split()<\/code><\/a> <code>beginning<\/code> and <code>ending<\/code> on the pipe we added to separate the status from the timestamp into a <a href=\"https:\/\/docs.splunk.com\/Splexicon:Multivaluefield\" rel=\"nofollow noreferrer\">multivalue field<\/a><\/p>\n<p>Then assign the last item from the multivalue field (which we know is the timestamp) into itself (because we know that the earliest entry for a <code>status_time<\/code> should always be &quot;match&quot;, and the latest entry for a <code>status_time<\/code> should always be &quot;mismatched&quot;)<\/p>\n<p>Lastly, <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/table\" rel=\"nofollow noreferrer\"><code>table<\/code><\/a> the id and time stamps, <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/sort\" rel=\"nofollow noreferrer\">sort<\/a> by id, and format the timestamp into something human readable (<a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/DateandTimeFunctions#strftime.28X.2CY.29\" rel=\"nofollow noreferrer\"><code>strftime<\/code><\/a> takes many <a href=\"https:\/\/strftime.org\" rel=\"nofollow noreferrer\">arguments<\/a>, <code>%c<\/code> just happens to be quick)<\/p>\n<p>from User warren &#8211; Stack Overflow https:\/\/stackoverflow.com\/questions\/75356345\/extracting-a-count-from-raw-splunk-data-by-id\/75363877#75363877<br \/>\nvia <a href=\"https:\/\/ifttt.com\/?ref=da&#038;site=wordpress\">IFTTT<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Presuming the pin status and ID have not been extracted: index=ndx sourcetype=srctp &quot;pin&quot; &quot;match&quot; OR &quot;mismatched&quot; | rex field=_raw &quot;pin (?&lt;pin_status&gt;\\w+)&quot; | rex field=_raw &quot;id (?&lt;id&gt;\\S+)&quot; | eval status_time=pin_status+&quot;|&quot;+_time | stats earliest(status_time) as beginning latest(status_time) as ending by id | eval beginning=split(beginning,&quot;|&quot;), ending=split(ending,&quot;|&quot;) | eval begining=mvindex(beginning,-1), ending=mvindex(ending,-1) | table id beginning ending | sort 0 &hellip;<br \/><a href=\"https:\/\/merikebi.warrenmyers.com\/?p=70447\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">Answer by warren for Extracting a count from raw splunk data by id<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[991],"keyring_services":[],"class_list":["post-70447","post","type-post","status-publish","format-standard","hentry","category-blih","tag-stackexchange"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/70447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70447"}],"version-history":[{"count":1,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/70447\/revisions"}],"predecessor-version":[{"id":70448,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/70447\/revisions\/70448"}],"wp:attachment":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70447"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fkeyring_services&post=70447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}