<?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 Extract fields fomr Python Dictionary text file in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Extract-fields-fomr-Python-Dictionary-text-file/m-p/108292#M1605</link>
    <description>&lt;P&gt;How do I create an extract that handles variable numbers of fields.&lt;/P&gt;

&lt;P&gt;I am generating events that are time stamped Python dictionaries. The list of items are emitted to the event using Python logging where everything in curly brackets was from a single Python dictionary.  The dictionary is rendered using built-in rend(d) where d is a dict. The list of items in the {} brackets are variable, and the order of items is arbitrary.&lt;/P&gt;

&lt;P&gt;2013/07/18 19:51:00.090 UTC [DssSplunkHostAgent] INFO: {'rtime': 31556.303133832, 'ABI': 32, 'egid': 20000, 'uid': 101, 'mrcv': 0, 'pctcpu': 0.0, 'pctmem': 0.5523681640625, 'args': 'python -W ignore::DeprecationWarning -m DssCore', 'pid': 9452, 'Taskname': 'DssCore', 'start': datetime.datetime(2013, 7, 18, 11, 5, 5, 785854), 'gid': 20000, 'euid': 101, 'fname': 'python', 'time': 1.244510313, 'oublk': 0, 'dmodel': 1, 'inblk': 0, 'ppid': 9289, 'msnd': 0, 'ctime': 256.16}&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2013 22:52:13 GMT</pubDate>
    <dc:creator>Claw</dc:creator>
    <dc:date>2013-07-26T22:52:13Z</dc:date>
    <item>
      <title>Extract fields fomr Python Dictionary text file</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Extract-fields-fomr-Python-Dictionary-text-file/m-p/108292#M1605</link>
      <description>&lt;P&gt;How do I create an extract that handles variable numbers of fields.&lt;/P&gt;

&lt;P&gt;I am generating events that are time stamped Python dictionaries. The list of items are emitted to the event using Python logging where everything in curly brackets was from a single Python dictionary.  The dictionary is rendered using built-in rend(d) where d is a dict. The list of items in the {} brackets are variable, and the order of items is arbitrary.&lt;/P&gt;

&lt;P&gt;2013/07/18 19:51:00.090 UTC [DssSplunkHostAgent] INFO: {'rtime': 31556.303133832, 'ABI': 32, 'egid': 20000, 'uid': 101, 'mrcv': 0, 'pctcpu': 0.0, 'pctmem': 0.5523681640625, 'args': 'python -W ignore::DeprecationWarning -m DssCore', 'pid': 9452, 'Taskname': 'DssCore', 'start': datetime.datetime(2013, 7, 18, 11, 5, 5, 785854), 'gid': 20000, 'euid': 101, 'fname': 'python', 'time': 1.244510313, 'oublk': 0, 'dmodel': 1, 'inblk': 0, 'ppid': 9289, 'msnd': 0, 'ctime': 256.16}&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2013 22:52:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Extract-fields-fomr-Python-Dictionary-text-file/m-p/108292#M1605</guid>
      <dc:creator>Claw</dc:creator>
      <dc:date>2013-07-26T22:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract fields fomr Python Dictionary text file</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Extract-fields-fomr-Python-Dictionary-text-file/m-p/108293#M1606</link>
      <description>&lt;P&gt;Here is a very clean answer. It assumes that the sourcetype is called python dictionary. Change this to meet your needs.&lt;/P&gt;

&lt;P&gt;The oddball issue here is the "start" field so we set up automated extractions for every thing else using DELIMS and handle the exceptions with regular extracts.&lt;/P&gt;

&lt;P&gt;Props.conf&lt;/P&gt;

&lt;P&gt;[pythondictionary]&lt;BR /&gt;
EXTRACT-PD_MessageLevel = (?i)[.&lt;EM&gt;?] (?P&lt;PD_MESSAGELEVEL&gt;\w+)(?=:)&lt;BR /&gt;
EXTRACT-PD_Agent = (?i)^[^[]&lt;/PD_MESSAGELEVEL&gt;&lt;/EM&gt;[(?P&lt;PD_AGENT&gt;[^]]+)&lt;BR /&gt;
REPORT-pythondictionary = PD-Extract&lt;BR /&gt;
EXTRACT-PD_Message = {(?P&lt;PD_MESSAGE&gt;.+)(?=})&lt;BR /&gt;
EXTRACT-start = \'start\':\s(?&lt;START&gt;.*?),\s\'&lt;/START&gt;&lt;/PD_MESSAGE&gt;&lt;/PD_AGENT&gt;&lt;/P&gt;

&lt;P&gt;Transforms.conf&lt;/P&gt;

&lt;P&gt;[PD-Extract]&lt;BR /&gt;
SOURCE_KEY = PD_Message&lt;BR /&gt;
DELIMS = ",", ":"&lt;/P&gt;

&lt;P&gt;Kudos for this solution goes to Dritan Bitincka in Splunk ps.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:26:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Extract-fields-fomr-Python-Dictionary-text-file/m-p/108293#M1606</guid>
      <dc:creator>Claw</dc:creator>
      <dc:date>2020-09-28T14:26:41Z</dc:date>
    </item>
  </channel>
</rss>

