2.配置Nagios功能定义配置文件:
[iyunv@KCentOS5C ~]# vi /usr/local/nagios/etc/localhost.cfg
----------------------------------------------------------------------------------
###############################################################################
# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE
#
# Last Modified: 11-27-2006
#
# NOTE: This config file is intended to servce as an *extremely* simple
# example of how you can create your object configuration file(s).
#
###############################################################################
第一部分:时间定义段
###############################################################################
###############################################################################
#
# TIME PERIODS
#
###############################################################################
###############################################################################
# This defines a timeperiod where all times are valid for checks,
# notifications, etc. The classic "24x7" support nightmare. :-)
在时间定义段里,可以自己定义好几个指定的时间段并给与命名。Nagios应该在什么时间内做什么工作,对于Nagios自己来说并不是直接引用时间参数,而是引用用户自己定义的时间段的命名,Nagios只会参考和引用用户定义过的时间段名。
define timeperiod{
timeperiod_name none
alias No Time Is A Good Time
}
第二部分:命令定义段
###############################################################################
###############################################################################
#
# COMMANDS
#
###############################################################################
###############################################################################
# NOTE: Sample command definitions can now be found in the sample commands.cfg
# file
这些命令定义被独立归在了commands.cfg文件中了,这里先不多讲了,放到后面。
第三部分:联系人定义段
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# In this simple config file, a single contact will receive all alerts.
# This assumes that you have an account (or email alias) called
# "nagios-admin" on the local host.
在Nagios的诸多工作中都会涉及到联系人。当发生监测超出阀值,或者产程告警等情况时,Nagios都会以Email甚至更多方式来告知指定的联系人。联系人应该是系统当中存在的用户或者是Email的别名用户,以便于接收到重要的消息通知。
第四部分:联系人组定义段
###############################################################################
###############################################################################
#
# CONTACT GROUPS
#
###############################################################################
###############################################################################
# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.
联系人组就是将若干联系人聚合起来的组。
name generic-host ; The name of this host template
通过name来指定主机类名,这里的generic-host就是一个主机类名。
notifications_enabled 1 ; Host notifications are enabled
设定启用主机事件通知
event_handler_enabled 1 ; Host event handler is enabled
设定启用主机事件处理程序
flap_detection_enabled 1 ; Flap detection is enabled
设定启用状态抖动监测。
failure_prediction_enabled 1 ; Failure prediction is enabled
设定启用故障预测
process_perf_data 1 ; Process performance data
设定启用进程性能数据记录
retain_status_information 1 ; Retain status information across program restarts
设定启用状态信息保存功能。当Nagios重新启动的时候不会是空数据,而是先显示上次离线时最后保留的状态数据。
retain_nonstatus_information 1 ; Retain non-status information across program restarts
设定启用非状态信息保存功能。当Nagios重新启动的时候不会是空数据,而是先显示上次离线时最后保留的非状态数据。
notification_period all_days ; Send host notifications at any time
设定事件通知的工作时间段。后面要跟上定义过的时间段名,这里用全天时间段。
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
设定非注册。此项register为0值的时候Nagios会理解到该定义段是主机类而为实体主机的定义段。因此,在自定义主机类段的时候,记得也要加入这一个属性,用来向Nagios表明该段为主机类段。
}
## Linux host definition template - This is NOT a real host, just a template!
以下再建立一个Linux主机类段linux-server。这个类同时也继承了之前的通用主机类generic-host类,也就是说类也可以继承类。这样的关系和设定将使得主机设定进一步灵活。
define host{
name linux-server ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
通过use来指定要继承的主机类名。类也可以继承类。
check_period all_days ; By default, Linux hosts are checked round the clock
max_check_attempts 10 ; Check each Linux host 10 times (max)
设定监测失败后的最大尝试次数。
check_command check-host-alive ; Default command to check Linux hosts
设定监测主机存活的命令。
notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 15 ; Resend notification every 15 seconds.
设定监测主机的时间间隔,单位为秒
notification_options d,u,r ; Only send notifications for specific host states
设定监测指定主机产生的事件通知的条件选项。这里后面跟上一些级别类型参数:
w代表warning告警;
u代表unknown未知;
c代表critical严重;
r代表recover恢复;
d代表down奔溃。
contact_groups admins ; Notifications get sent to the admins by default
指定联系人组,这里的联系人组名必须是定义过的。
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
设定register表明本段定义的是一个主机类,而不是实体主机。
}
## Windows host definition template - This is NOT a real host, just a template!
这个是我自己添加的Windows的主机类windows-server,当然,它也是继承了generic-host这个大类,但其中的参数都没有怎么变动过。
## Since this is a simple configuration file, we only monitor one host - the
## local host (this machine).
以下为实体主机的定义了。首先必须要有localhost本地主机的定义段,否则很多基本功能都会有问题。
define host{
use linux-server
通过use来继承linux-server这个之前专为Linux主机定义的类。
define host{
use linux-server
host_name KCentOS5A
alias Kane Cruise CentOS 5 Server A
address 192.168.1.10
}
define host{
use windows-server
host_name KCWIN2K3A
alias Kane Cruise Windows Server 2003 A
address 192.168.1.14
}
define host{
use windows-server
host_name KCXP1
alias Kane Cruise Windows XP Professional 1
address 192.168.1.9
}
第六部分:主机组定义段
###############################################################################
###############################################################################
#
# HOST GROUPS
#
###############################################################################
###############################################################################
# We only have one host in our simple config file, so there is no need to
# create more than one hostgroup.
简而言之就是将定义的主机归类成主机组。
members localhost,KCentOS5A
通过members来指定该主机组的成员,注意这里的主机成员必须要是在host里定义过的主机。
}
define hostgroup{
hostgroup_name windows_hosts
alias Group of Windows Hosts
members KCXP1,KCWIN2K3A
}
转自 http://hi.baidu.com/kouzl/blog/item/0aa6084be09635f483025c0b.html