0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Splunk】Splunk Add-on for Unix and Linuxの使い方をまとめる

Posted at

こんにちは。torippy1024です。
本日は、SplunkのApp/Add-onの中でも最も利用頻度が高い?(勝手な推測)と思われるAdd-onである、Splunk Add-on for Unix and Linux(通称、Splunk_TA_nix)について、改めて使い方をまとめます。

Splunk Add-on for Unix and Linuxとは

Splunk Add-on for Unix and Linux(Splunk_TA_nix)とは、splunkbaseで公開されているSplunkのAdd-onです。

その名の通り、Unix/Linux両方に対応しており、Unix/Linuxの基本的なログを取得するための入力モニター定義や入力スクリプトが入ったAdd-onです。

スクリーンショット 2025-11-02 0.07.37.png

以下よりダウンロードが可能です。

Splunk Add-on for Unix and Linux
https://splunkbase.splunk.com/app/833

ドキュメントは以下です。
https://splunk.github.io/splunk-add-on-for-unix-and-linux/

ちなみに、Splunk_TA_nixとは、add-onをダウンロードして解凍した際に作成されるフォルダ名(=Appを識別する名前)のことを指しています。

TAはTechnology Add-onの略らしいです。他にもSA(Supporting Add-on), DA(Domain Add-on)などもあるようですが、ここでは詳しく触れません。
https://dev.splunk.com/enterprise/docs/devtools/enterprisesecurity/abouttheessolution/

取得できる情報

Splunk_TA_nixによって取得できる情報はgithubに記載があります。
https://splunk.github.io/splunk-add-on-for-unix-and-linux/Sourcetypes/

ただ、上記を見ても、Splunk上でどのソースタイプとしてインデックス化されるかはわかるのですが、
Linux上でどういったインプットからそのソースタイプのデータを生成するかまでは書かれていません。
知りたい場合は、splunkbaseから実物のAdd-onをダウンロードし、中身の実装を確認する必要があります。
実際にダウンロードしたinputs.confを見ると、以下のようになっていました。
(以下はバージョン10.0.2の内容となります。)

データタイプ モニターパス/スクリプトパス ソースタイプ ソース スクリプト実行間隔(秒)
メトリクス ./bin/vmstat_metric.sh vmstat_metric vmstat 60
メトリクス ./bin/iostat_metric.sh iostat_metric iostat 60
メトリクス ./bin/ps_metric.sh ps_metric ps 30
メトリクス ./bin/df_metric.sh df_metric df 300
メトリクス ./bin/interfaces_metric.sh interfaces_metric interfaces 60
メトリクス ./bin/cpu_metric.sh cpu_metric cpu 30
イベント ./bin/vmstat.sh vmstat vmstat 60
イベント ./bin/iostat.sh iostat iostat 60
イベント ./bin/nfsiostat.sh nfsiostat nfsiostat 60
イベント ./bin/ps.sh ps ps 30
イベント ./bin/top.sh top top 60
イベント ./bin/netstat.sh netstat netstat 60
イベント ./bin/bandwidth.sh bandwidth bandwidth 60
イベント ./bin/protocol.sh protocol protocol 60
イベント ./bin/openPorts.sh openPorts openPorts 300
イベント ./bin/time.sh time time 21600
イベント ./bin/lsof.sh lsof lsof 600
イベント ./bin/df.sh df df 300
イベント ./bin/who.sh who who 150
イベント ./bin/usersWithLoginPrivs.sh usersWithLoginPrivs usersWithLoginPrivs 3600
イベント ./bin/lastlog.sh lastlog lastlog 300
イベント ./bin/cpu.sh cpu cpu 300
イベント ./bin/rlog.sh auditd auditd 300
イベント ./bin/package.sh package package 300
イベント ./bin/hardware.sh hardware hardware 300
イベント /Library/Logs - - -
イベント /var/log/ ※whitelist/blacklistによる対象ログの制限あり - - -
イベント /var/adm/ ※whitelistによる対象ログの制限あり - - -
イベント /etc/ ※whitelistによる対象ログの制限あり - - -
イベント /root/.bash_history bash_history - -
イベント /home/*/.bash_history bash_history - -
イベント ./bin/openPortsEnhanced.sh Unix:ListeningPorts Unix:ListeningPorts 3600
イベント ./bin/passwd.sh Unix:UserAccounts Unix:UserAccounts 3600
イベント ./bin/selinuxChecker.sh Unix:SELinuxConfig Unix:SELinuxConfig 3600
イベント ./bin/service.sh Unix:Service Unix:Service 3600
イベント ./bin/sshdChecker.sh Unix:SSHDConfig Unix:SSHDConfig 3600
イベント ./bin/update.sh Unix:Update Unix:Update 86400
イベント ./bin/uptime.sh Unix:Uptime Unix:Uptime 86400
イベント ./bin/version.sh Unix:Version Unix:Version 86400
イベント ./bin/vsftpdChecker.sh Unix:VSFTPDConfig Unix:VSFTPDConfig 86400

ファイルモニターとして定義されているものは何となくパスを見ればわかると思います。
スクリプトインプットとして定義されているものも、何となく名前から実行しているコマンドを察することができるものもあります。ただ具体的な実装はスクリプトの中を見て解析するしかなさそうです。

データタイプ(イベント/メトリクス)について補足

初めてsplunkのAdd-onを使ってログを取り込みしようとする人は、イベントとメトリクスという二つのデータタイプの違いがわかりづらいかもしれません。
Splunkには、イベントとメトリクスという二つのデータタイプがあり、インデックスもイベントインデックスとメトリクスインデックスの二種類があります。

メトリクスは、オブザーバビリティの分野で使われるメトリクスデータのことで、CPU、メモリ、レスポンスタイムなどの定量的な時系列データのことを指します。

通常のイベントインデックスと比較し、メトリクスインデックスはメトリクス専用に構成されており、性能とディスク効率に優れていることが特徴です。

Splunk_TA_nixでは、これらメトリクスデータを適切な形式で収集・格納するためのスクリプトが用意されており、上記の入力を有効にすることで、メトリクスデータを取得してSplunkに保管することができます。
(ただし、イベントインデックスはデフォルトでmainというインデックスが用意されていますが、メトリクスインデックスのデフォルトインデックスは存在しないため、入力を有効にする前にsplunk側でメトリックスインデックスを自分で作成しておく必要があることには注意が必要です)

Forwarderへのインストール手順

以前別の記事(https://qiita.com/torippy1024/items/1c125ab08967c11f1889 )でも紹介しましたが、Add-onをForwarderにインストールする場合は、splunkbaseからAdd-onをダウンロードし、そのAdd-onをForwarderのローカルディレクトリに転送してからインストールをする必要があります。以下の通りです。

Appの転送(ローカルPC上で実行)

scp -r /Users/torippy1024/splunk-add-on-for-unix-and-linux_1020.tgz torippy1024@xx.xx.xx.xx:/home/ec2-user/splunk-add-on-for-unix-and-linux_1020.tgz

Appのインストール(Add-onインストール先のForwarderにログインして実行)

/opt/splunkforwarder/splunk/bin/splunk status
(splunkdプロセスが起動中であることを確認)

sudo /opt/splunkforwarder/bin/splunk install app splunk-add-on-for-unix-and-linux_1020.tgz
(App '/home/ec2-user/splunk-add-on-for-unix-and-linux_1020.tgz' installed 
などと表示されることを確認)

以前の記事ではマニュアルで解凍してフォルダを移動させていましたが、./splunk install appコマンドを使えればそれら作業を自動でやってくれるので、今回はそちらを使ってインストール使っています。(ただし、splunkdプロセスが起動中でないと使えません)

inputs.confの修正

sudo mkdir /opt/splunkforwarder/etc/apps/Splunk_TA_nix/local
sudo cp -R /opt/splunkforwarder/etc/apps/Splunk_TA_nix/default/inputs.conf /opt/splunkforwarder/etc/apps/Splunk_TA_nix/local/inputs.conf
sudo chown -R splunk:splunk /opt/splunkforwarder/etc/apps/Splunk_TA_nix/local
sudo chmod -R 755 /opt/splunkforwarder/etc/apps/Splunk_TA_nix/local
sudo vi /opt/splunkforwarder/etc/apps/Splunk_TA_nix/local/inputs.conf
(必要な項目を有効化)
sudo /opt/splunkforwarder/bin/splunk restart

ちなみに、inputs.confの修正を一つ一つマニュアルで行うのは手間であるため、セットアップスクリプトが用意されています。
こちらを使えば一度に全項目を有効化できます。

一括設定スクリプトを利用した手順(事前に"metrics"という名前のメトリックスインデックスをsplunk上に作成しておいてください。本コマンドを実行すると、デフォルトであればイベントインデックスはmainに、メトリックスインデックスはmetricsに格納されるようになります)

sudo /opt/splunkforwarder/bin/splunk cmd sh /opt/splunkforwarder/etc/apps/Splunk_TA_nix/bin/setup.sh --enable-all --metric-index metrics
sudo /opt/splunkforwarder/bin/splunk restart

参考:
https://splunk.github.io/splunk-add-on-for-unix-and-linux/Enabledataandscriptedinputs/#enable-data-and-scripted-inputs-with-the-command-line

最後にsplunkdを再起動すれば完了です。

有効化した入力が動作しているか確認

無事にインストールとinputs.confの修正が完了していれば、splunkにログが転送されているようになっています。
しかし、Splunk_TA_nix Add-onでは、スクリプトインプットを多用しており、かつ、そのスクリプトの中にはけっこう依存関係があるライブラリが存在しています。

以下のコマンドを実行し、exit code=1で終了してしまっているスクリプトがないか確認してください。

sudo /opt/splunkforwarder/bin/splunk list inputstatus | grep "exited with code 1" -C 2

exit code=1で終了してしまっているスクリプトがあれば、そのスクリプト実行に必要なライブラリや権限が足りない可能性があるため、以下Githubより必要なライブラリを参照してインストールしてみてください。
https://splunk.github.io/splunk-add-on-for-unix-and-linux/Requirements/#dependencies

ただしスクリプトによっては実行インターバルが長めのものもあるため、ライブラリをインストールしたあと、一定時間待機することも必要です。また、nfsiostat.shについては、NFSを使用していない環境だとexit code=1で何もせず終了する仕様のようなので、無視するか、そもそも有効化させないほうがよい場合もあるようです・・・。

取得したログのユースケース

最後に、取得したログのユースケースをいくつか紹介しておきます。
Splunk上でサーチを行うときのSPLです。
サーチ実行時にフィールドを抽出する必要があるため、Splunk側にもSplunk_TA_nix Add-onをインストールしてから実行してみてください。

ログインに失敗したユーザーとソースIPを表示するSPL:

index=* sourcetype=linux_secure action=failure
| table _time host, user, src

スクリーンショット 2025-11-02 2.20.26.png

実行されたコマンドをホスト、ユーザー毎に集計して表示するSPL:

index=* sourcetype=linux_secure
| stats count by host, USER, COMMAND
| sort -count

スクリーンショット 2025-11-02 2.19.21.png

1分毎のシステム+ユーザーの全コアの平均CPU利用率をサーバー毎に表示するSPL:

index=* sourcetype=cpu CPU=All
| eval pctTotal = pctSystem + pctUser
| timechart span=1m avg(pctTotal) by host

表示例(視覚エフェクトタブでグラフを折れ線グラフに変更):
スクリーンショット 2025-11-02 2.16.59.png

参考資料

記事中でも参照したものも含まれていますが・・・。

Splunk Add-on for Unix and Linux
https://splunkbase.splunk.com/app/833

Deploy and Use the Splunk Add-on for Unix and Linux(レガシードキュメントなので参考程度)
https://docs.splunk.com/Documentation/UnixAddOn/6.0.0/User/AbouttheSplunkAdd-onforUnixandLinux

About the Splunk Add-on for Unix and Linux
https://splunk.github.io/splunk-add-on-for-unix-and-linux/

Overview of metrics
https://help.splunk.com/en/splunk-enterprise/get-data-in/metrics/10.0/introduction-to-metrics/overview-of-metrics

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?