Splunk Search

検索結果の指定フィールド列で別ソースタイプを検索し結果を右列に追加する方法について

mozukun3
New Member

お世話になります。

サーチ文の書き方についてご教示ください。

まず、以下の検索結果を出しています。
・サーチ文
「soucetype="test1" | table host, user, state」
・サーチ結果
------
host, user, state
H001, U001, 000
H002, U002, 001
H003, U003, 002
H004, U004, 002
H005, U005, 002
------

この時、userフィールドのそれぞれの値で、
sourcetype "test2"のUSERフィールドが一致するログを検索し、
最も新しいログのactionフィールドを上記ログの右列に追記したいです。

例えば、sourcetype "test2"でUSERフィールドがU001のログが10件あり、
それぞれのActionが1~10のどれかが記載されていて、最も新しいログの
Actionが5だった場合、最初に記載したサーチ結果の1列目の右列に5が追記される。
という動作です。

0 Karma
1 Solution

to4kawa
Ultra Champion
sourcetype=test1 OR sourcetype=test2
|stats values(host) as host values(state) as state latest(action) as action by user
|table host, user, state, action

これでいかがですか?
最後のtableは列の順番がアルファベット順になる可能性があったため、つけました。

Splunkは一気に検索して、stats等でまとめた方がいいです。

sourcetype="test1" | table host, user, state
|join user [search sourcetype="test2"
|stats latest(action) as action by user]

のように考えたと思いますが、これはかなり遅い検索になります。

View solution in original post

0 Karma

to4kawa
Ultra Champion
sourcetype=test1 OR sourcetype=test2
|stats values(host) as host values(state) as state latest(action) as action by user
|table host, user, state, action

これでいかがですか?
最後のtableは列の順番がアルファベット順になる可能性があったため、つけました。

Splunkは一気に検索して、stats等でまとめた方がいいです。

sourcetype="test1" | table host, user, state
|join user [search sourcetype="test2"
|stats latest(action) as action by user]

のように考えたと思いますが、これはかなり遅い検索になります。

0 Karma

mozukun3
New Member

回答いただきありがとうございます。
こちらはフィールド名が同一でないとだめなのでしょうか。

実際には、test1のフィールド名はuserなのですが、test2のフィールドはUserで、大文字が入るためフィールド名が同一ではなく。
この場合の手段もご教示いただけませんでしょうか。
たびたびすみませんがお願いします。

0 Karma

to4kawa
Ultra Champion

こちらはフィールド名が同一でないとだめなのでしょうか。

はい、その通りです。
違う場合はrename User as user等フィールド名を変更する必要があります。

sourcetype=test1 OR sourcetype=test2
|eval user=coalesce(user,User) 
|stats values(host) as host values(state) as state latest(action) as action by user
|table host, user, state, action

でいかがですか?
coalesceはイベントによって違うフィールド名を同じものにします。

0 Karma

mozukun3
New Member

できました!!
実例も書いていただいて分かりやすく大変たすかりました。
ありがとうございました。

0 Karma

to4kawa
Ultra Champion

どういたしまして。またなにかありましたら。Happy Splunk.

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 ...