LoginSignup
1
0

More than 3 years have passed since last update.

Splunk 時刻(_time)をファイル名から取得するには

Posted at

データの中にタイムスタンプを持っていなかったり、出力時刻がファイル名に記載されている場合の対処法。
以前のSplunkVersionではdatetime.xmlを駆使する形だったけど、7.2以降は INGEST_EVAL が transforms.conf の中で使えるようになり、Eval関数で柔軟に定義できるようになってます。
まずベーシックな INGEST_EVAL の使い方は

transforms.conf
[eval_sample]
INGEST_EVAL = create_field = length_raw* 2
props.conf
[sample]
TRANSFORMS = eval_sample

上のように transforms.conf にフィールド(create_field)を作成して、取り込むデータの長さを2倍した値を代入 するような形をEvalでかけるので、それをprops.confから呼び出す。

これを使ってファイル名に埋め込まれた日付からtimeを取得
ファイル名 : PoC_test_2020-09-07T11-15-02
フォーマット : PoC_test
%Y-%m-%dT%H-%M-%S

transforms.conf
[eval_time]
INGEST_EVAL = _time=strptime(replace(source,".*(?=/)/",""),"PoC_test_%Y-%m-%dT%H-%M-%S")
props.conf
[date_from_filename]
TRANSFORMS = eval_time

以上です。

以下リファレンス
https://docs.splunk.com/Documentation/Splunk/8.0.6/Admin/Transformsconf
https://docs.splunk.com/Documentation/Splunk/latest/Data/IngestEval
https://community.splunk.com/t5/Getting-Data-In/How-do-you-extract-a-timestamp-from-a-filename/m-p/427089

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0