はじめに
splunkで作ったナレッジオブジェクトの権限をwebブラウザで一個ずつ確認するのが煩雑だなあと考えていた結果、restコマンドで一覧形式で確認することができるサーチコマンドを作ったので情報共有いたします。
ナレッジオブジェクトってなに
Splunk社公式ドキュメント(日本語版)によるとナレッジについて以下のように記述されています。
Splunk ソフトウェアはお客様の IT データ (イベント、フィールド、タイムスタンプなど) からさまざまな知識(ナレッジ) を抽出して、より理解、把握しやすく、有益な情報を導き出せるようにします。このような情報の⼀部は、Splunk ソフトウェアが IT データのインデックスを作成する時 (インデックス時) に抽出されます。しかし、この情報の⼤半は「サーチ時」に Splunk ソフトウェアとユーザーの両⽅により作成されます。あらかじめ抽出する情報を決めるまたは分析しておく、データベースまたはスキーマベースの分析ツールと違い、Splunk ソフトウェアでは raw データから必要に応じて動的にナレッジを抽出することができます。
Splunk ソフトウェアを使⽤すると、イベントタイプ、タグ、ルックアップ、フィールド抽出、ワークフローアクション、保存済みサーチなどの、さまざまな Splunk ソフトウェアナレッジオブジェクトが作成されていきます。
長くてちょっと何言ってるかわからないですね。
要は、サーチ時のフィールド抽出や、保存したサーチ、ダッシュボード、ルックアップなど「サーチ結果の分析を手助けするための各種設定≒ナレッジオブジェクト」と考えていただければと思います。
このナレッジオブジェクトはAppに予め設定されていたり、ユーザ自身の手で作ったりできます。
restコマンドってなに
splunkが提供しているrestエンドポイントを読み取るサーチコマンドです。
これだけだとまたちょっと何言ってるかわかんないですが、
今回はsplunkの各種設定を通常のサーチと同じような方法でサーチできるコマンドと考えてもらえればよいです。
ですので実行時は通常のサーチと同じようにサーチバーで以下のように入力します。
| rest <エンドポイントURL>
最低限エンドポイントだけ指定すれば実行できますが、オプションを指定することもできます。オプションについては公式ドキュメントを参考にしてみてください。
restコマンドを実行するための前提条件
-
restコマンドを実行するにはユーザに権限(rest_properties_get)が必要です。
※splunkデフォルトのロール(user,power,admin)にはこの権限が付与されています。 -
分散環境でサーチピアにrestコマンドを実行したい場合は権限dispatch_rest_to_indexersが必要です。
※splunkデフォルトではadminロールにのみ権限が付与されています。
restコマンドを使ったサーチ文例
ここで、例としてrestコマンドで"search"Appのルックアップテーブルファイルの権限を確認するサーチ文についてご紹介します。
| rest /servicesNS/-/-/data/lookup-table-files
| search eai:acl.app=search
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
※コマンドの仕様上、必ずサーチの先頭に入力します。また行頭の|は必須です。
restコマンド実行結果の主な表示項目について
restコマンドを実行すると、色んなフィールドを含んだ結果が返ってきます。
ここでは、権限を確認するために必要な項目についてご紹介します。
※公式ドキュメントに説明が見当たらなかったので、ID名,サーチ結果,splunkwebの内容から作っています。
(訂正)ここに書いてありました。
フィールドID | 説明 |
---|---|
eai:acl.app | ナレッジオブジェクトを持つApp |
title | ナレッジオブジェクト名 |
author | 作成者 |
eai:acl.owner | 所有者 |
eai:acl.sharing | 共有範囲※app,global,user |
eai:acl.perms.read | 読み取り可能ユーザ※ |
eai:acl.perms.write | 書き込み可能ユーザ※ |
eai:acl.can_change_perms | (ナレッジオブジェクトの)権限の編集が可能か |
eai:acl.can_list | リスト表示可能か |
eai:acl.can_share_app | App共有に設定可能か |
eai:acl.can_share_global | グローバル共有に設定可能か |
eai:acl.can_share_user | プライベート共有に設定可能か |
eai:acl.can_write | 書き込み可能か |
eai:acl.modifable | 変更可能か |
eai:acl.removable | 削除可能か |
※eai:acl.sharingがuser(プライベート)の場合nullになるようです
サーチ文サンプル
ここでは、よく使うと思われるナレッジオブジェクトの権限をrestコマンドを使って確認するサーチ文についてご紹介していきます。
※サーチ文2行目の<AppName>にはナレッジオブジェクトが保存されているApp名を指定します。
この行を省略すると、restを実行したユーザが参照可能なすべてのAppの情報を表示します。
カスタムフィールド(props)
| rest /servicesNS/-/-/data/props/fieldaliases
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
| rest /servicesNS/-/-/data/props/calcfields
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
| rest /servicesNS/-/-/data/props/extractions
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
カスタムフィールド(transforms)
| rest /servicesNS/-/-/data/transforms/extractions
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
ルックアップ
| rest /servicesNS/-/-/data/lookup-table-files
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
| rest /servicesNS/-/-/data/transforms/lookups
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
ダッシュボード
| rest /servicesNS/-/-/data/ui/views
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
アラート(保存済みサーチ)
| rest /servicesNS/-/-/saved/searches
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
アラートアクション
| rest /servicesNS/-/-/admin/alert_actions
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
マクロ
| rest /servicesNS/-/-/admin/macros
| search eai:acl.app=<AppName>
| table eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write,eai*
上記の確認を一気に行う
ここまでご紹介したサーチを一気に行うサーチです。
| makeresults
| append
[| rest /servicesNS/-/-/data/props/fieldaliases
| eval type="field-aliases"]
| append
[| rest /servicesNS/-/-/data/props/calcfields
| eval type="field-calcfields"]
| append
[| rest /servicesNS/-/-/data/props/extractions
| eval type="field-extractions-props"]
| append
[| rest /servicesNS/-/-/data/transforms/extractions
| eval type="field-extractions-transforms"]
| append
[| rest /servicesNS/-/-/data/lookup-table-files
| eval type="lookup-table-files"]
| append
[| rest /servicesNS/-/-/data/transforms/lookups
| eval type="lookups"]
| append
[| rest /servicesNS/-/-/data/ui/views
| eval type="dashboard"]
| append
[| rest /servicesNS/-/-/saved/searches
| eval type="savedsearches" ]
| append
[| rest /servicesNS/-/-/admin/alert_actions
| eval type="alert_actions"]
| append
[| rest /servicesNS/-/-/admin/macros
| eval type="macros"]
| search eai:acl.app=<AppName>
| table type,eai:acl.app,title,author,eai:acl.owner,eai:acl.sharing,eai:acl.perms.read,eai:acl.perms.write
おまけ(ロールの設定を色々確認する)
restコマンドを使うと、splunk webの設定画面をみなくとも各種設定が確認できます。
ここでは、ナレッジオブジェクトではないロールのデフォルトAppや参照可能インデックスといった
設定を確認するサーチコマンドについてご紹介します。
| rest /services/authorization/roles
| table title,defaultApp,imported_roles,srchIndexesAllowed,imported_capabilities,eai:acl.owner,author,*
おわりに
今回はナレッジオブジェクトの中でも私が比較的よく使っているものを代表してご紹介しました。
他のナレッジオブジェクトの権限についてもendpointを変更することで取得できると思いますので
ご紹介したサーチコマンドを参考に色々試してみてください。
参考文献
-
restコマンドに関するsplunk社のドキュメント
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rest -
ナレッジオブジェクトに関するsplunk社のドキュメント
http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/WhatisSplunkknowledge -
ナレッジオブジェクトのREST endpointに関するsplunk社のドキュメント
http://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTknowledge -
ナレッジオブジェクトのアクセス権限に関するSplunk社の開発ドキュメント
http://dev.splunk.com/view/webframework-developapps/SP-CAAAE88