CentOS5でNagios3.04構築【監視対象設定編】

Nagios2系からNagios3系に変わり、config系も若干変わりました。
Nagios2系の事はyumで入れると【/etc/nagios】配下に「hosts.cfg」「hostgroups.cfg」「services.cfg」等を
置いて管理するようにconfigもなっておりましたが


今回は

# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

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

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

# Definitions for monitoring a Windows machine
#cfg_file=/etc/nagios/objects/windows.cfg

# Definitions for monitoring a router/switch
#cfg_file=/etc/nagios/objects/switch.cfg

# Definitions for monitoring a server
#cfg_file=/etc/nagios/objects/printer.cfg

こんな感じになってます。
【/etc/nagios/】内にはnagios.cfg、cgi.cfgがあり
【/etc/nagios/objects】内にホスト設定等を行うファイルが存在します。


自分の場合はネットワーク系は「switch.cfg」に
サーバ系は「server.cfg」に書いていく事にしました。


なので上記コンフィグから
・cfg_file=/etc/nagios/objects/switch.cfg
コメントアウトを外し。
・cfg_file=/etc/nagios/objects/printer.cfg
をcfg_file=/etc/nagios/objects/server.cfg
に書き換えました。


又、nagios2系では、ホスト設定(hosts.cfg)、ホストグループ設定(hostgroups.cfg)、サービス設定(services.cfg)と分けて記載してましたが
今回はserver.cfgにサーバのhost設定、グループ設定、サービス設定をいっぺんに載せる様にテンプレート化されてますので
それに倣って記載していきたいと思います。


ちょっと複雑なんですがlocalhost.cfgに書いてあるhostをserver.cfgに記載してあるグループに入れる事も可能です。
自分の場合はserver.cfg内に「社内サーバグループ」と「データセンター」グループを作成し
「社内サーバグループ」の「member」に「localhost」と記載し設定しました。
localhost.cfg内のグループはコメントアウト)


※server.cfgサンプル

##############################
##############################
## HOST DEFINITIONS
#
##############################
##############################

# Define a host for the printer we'll be monitoring
# Change the host_name, alias, and address to fit your situation

#define host{
# use generic-printer ; Inherit default values from a template
# host_name hplj2605dn ; The name we're giving to this printer
# alias HP LaserJet 2605dn ; A longer name associated with the printer
# address 192.168.1.30 ; IP address of the printer
# hostgroups network-printers ; Host groups this printer is associated with
# }

##############################
#
# IDC
#
##############################

define host{
use linux-server
host_name --------.---
alias ------------
address ---.---.---.---
parents IDC-Router
hostgroups IDC-servers
}

##############################
##############################
#
# HOST GROUP DEFINITIONS
#
##############################
##############################

# A hostgroup for network printers

#define hostgroup{
# hostgroup_name network-printers ; The name of the hostgroup
# alias Network Printers ; Long name of the group
# }

define hostgroup{
hostgroup_name office-servers
alias ------
members -------,--------,-------
}

define hostgroup{
hostgroup_name IDC-servers
alias -----------
members ----------,----------,----------
}


##############################
##############################
#
# SERVICE DEFINITIONS
#
##############################
##############################

# Create a service for monitoring the status of the printer
# Change the host_name to match the name of the host you defined above
# If the printer has an SNMP community string other than "public", change the check_command directive to reflect that

#define service{
# use generic-service ; Inherit values from a template
# host_name hplj2605dn ; The name of the host the service is associated with
# service_description Printer Status ; The service description
# check_command check_hpjd!-C public ; The command used to monitor the service
# normal_check_interval 10 ; Check the service every 10 minutes under normal conditions
# retry_check_interval 1 ; Re-check the service every minute until its final/hard state is determined
# }


# Create a service for "pinging" the printer occassionally. Useful for monitoring RTA, packet loss, etc.

define service{
use generic-service
host_name ----------,----------,----------
service_description PING check_command check_ping!3000.0,80%!5000.0,100% normal_check_interval 10
retry_check_interval 1
}


こんな感じ。殆ど伏せ字になっちゃいましたが・・・
要は元のprinter.cfgの情報をコメントアウトして、新たにサーバ情報、グループ情報を記載しているだけです。


これだけ出来れば、監視設定は完了となりますので再び下記コマンドでコンフィグチェックして起動します。


# /usr/bin/nagios -v /etc/nagios/nagios.cfg
# /etc/rc.d/init.d/nagios restart


次回、statusmapの設定方法を記載します。