2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Splunkのreturnの結果がない時、結果なしとする。

Last updated at Posted at 2019-08-26

概要

サブサーチ結果をreturnで返す時、検索結果がない場合メインサーチは引数なしで検索してしまう。
それを防止する方法。

結論

SPL
return あなたのサブサーチ結果フィールド名等
where search!=""
] `comment(“サブサーチの閉じかっこ”)` 

解説

isnotnullが使えるかと思ったら、使えなかったので。

returnについてはSplunkサブサーチで検索期間を変化させるを参照

ちょっと調べてみるとevalwhereも)の評価で
isnull:そのフィールドがない場合
=="":フィールドはあるけど値が入っていない場合
みたい。

Splunkチュートリアルのデータで確かめられる。

SPL
source="access_30DAY.log"
| where isnull(action)

なのでその逆、サブサーチ検索結果がある時のみメインサーチが動くようにしている。

:sweat: 画像がない・・・・

結果がない時メッセージを表示する

結果なし
...
| appendpipe [|stats count
| eval message="There is no result"
| where count = 0 | table message ]

appendpipeでこのように作ってあげると、メインサーチの結果がない場合、メッセージを表示してくれる。

意外のニーズはある。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?