<?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 use rex to extract JSON text in &amp;quot;ip&amp;quot; keyValue pair? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583013#M203016</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I am trying to see how I can extract the ip whenever it is after the text: "Source device","values":[{"ip":&lt;/P&gt;&lt;P&gt;Log:&lt;BR /&gt;{"type":"device","key":"Source device","values":[{"ip":"10.10.10.10","mac"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try the following statement but it didn't work:&lt;/P&gt;&lt;P&gt;| rex field=_raw ".*,\"Source device\",\"values\":"\[\{\"ip\":"(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\",\"mac\""&lt;/P&gt;&lt;P&gt;"Source device\",\"values\":"\[\{\"ip\": | rex field=_raw "(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"&lt;/P&gt;&lt;P&gt;| rex field=_raw "Source device,value:\S{\w+:(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"&lt;/P&gt;</description>
    <pubDate>Sat, 29 Jan 2022 07:35:54 GMT</pubDate>
    <dc:creator>Raymundo</dc:creator>
    <dc:date>2022-01-29T07:35:54Z</dc:date>
    <item>
      <title>How to use rex to extract JSON text in "ip" keyValue pair?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583011#M203014</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a json raw string from which I have to extract the&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Source&lt;/SPAN&gt; &lt;SPAN class=""&gt;device&lt;/SPAN&gt;","&lt;SPAN class=""&gt;values&lt;/SPAN&gt;"&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;[{"&lt;SPAN class=""&gt;ip&lt;/SPAN&gt;"&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; key and pair value. Can you please assist. The log line looks like below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Source&lt;/SPAN&gt; &lt;SPAN class=""&gt;device&lt;/SPAN&gt;","&lt;SPAN class=""&gt;values&lt;/SPAN&gt;"&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;[{"&lt;SPAN class=""&gt;ip&lt;/SPAN&gt;"&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;10.10.10.10&lt;/SPAN&gt;&lt;SPAN&gt;","&lt;/SPAN&gt;&lt;SPAN class=""&gt;mac&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;I want to extract&amp;nbsp;the ip address:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;10.10.10.10&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 06:55:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583011#M203014</guid>
      <dc:creator>Raymundo</dc:creator>
      <dc:date>2022-01-29T06:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex to extract JSON text in "ip" keyValue pair?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583012#M203015</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/242526"&gt;@Raymundo&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you have two ways:&lt;/P&gt;&lt;P&gt;you can use the spath command (&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath&lt;/A&gt;),&lt;/P&gt;&lt;P&gt;or a regex like the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "\"ip\":\"(?&amp;lt;ip&amp;gt;\d+\.\d+\.\d+\.\d+)\""&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 07:04:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583012#M203015</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-01-29T07:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex to extract JSON text in "ip" keyValue pair?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583013#M203016</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I am trying to see how I can extract the ip whenever it is after the text: "Source device","values":[{"ip":&lt;/P&gt;&lt;P&gt;Log:&lt;BR /&gt;{"type":"device","key":"Source device","values":[{"ip":"10.10.10.10","mac"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try the following statement but it didn't work:&lt;/P&gt;&lt;P&gt;| rex field=_raw ".*,\"Source device\",\"values\":"\[\{\"ip\":"(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\",\"mac\""&lt;/P&gt;&lt;P&gt;"Source device\",\"values\":"\[\{\"ip\": | rex field=_raw "(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"&lt;/P&gt;&lt;P&gt;| rex field=_raw "Source device,value:\S{\w+:(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 07:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583013#M203016</guid>
      <dc:creator>Raymundo</dc:creator>
      <dc:date>2022-01-29T07:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex to extract JSON text in "ip" keyValue pair?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583014#M203017</link>
      <description>&lt;LI-CODE lang="markup"&gt;| rex field=_raw ".*,\"Source device\",\"values\":\[\{\"ip\":\"(?&amp;lt;src_ip2&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\",\"mac\""&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 29 Jan 2022 08:01:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583014#M203017</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-29T08:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex to extract JSON text in "ip" keyValue pair?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583018#M203020</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/242526"&gt;@Raymundo&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you can try my previous regex, but if you have more ips in your logs, you could use this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "\{\"type\":\"device\",\"key\":\"Source device\",\"values\":\[{\"ip\":\"(?&amp;lt;ip&amp;gt;\d+\.\d+\.\d+\.\d+)\",\"mac\""&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/fiCXZP/1" target="_blank"&gt;https://regex101.com/r/fiCXZP/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 06:42:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583018#M203020</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-01-30T06:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use rex to extract JSON text in "ip" keyValue pair?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583021#M203021</link>
      <description>&lt;P&gt;If the source is conforming JSON, you shouldn't need to use regex to extract such data. &amp;nbsp;If the above is how a fully line looks like, the full JSON message is perhaps something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{...,"somekey":
"Source device","values":[{"ip":"10.10.10.10","mac"
:"12:34:56:78:9a:bc"},...],...}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But no matter how the full JSON message is broken up in multiple lines,&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;should be able to handle it. &amp;nbsp;Using a build-in command/function to extract structured data is much more robust. &amp;nbsp;So, I recommend to focus on getting the full JSON message. &amp;nbsp;Assuming the JSON message is in jsonfield, the following will catch the source device&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=jsonfield
| where somekey == "Source device"
| rename values{}.* AS source_*&lt;/LI-CODE&gt;&lt;P&gt;The source IP address, for example, will be in source_ip field.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 08:21:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-rex-to-extract-JSON-text-in-quot-ip-quot-keyValue/m-p/583021#M203021</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-01-30T08:21:22Z</dc:date>
    </item>
  </channel>
</rss>

