Definehost{
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 Nagios-Server
Alias Nagios-Server
Address 127.0.0.1
}
definehostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
Alias Linux Servers ; Long name of thegroup
members Nagios-Server ; Comma separated listof hosts that belong to this group
}
defineservice{
Use local-service ; Name of service template to use
Host_name Nagios-Server
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
Defineservice{
use local-service ; Name of service template to use
host_name Nagios-Server
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
defineservice{
use local-service ; Name of service template to use
host_name Nagios-Server
service_description Current Users
check_command check_local_users!20!50
}
defineservice{
use local-service ; Name of service template to use
host_name Nagios-Server
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
Defineservice{
Use local-service ; Name of service template to use
host_name Nagios-Server
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
defineservice{
use local-service ; Name of service template to use
host_name Nagios-Server
service_description Swap Usage
check_command check_local_swap!20!10
}
defineservice{
Use local-service ; Name of service template to use
host_name Nagios-Server
service_description SSH
check_command check_ssh
notifications_enabled 0
}
defineservice{
Use local-service ; Name of service template to use
host_name Nagios-Server
service_description HTTP
check_command check_http
notifications_enabled 0
}
windows.cfg,本实验主要采用组进行配置,此文档不删掉不使,下面配置供参考。
definehost{
use windows-server ; Inherit default values from a template
host_name Nagios-Windows ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.1.113 ; IP address of the host
}
definehostgroup{
hostgroup_name windows-servers ; The name of the hostgroup
alias Windows Servers ; Long name of thegroup
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description Uptime
check_command check_nt!UPTIME
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c90
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -lW3SVC
}
defineservice{
use generic-service
host_name Nagios-Windows
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -lExplorer.exe
}
e. services.cfg文件
此文件默认也不存在,需要手动创建,services.cfg文件主要用于定义监控的服务和主机资源,例如监控http服务、ftp服务、主机磁盘空间、主机系统负载等等。Nagios-Server 和Nagios-Windows 相关服务已在相应的配置文件中定义,所以这里只需要定义Nagios-Linux 相关服务即可,这里只定义一个检测是否存活的服务来验证配置文件的正确性,其他服务的定义将在后面讲到。
define service{
use local-service ; #引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。
host_name Nagios-Linux ; #指定要监控哪个主机上的服务,“Nagios-Server”在hosts.cfg文件中进行了定义。
service_description PING ; #对监控服务内容的描述,以供维护人员参考。
contact_groups linuxcontact
check_command check-host-alive ; #指定检查的命令。
}
define service{
use local-service
host_name Nagios-Linux
service_description CurrentLoad
contact_groups linuxcontact
check_command check_nrpe!check_load
}
define service{
use local-service
host_name Nagios-Linux
service_description TotalProcesses
contact_groups linuxcontact
check_command check_nrpe!check_total_procs
}
define service{
use local-service
host_name Nagios-Linux
service_description CurrentUsers
contact_groups linux contact
check_command check_nrpe!check_users
}
define service{
use local-service
host_name Nagios-Linux
service_description CheckZombie Procs
contact_groups linuxcontact
check_command check_nrpe!check_zombie_procs
}
define service{
use local-service
host_name Nagios-Linux
service_description Check Swap
contact_groups linux contact
check_command check_nrpe!check_swap
}
# SERVICE DEFINITIONS
#
###############################################################################
# Create a service for monitoring the versionof NSCLient++ that is installed
# Change the host_name to match the name ofthe host you defined above
define service{
use generic-service
host_name Nagios-Windows
service_description NSClient++Version
contact_groups windowscontact
check_command check_nt!CLIENTVERSION
}
# Create a service for monitoring the uptimeof the server
# Change the host_name to match the name ofthe host you defined above
# Create a service for monitoring theExplorer.exe process
# Change the host_name to match the name ofthe host you defined above
define service{
use generic-service
host_name Nagios-Windows
service_description Explorer
contact_groups windowscontact
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
f. contacts.cfg,contactgroup.cfg文件,默认不存在,需手动创建!
contacts.cfg是一个定义联系人和联系人组的配置文件,当监控的主机或者服务出现故障,nagios会通过指定的通知方式(邮件或者短信)将信息发给这里指定的联系人或者使用者。contactgroup.cfg定义联系人组的配置文件,注意:members选项里面的联系人在contacts.cfg里面要要定义,多个联系从之间用逗号隔开。
contacts.cfg下面的配置文档
definecontact{
contact_name echo ; Short name of user
use generic-contact ; Inheritdefault values from generic-contact template (defined above)
alias linux contact ; Full name of user