Getting Data In

How to get props and transforms to extract time from source?

power12
Communicator

Hello Splunkers ,

 

I have the following source file which has the date/time in it .. How do I write the props and transforms to use the source date/time as the _time

 

Below is the sample file

/project/admin/sv/re/sniff/pre/logs/2022-12-16T11-57-36/status 

i want the _time or indexed time to be 2022-12-16 11-57-36.

 

Thanks in Advance 

Labels (2)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

Another way is use to INGEST_EVAL. I cannot say which one is more efficient.

Add props.conf

[<source or sourcetype name>]
TRANSFORMS-set_time = set_time_from_file_path

transforms.conf

[set_time_from_file_path]
INGEST_EVAL = _time = strptime(replace(source, ".*(\d{4}-\d\d-\d\dT\d\d-\d\d-\d\d)/status","\1"),"%Y-%m-%dT%H-%M-%S")

 You also need to check TZ information should you add it here or not?  Definitely needs if you have source systems on different timezones and/or source systems and indexers / HFs are on different TZ.

r. Ismo

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @power12,

you have to configure datetime_config.xml and point to it in props.conf:

props.conf:

[your_sourcetype]
DATETIME_CONFIG = /opt/splunk/etc/apps/your_app/local/datetime.xml

in datetime_config.xml:

<datetime>

<define name="_timeAndDateFromFilename" extract="year, month, day, hour, minute, second">
        <text><![CDATA[source::\/project\/admin\/sv\/re\/sniff\/pre\/logs\/?(\d{4})-(\d{2})-(\d{2}T(\d{2})-(\d{2})-(\d{2})]]></text>
</define>

<timePatterns>
        <use name="_timeAndDateFromFilename"/>
</timePatterns>

</datetime>

As described at https://docs.splunk.com/Documentation/Splunk/9.0.4/Data/Configuredatetimexml#Examples_of_custom_date... 

Ciao.

Giuseppe

 

0 Karma

power12
Communicator

@gcusello  Thank you for your message...do you think there is a ) missing before the T

(\d{4})-(\d{2})-(\d{2}T(\d{2})-(\d{2})-(\d{2})
(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2})

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @power12,

yes, correct, sorry!

Ciao.

Giuseppe

gcusello
SplunkTrust
SplunkTrust

hi @power12 ,

good for you, see next time!

Please accept one answer for the other people of Community

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

How to find the worst searches in your Splunk environment and how to fix them

Everyone knows Splunk is a powerful platform for running searches and doing data analytics. Your ...

Share Your Feedback: On Admin Config Service (ACS)!

Help Us Build a Better Admin Config Service Experience (ACS)   We Want Your Feedback on Admin Config Service ...

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...