{"id":61002,"date":"2022-07-26T17:27:12","date_gmt":"2022-07-26T17:27:12","guid":{"rendered":"https:\/\/merikebi.warrenmyers.com\/?p=61002"},"modified":"2022-07-26T17:27:12","modified_gmt":"2022-07-26T17:27:12","slug":"answer-by-warren-for-splunk-search-query","status":"publish","type":"post","link":"https:\/\/merikebi.warrenmyers.com\/?p=61002","title":{"rendered":"Answer by warren for Splunk search query"},"content":{"rendered":"<p>If you&#8217;d like a <em>full<\/em> regex for extracting all of the bracketed fields, this is the <a href=\"https:\/\/regex101.com\/r\/R7vfay\/1\" rel=\"nofollow noreferrer\">most efficient<\/a> one-shot I could make:<\/p>\n<pre><code>| rex field=_raw &quot;(?&lt;extid&gt;[\\d\\.]+).+D\\[(?&lt;fieldtype&gt;[^\\]]+).+T\\[(?&lt;format&gt;[^\\]]+).+L\\[(?&lt;ll&gt;[^\\]]+).+N\\[(?&lt;len&gt;[^\\]]+).+E\\[(?&lt;type&gt;[^\\]]+).+S\\[(?&lt;charset&gt;[^\\[]+).+A\\[(?&lt;data&gt;[^\\]]+)&quot;\n<\/code><\/pre>\n<p>Most often I do sequential <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/rex\" rel=\"nofollow noreferrer\"><code>rex<\/code><\/a> calls, just in case some fields aren&#8217;t present in all events, but your sample data shows each of these items present<\/p>\n<p>Once you&#8217;ve extracted <em>every<\/em> field in the data, you can <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/stats\" rel=\"nofollow noreferrer\"><code>stats<\/code><\/a> or <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/search\" rel=\"nofollow noreferrer\"><code>search<\/code><\/a> it any way you may like (I see some of your &quot;<code>FLD<\/code>&quot; (which I&#8217;ve named &quot;<code>fieldtype<\/code>&quot;) values can have spaces or punctuation, so I&#8217;m using the wildcard <code>search<\/code> feature to match anything that looks like &quot;Response Code&quot;):<\/p>\n<pre><code>index=ndx sourcetype=srctp \n| rex field=_raw &quot;(?&lt;extid&gt;[\\d\\.]+).+D\\[(?&lt;fieldtype&gt;[^\\]]+).+T\\[(?&lt;format&gt;[^\\]]+).+L\\[(?&lt;ll&gt;[^\\]]+).+N\\[(?&lt;len&gt;[^\\]]+).+E\\[(?&lt;type&gt;[^\\]]+).+S\\[(?&lt;charset&gt;[^\\[]+).+A\\[(?&lt;data&gt;[^\\]]+)&quot;\n| search fieldtype=&quot;Response*&quot; \n| stats count by extid data fieldtype\n| fields - count\n| where tonumber(data)&gt;5\n<\/code><\/pre>\n<p><a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/latest\/SearchReference\/ConversionFunctions#tonumber.28NUMSTR.2CBASE.29\" rel=\"nofollow noreferrer\"><code>tonumber<\/code><\/a> is quite flexible; I&#8217;m using it here in its simplest form<\/p>\n<p>from User warren &#8211; Stack Overflow https:\/\/stackoverflow.com\/questions\/71194954\/splunk-search-query\/73127433#73127433<br \/>\nvia <a href=\"https:\/\/ifttt.com\/?ref=da&#038;site=wordpress\">IFTTT<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;d like a full regex for extracting all of the bracketed fields, this is the most efficient one-shot I could make: | rex field=_raw &quot;(?&lt;extid&gt;[\\d\\.]+).+D\\[(?&lt;fieldtype&gt;[^\\]]+).+T\\[(?&lt;format&gt;[^\\]]+).+L\\[(?&lt;ll&gt;[^\\]]+).+N\\[(?&lt;len&gt;[^\\]]+).+E\\[(?&lt;type&gt;[^\\]]+).+S\\[(?&lt;charset&gt;[^\\[]+).+A\\[(?&lt;data&gt;[^\\]]+)&quot; Most often I do sequential rex calls, just in case some fields aren&#8217;t present in all events, but your sample data shows each of these items present Once you&#8217;ve &hellip;<br \/><a href=\"https:\/\/merikebi.warrenmyers.com\/?p=61002\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">Answer by warren for Splunk search query<\/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-61002","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\/61002","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=61002"}],"version-history":[{"count":1,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/61002\/revisions"}],"predecessor-version":[{"id":61003,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=\/wp\/v2\/posts\/61002\/revisions\/61003"}],"wp:attachment":[{"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=61002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=61002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=61002"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/merikebi.warrenmyers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fkeyring_services&post=61002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}