ブログ?

もうだめぽ

NDOUtilsのインストール

NDOUtilsではNagiosのデータをデータベースに格納して管理することができます。
詳細は公式サイトを参照してください。
http://exchange.nagios.org/directory/Addons/Database-Backends/NDOUtils/details
下記はサイトからの引用です。

NDOUtils allows you to export current and historical data from one or more Nagios instances to a MySQL database. Several community addons use this as one of their data sources. NDOUtils consists of a standalone daemon, a Nagios event broker, and several helper utilities.

コンパイル、インストール

$ curl http://jaist.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz | tar zxv
$ cd ndoutils-1.4b9
$ ./configure

*** Configuration summary for ndoutils 1.4b9 10-27-2009 ***:

 General Options:
 -------------------------
 NDO2DB user:    nagios
 NDO2DB group:   nagios


Review the options above for accuracy.  If they look okay,
type 'make' to compile the NDO utilities.

$ make
$ sudo make install

  Hint: NDOUtils Installation against Nagios v3.x
  completed.

  If you want to install NDOUtils for Nagios v2.x
  please type  'make install-2x


  Next step should be the database initialization/upgrade
  cd into the db/ directory and either:
     ./installdb  (for a new installation) or:
     ./upgradedb  (for an existing one)

make[1]: ディレクトリ `/usr/local/src/ndoutils-1.4b9/src' から出ます

Main NDOUtils components installed

データベース作成

次にNDOUtilsで利用するデータベース、ユーザ、パスワードを設定します。(いずれもndoutilsとしました)
READMEには下記の記述があるため権限は制限しました。

2. Create a username/password that has at least the following privileges for the database:

SELECT, INSERT, UPDATE, DELETE

mysql> CREATE DATABASE ndoutils;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE
    -> ON ndoutils.*
    -> TO ndoutils@localhost
    -> IDENTIFIED BY 'ndoutils';
Query OK, 0 rows affected (0.01 sec)

次にテーブルを作成します。
failedと出ていますが気にしないでおきます :-)

$ cd db
$ ./installdb -u root -p "" -h localhost -d ndoutils
DBD::mysql::db do failed: Table 'ndoutils.nagios_dbversion' doesn't exist at ./installdb line 51.
** Creating tables for version 1.4b9
     Using mysql.sql for installation...
** Updating table nagios_dbversi

モジュール、コンフィグファイルのコピー

broker moduleのコピー。

$ sudo cp src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
$ sudo cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
$ sudo chown nagios:nagios /usr/local/nagios/etc/ndomod.cfg

nagiosがbroker moduleを読み込むように設定。

$ sudi vi /usr/local/nagios/etc/ndomod.cfg
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg 

ndo2dbのコピー。

$ sudo cp src/ndo2db-3x /usr/local/nagios/bin/ndo2db
$ sudo cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
$ sudo chown nagios:nagios /usr/local/nagios/etc/ndo2db.cfg

ndo2dbの設定を先ほど作成したデータベース情報に変更。

$ sudo vi /usr/local/nagios/etc/ndo2db.cfg
db_name=ndoutils
db_user=ndoutils
db_pass=ndoutils

ndo2dbデーモンの起動設定。

$ sudo cp daemon-init /etc/init.d/ndoutils
$ sudo chmod 755 /etc/init.d/ndoutils
$ sudo chkconfig ndoutils on

最後にndo2db,nagiosを起動して終わりです。

$ sudo service ndoutils start
$ sudo service nagios restart

動作確認

正常に動作していればnagiosのログ(/usr/local/nagios/var/nagios.log)に
こんな感じで表示されているはずです。

[1326691682] Nagios 3.3.1 starting... (PID=14465)
[1326691682] Local time is Mon Jan 16 14:28:02 JST 2012
[1326691682] LOG VERSION: 2.0
[1326691682] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1326691682] ndomod: Successfully connected to data sink.  0 queued items to flush.
[1326691682] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
[1326691682] Finished daemonizing... (New PID=14469)


また、MySQLにもデータが格納されます。

mysql> SELECT * FROM ndoutils.nagios_hosts\G
*************************** 1. row ***************************
                          host_id: 2
                      instance_id: 1
                      config_type: 1
                   host_object_id: 1
                            alias: oreore.dtdns.net
                     display_name: oreore.dtdns.net
                          address: 127.0.0.1
          check_command_object_id: 13
               check_command_args: 
   eventhandler_command_object_id: 0
        eventhandler_command_args: 
notification_timeperiod_object_id: 43
       check_timeperiod_object_id: 2
       failure_prediction_options: 
                   check_interval: 1
                   retry_interval: 1
               max_check_attempts: 10
         first_notification_delay: 0
            notification_interval: 120
                   notify_on_down: 1
            notify_on_unreachable: 1
               notify_on_recovery: 1
               notify_on_flapping: 0
               notify_on_downtime: 0
                      stalk_on_up: 0
                    stalk_on_down: 0
             stalk_on_unreachable: 0
           flap_detection_enabled: 1
             flap_detection_on_up: 1
           flap_detection_on_down: 1
    flap_detection_on_unreachable: 1
               low_flap_threshold: 0
              high_flap_threshold: 0
         process_performance_data: 1
         freshness_checks_enabled: 0
              freshness_threshold: 0
           passive_checks_enabled: 1
            event_handler_enabled: 1
            active_checks_enabled: 1
        retain_status_information: 1
     retain_nonstatus_information: 1
            notifications_enabled: 1
                 obsess_over_host: 1
       failure_prediction_enabled: 1
                            notes: 
                        notes_url: 
                       action_url: 
                       icon_image: 
                   icon_image_alt: 
                       vrml_image: 
                  statusmap_image: 
                   have_2d_coords: 0
                             x_2d: -1
                             y_2d: 0
                   have_3d_coords: 0
                             x_3d: 0
                             y_3d: 0
                             z_3d: 0
1 row in set (0.00 sec)