Getting Data In

インデックス時にファイル名から時刻を取得する方法

yagi1234
New Member

ログファイル内に日付、時刻がなく、ファイル名に日付がある場合に、ファイル名の日付を_timeとして認識させることは可能でしょうか?
タイムレンジピッカーによる日付範囲指定を行いたいので、index-timeに_timeに値を設定したいと考えています。
※search-timeだとタイムレンジピッカーによる絞り込みが行えないため

・ログファイル名:ABC_20170203.csv
・期待する結果:
 _time=2017/02/03 00:00:00

0 Karma

felipesewaybric
Contributor

このファイルを編集することができます:datetime.xml
You can edit the file: datetime.xml

 <datetime>
 <define name="datefromfile" extract="year, month, day">
    <text><![CDATA[source::.*?_(\d{4})(\d{2})(\d{2}]]></text>
 </define>
 <define name="timefromfile" extract="hour, second">
    <text><![CDATA[source::.*?_\d{8}(\d{2})(\d{2}]]></text>
 </define>
 <timePatterns>
    <use name="timefromfile"/>
 </timePatterns>
 <datePatterns>
    <use name="datefromfile"/>
 </datePatterns>
 </datetime>
0 Karma

yagi1234
New Member

回答ありがとうございます。
以下条件で確認しましたが、うまく動作しません 。

※ファイル名を「ABC_20170105101501.csv」とし、ファイル名に年月日時分秒を設定しました。

datetime.xml

<datetime>
<define name="datefromfile" extract="year, month, day">
   <text><![CDATA[source::.*?_(\d{4})(\d{2})(\d{2})]]></text>
</define>
<define name="timefromfile" extract="hour, minute, second">
   <text><![CDATA[source::.*?_\d{8}(\d{2})(\d{2})(\d{2})]]></text>
</define>
<timePatterns>
   <use name="timefromfile"/>
</timePatterns>
<datePatterns>
   <use name="datefromfile"/>
</datePatterns>
</datetime>

props.conf
[samplecsv]

DATETIME_CONFIG = /etc/system/local/datetime.xml

ABC_20170105101501.csv

column1,column2,column3
a,b,c
d,e,f

結果
alt text

以上、よろしくお願いいたします。

0 Karma

felipesewaybric
Contributor

お役に立てて嬉しいです

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...