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
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...