4
4

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のSDKで自分で定義したfieldを使うためのメモ

Posted at

概要

splunkのruby sdkを使ったツールを作っているんだけど、ドキュメントがわかりづらすぎて、ハマったので、その設定のメモ。

stmt = "search sourcetype=ssl_access_log-too_small source=*confluence* earliest=-1d@d latest=@d | head 10"
stream = service.create_oneshot(stmt, :output_mode=>"json")

上記のような検索をsdkで投げると、きちんとレスポンスが返ってくるが、

stmt = "search sourcetype=ssl_access_log-too_small source=*confluence* latency>1000 earliest=-1d@d latest=@d | head 10"

このようにlatency>1000というのを加えるとレスポンスが帰ってくなくなっていた。ちなみにweb interfaceから検索すると普通に検索が返ってくる。

試行錯誤

最初は正規表現周りかと思って、いろいろと調査していたのだが、全然わからなかった。やればやるほどわからなくなっていった。

web interfaceから投げているときに、たまに返ってこないことを発見する。どうやらappの指定をしていないときに返ってきていないらしい。そこで、latencyというfieldは自分で指定したfieldだと思いだした。

Splunk SDK fields - Splunk Community

このへんに載っている、permissionの変更などを試してみたが、効果はなかった。

namespace

半日ほど試行錯誤した結果、appを指定するためにnamespaceというのを指定する必要があるらしいことがわかった。

Overview | Splunk SDK for Ruby

appの名前とusernameの組み合わせという断片的な情報はいろんなページにあるが、肝心の指定方法は以下にしか書いてなかった(かなり探した)

How to connect to Splunk | Splunk SDK for Ruby

ns = Splunk::namespace(:sharing => "app", :app => "testrubySS")
svc = Splunk::connect(:username => 'admin', :password => 'changed', :namespace => ns)

これをつかって、

ns = Splunk::namespace(:sharing => "app", :app => "myappname")
service = Splunk::Service.new(:host => "localhost",
                              :port => 8089,
                              :username => "username",
                              :password => "password",
                              :namespace => ns).login()

こういった感じに書くことで自分で定義したfieldも使うことができた。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?