Getting Data In

props.confとtransforms.confを使用したデータ取り込み時のフィルタの方法について

t_kubota
New Member

・背景
データ取り込み時に特定のイベントのみ抽出したいとき、props.confとtransforms.confに以下のような設定で実現できるかと思います。
例として、項目statusの値がerrorのイベントのみ抽出したい場合を想定します。

■props.conf

[sourcetype_A]
TRANSFORMS-FILTER=null,set1

■transforms.conf

[null]
REGEX = .
DEST_KEY = queue
FORMAT = nullQueue

[set1]

REGEX = status=error
DEST_KEY = queue
FORMAT = indexQueue

webアクセスログのように、ログの各行に「status=error」の文字列が含まれる形式であれば上記の方法で問題ないのですが、ログのフォーマットがCSVやスペース区切りのように、ヘッダ行に項目名が並びその下の各行に値が表示される形式であれば、「status=error」という文字列の並びは存在しないので以下のように値の部分のみ指定することになるかと思います。

[set1]

REGEX = error
DEST_KEY = queue
FORMAT = indexQueue

・課題
上の方法では、項目status以外にもerrorという文字列を含んでいる行についてもデータ取り込み対象となってしまい、本来の意図である「項目statusの値がerrorのイベントのみ抽出したい」よりも余計なデータを取り込んでしまう。

・質問
CSVやスペース区切りのようなログフォーマットについて、transforms.conf内で項目名と値を明記して取り込み対象を指定する表現は、どのようにすれば実現できるでしょうか?

0 Karma

t_kubota
New Member

すみません、その後自己解決したので共有させて頂きます。
アプローチを変え、項目に対して値を指定するのではなく、行全体を直接正規表現で表現し、左から何番目の項目に「error」があるか、という考え方で解決しました。

具体的には、以下のイメージです。
(ログフォーマットとしてdate,time,address,status,codeの例)

[set1]
REGEX = ^(?:\d{4}-\d{2}-\d{2})\s+(?:\d{2}:\d{2}:\d{2})\s+(?:\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s+(?:error)\s+(?:\w*)\s*$
DEST_KEY = queue
FORMAT = indexQueue

0 Karma

vinod94
Contributor

Hi @t_kubota ,

サンプルイベントをいくつか教えていただけますか?

0 Karma

t_kubota
New Member

コメントありがとうございます。

サンプルイベントですが、簡単なもので以下のログで再現できます。

(スペース区切りのログを想定、ソースタイプはスペース区切りで項目が識別できればなんでもよいです)

date time adderess status code
2019-01-19 17:00:01 10.1.1.1 information OK
2019-01-19 17:00:02 10.1.1.1 warning error

2019-01-19 17:00:03 10.1.1.1 error error

上の例で、3行目のみを取り込み対象とできることがゴールです。

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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