how-to-monitor-nagios-alerts-with-alerta-on-ubuntu-16-04
前書き
Alertaは、複数の監視システムからのアラートを統合および重複排除し、それらを単一の画面で視覚化するために使用されるWebアプリケーションです。 Alertaは、Nagios、Zabbix、Sensu、InfluxData Kapacitorなど、多くの有名な監視ツールと統合できます。
このチュートリアルでは、Alertaを設定し、一般的なオープンソース監視システムであるhttp://nagios.org [Nagios]からの通知を表示するように設定します。
前提条件
このチュートリアルを実行するには、次のものが必要です。
-
Ubuntu 16.04初期サーバーセットアップガイドに従ってsudo non- rootユーザーとファイアウォール。
-
Nagiosを実行する最初のUbuntuサーバーで、次のコンポーネントをインストールします。
-
Apache、MySQL、およびPHP、チュートリアルhttps://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04に従う[Linux、Apache、MySQL、PHP(LAMP)スタックをUbuntu 16.04にインストールする方法]。
-
Nagios 4は、チュートリアルhttps://www.digitalocean.com/community/tutorials/how-to-install-nagios-4-and-monitor-your-servers-on-ubuntu-14-04[How To Nagios 4をインストールし、Ubuntuでサーバーを監視してください]およびそれを構成するための前提条件。
-
このチュートリアルでAlertaをインストールする2番目のUbuntuサーバーに、次のコンポーネントをインストールします。
-
チュートリアルhttps://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04[Ubuntu 16.04にNginxをインストールする方法]に従ってインストールされたNginx。
-
チュートリアルhttps://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04[Ubuntu 16.04にMongoDBをインストールする方法]に従ってインストールされたMongoDB。
-
Alerta、チュートリアルhttps://www.digitalocean.com/community/tutorials/how-to-monitor-zabbix-alerts-with-alerta-on-ubuntu-16-04[How To Ubuntu 16.04のAlertaでZabbixアラートを監視します]。
ステップ1-Nagios-to-Alerta Gatewayのインストール
Nagiosの機能をNagios Event Broker(NEB)モジュールで拡張できます。 NEBはNagiosのイベント統合メカニズムであり、NEBモジュールは他のサービスをNagiosと統合できる共有ライブラリです。 この手順では、Alertaに通知を送信するNEBモジュールであるhttps://github.com/alerta/nagios-alerta[Nagios to Alerta Gateway]をインストールします。
非rootユーザーとしてNagiosサーバーにログインします。
ssh sammy@
Nagios to Alerta Gatewayにはシステムパッケージが事前に構成されていないため、ソースからビルドする必要があります。 そのためには、いくつかの開発ツールとファイルをインストールする必要があります。 GitHubからソースコードを取得できるように、Gitもインストールする必要があります。
sudo apt-get install -y git curl gcc make libcurl4-openssl-dev
前提条件をインストールしたら、Gitを使用してプロジェクトのGitHubリポジトリからソースコードを複製します。
git clone https://github.com/alerta/nagios-alerta.git
次に、新しい `+ nagios-alerta +`ディレクトリに移動します。
cd nagios-alerta
次に、 `+ make `を使用して ` nagios-alerta +`モジュールをコンパイルします。
make nagios4
次の出力が表示されます。
Outputcd ./src && make nagios4
make[1]: Entering directory '/home/sammy/nagios-alerta/src'
gcc -fPIC -g -O2 -DHAVE_CONFIG_H -I../include -I../include/nagios4 -lcurl -o alerta-neb.o alerta-neb.c -shared -lcurl
make[1]: Leaving directory '/home/sammy/nagios-alerta/src'
異なるものが表示された場合は、すべての前提条件がインストールされていることを確認してください。
次に、インストールタスクを実行します。
sudo make install
モジュールが `+ / usr / lib / nagios +`にインストールされたことを示す次の出力が表示されます。
Outputcd ./src && make install
make[1]: Entering directory '/home/sammy/nagios-alerta/src'
[ -d /usr/lib/nagios ] || mkdir /usr/lib/nagios
install -m 0644 alerta-neb.o /usr/lib/nagios
make[1]: Leaving directory '/home/sammy/nagios-alerta/src'
モジュールをインストールしたら、この新しいモジュールを使用するようにNagiosを構成できます。
ステップ2-Nagios-to-Alerta Gatewayの構成
Nagiosを設定して、通知メッセージをAlertaに送信します。
最初に、Nagiosメイン構成ファイルで新しくインストールされたAlertaブローカーモジュールを有効にします。 エディターでNagios構成ファイルを開きます。
sudo vi /usr/local/nagios/etc/nagios.cfg
`+ broker_module +`ディレクティブを含むセクションを見つけます:
/usr/local/nagios/etc/nagios.cfg
...
# EVENT BROKER MODULE(S)
# This directive is used to specify an event broker module that should
# by loaded by Nagios at startup. Use multiple directives if you want
# to load more than one module. Arguments that should be passed to
# the module at startup are separated from the module path by a space.
#
[...]
#broker_module=/somewhere/module1.o
#broker_module=/somewhere/module2.o arg1 arg2=3 debug=0
...
Alertaモジュールを構成するには、2つの必須引数を指定する必要があります。
-
* URL *:Alerta APIとの通信に使用されるアドレス。 チュートリアルのステップ3でこれを設定しましたhttps://www.digitalocean.com/community/tutorials/how-to-monitor-zabbix-alerts-with-alerta-on-ubuntu-16-04[Zabbixアラートを監視する方法Ubuntu 16.04でAlertaを使用]。
-
* key *:チュートリアルのステップ4で作成したAPIキーhttps://www.digitalocean.com/community/tutorials/how-to-monitor-zabbix-alerts-with-alerta-on-ubuntu-16-04 [Ubuntu 16.04でAlertaを使用してZabbixアラートを監視する方法]。 これは、Alertaで認証してイベントをポストするために必要です。
次の行をファイルに追加して、Alerta統合を構成します。
/usr/local/nagios/etc/nagios.cfg
...
broker_module=/usr/lib/nagios/alerta-neb.o http:// key=
...
指定できる追加のオプション引数もいくつかあります。
-
* env *:環境名を指定します。 デフォルトの環境名は `+ Production`です。
-
* hard_only *:結果をハード状態でのみ転送します。 Nagios State Typesの詳細については、https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/statetypes.html [Nagiosのドキュメント]をご覧ください。 このモードを有効にするには、これを「1」に設定します。
-
* debug *:-モジュールのデバッグモードを有効にします。 このモードを有効にするには、これを「1」に設定します。
これらのオプションをすべて指定するには、代わりに次の行を使用します。
/usr/local/nagios/etc/nagios.cfg
...
broker_module=/usr/lib/nagios/alerta-neb.o http:// key= env= hard_only= debug=
...
ファイルを保存し、エディターを終了します。
環境とサービス名でアラートを識別するには、Nagios カスタムオブジェクト変数。 これを行うには、設定で `+ _Environment `および ` _Service +`変数を使用します。 それらを今設定しましょう。
`+ / usr / local / nagios / etc / objects / +`ディレクトリにあるデフォルトのNagiosホストオブジェクト設定ファイルを開きます。
sudo vi /usr/local/nagios/etc/objects/localhost.cfg
このホストでのすべてのアラートを* Production アラートとしてマークし、デフォルトサービス Nagios *を呼び出します。 次のホスト定義を見つけます。
/usr/local/nagios/etc/objects/localhost.cfg
...
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
...
設定に `+ _Environment `と ` _Service +`の値を追加します:
/usr/local/nagios/etc/objects/localhost.cfg
...
host_name localhost
alias localhost
address 127.0.0.1
}
...
ここで、システムパーティションのスペース不足に関連するすべてのイベントを*システム*アラートとしてマークします。 空き領域を確認する方法を定義するファイルのこのセクションを見つけます。
/usr/local/nagios/etc/objects/localhost.cfg
...
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
...
それを変更して、 `+ System +`サービスに関連付けます:
/usr/local/nagios/etc/objects/localhost.cfg
...
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
...
ファイルを保存し、エディターを終了します。 Nagiosを再起動して、これらの新しい設定を適用します。
sudo systemctl restart nagios.service
Nagiosログファイルをチェックして、サービスが正しく実行されていることを確認します。
tail /usr/local/nagios/var/nagios.log
次の出力が表示されます。
Output...
[1505804481] [alerta] Initialising Nagios-Alerta Gateway module, v3.5.0
[1505804481] [alerta] debug is on
[1505804481] [alerta] states=Hard (only)
[1505804481] [alerta] Forward service checks, host checks and downtime to http://your_alerta_server_ip/api
[1505804481] .
[1505804481] Successfully launched command file worker with pid 25416
これで、Nagiosはシステムまたはサービスがオフになるとすぐに通知を送信します。 テストイベントを生成しましょう。
手順3-Nagios-Alerta統合を検証するためのテストアラートの生成
テストアラートを生成して、すべてが接続されていることを確認しましょう。 デフォルトでは、Nagiosはサーバーの空きディスク容量を追跡します。 Nagiosのファイルシステム使用状況アラートをトリガーするのに十分な大きさの一時ファイルを作成します。
最初に、Nagiosサーバーの空き容量を確認します。 `+ df +`コマンドを使用して確認できます:
df -h
次のような出力が表示されます。
Output Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 3.1G 17% /
使用可能な空き領域の量を確認してください。 この場合、空き領域は「+ 16GB +」です。 空き容量は異なる場合があります。
`+ fallocate +`コマンドを使用して、利用可能なディスク容量の80%以上を占めるファイルを作成します。これはアラートをトリガーするのに十分なはずです:
fallocate -l 14G /tmp/temp.img
数分以内に、Nagiosは空きディスク容量のアラートをトリガーし、アラートメッセージをAlertaに送信します。 Alertaダッシュボードにこの新しい通知が表示されます。
image:https://assets.digitalocean.com/articles/alerta_nagios_cent7/xPCO3K0.png [Nagiosからの空き領域アラートを表示するアラート]
アラートが機能していることがわかったので、作成した一時ファイルを削除して、ディスク容量を再利用できるようにします。
rm -f /tmp/temp.img
1分後、Nagiosは回復メッセージを送信します。 アラートはメインのAlertaダッシュボードから消えますが、* Closed *を選択することにより、すべてのクローズされたイベントを表示できます。
image:https://assets.digitalocean.com/articles/alerta_nagios_cent7/NrCfEUV.png [Alerta’s closed alerts]
イベント行をクリックして、詳細を表示できます。
結論
このチュートリアルでは、Alertaを実行している別のサーバーに通知を送信するようにNagiosを構成しました。
Alertaは、多くのシステムからのアラートを追跡する便利な場所を提供します。 たとえば、インフラストラクチャの一部がNagiosを使用し、他の部分がZabbixを使用する場合、両方のシステムからの通知を1つのパネルにマージできます。