Tips

nagiosでフリーな監視をしてみよう!~nagiosの設定(4)~

hostgroupの設定

ホストグループに追加する前に、ホストグループ専用の設定ファイルを作成します。

(1)「/usr/local/nagios/etc/nagios.cfg」ファイルを編集します。

# vi /usr/local/nagios/etc/nagios.cfg


・「nagios.cfg」ファイル変更前の内容

 # You can specify individual object config files as shown below:
 cfg_file=/usr/local/nagios/etc/objects/commands.cfg
 cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
 cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
 cfg_file=/usr/local/nagios/etc/objects/templates.cfg

 # Definitions for monitoring the local (Linux) host
 cfg_file=/usr/local/nagios/etc/objects/localhost.cfg


・「nagios.cfg」ファイル変更後の内容

 # You can specify individual object config files as shown below:
 cfg_file=/usr/local/nagios/etc/objects/commands.cfg
 cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
 cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
 cfg_file=/usr/local/nagios/etc/objects/templates.cfg
 cfg_file=/usr/local/nagios/etc/objects/hostgroup.cfg

 # Definitions for monitoring the local (Linux) host
 cfg_file=/usr/local/nagios/etc/objects/localhost.cfg


(2)「/usr/local/nagios/etc/objects/hostgroup.cfg」ファイルを作成します。

# vi /usr/local/nagios/etc/objects/hostgroup.cfg


・「hostgroup.cfg」ファイルの内容

 define hostgroup{
     hostgroup_name  linux-servers ; The name of the hostgroup
     alias           Linux Servers ; Long name of the group
     members         localhost,nagios2     ; Comma separated list of hosts that belong to this group
 }


(3)「/usr/local/nagios/etc/objects/localhost.cfg」ファイルを編集します。

# vi /usr/local/nagios/etc/objects/localhost.cfg


・「localhost.cfg」ファイル変更前の内容

 # Define an optional hostgroup for Linux machines

 define hostgroup{
         hostgroup_name  linux-servers ; The name of the hostgroup
         alias           Linux Servers ; Long name of the group
         members         localhost     ; Comma separated list of hosts that belong to this group
         }


・「localhost.cfg」ファイル変更後の内容

 # Define an optional hostgroup for Linux machines

 #define hostgroup{
 #        hostgroup_name  linux-servers ; The name of the hostgroup
 #        alias           Linux Servers ; Long name of the group
 #        members         localhost     ; Comma separated list of hosts that belong to this group
 #        }


(3)「service nagios checkconfig」コマンドで設定を確認します。

# service nagios checkconfig


※設定がおかしいと、以下のように「どのファイルの何行目がおかしい」とエラーメッセージを表示します。

# service nagios checkconfig
Running configuration check...

Nagios Core 4.0.8
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-12-2014
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Warning: Duplicate definition found for hostgroup 'linux-servers' (config file '/usr/local/nagios/etc/objects/hostgroup.cfg', starting on line 7)
Error: Could not add object property in file '/usr/local/nagios/etc/objects/hostgroup.cfg' on line 8.
   Error processing object config files!


***> One or more problems was encountered while processing the config files...

     Check your configuration file(s) to ensure that they contain valid
     directives and data defintions.  If you are upgrading from a previous
     version of Nagios, you should be aware that some variables/definitions
     may have been removed or modified in this version.  Make sure to read
     the HTML documentation regarding the config files, as well as the
     'Whats New' section to find out what has changed.


(4)問題なければ、nagiosのリロードを行います。

# service nagios reload

動作確認


「http://(サーバのIP)/nagios/」を開いて、左側の「現在の状態(Current Status)」-「ホストグループ(hostgroup)」をクリックし、「nagios2」が表示されていることを確認してください。

Linux認定資格 LPICを取るなら・・

Linux資格 「LPIC Lv1」徹底解説 連載目次

Recent News

Recent Tips

Tag Search