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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...