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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...