vim /etc/nagios/conf.d/192.168.1.201.cfg
define host{
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 192.168.1.201
alias 1.201
address 192.168.1.201
}
define service{
use generic-service
host_name 192.168.1.201
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.1.201
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.1.201
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
} ■4.配置文件说明
2.配置加载监控对象文件
vim /etc/nagios/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg #去掉注释
3.编辑 commands.cfg 文件定义check_nt对nagios使用(默认已经定义,不需要再配置)
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
} 4.设置要监控的内容(默认配置)
define host{
use windows-server
host_name winserver
alias My Windows Server
address 192.168.1.105 #被监控主机ip
}
define hostgroup{
hostgroup_name windows-servers
alias Windows Servers
}
define service{
use generic-service
host_name winserver
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
define service{
use generic-service
host_name winserver
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service{
use generic-service
host_name winserver
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
define service{
use generic-service
host_name winserver
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use generic-service
host_name winserver
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
define service{
use generic-service
host_name winserver
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
} 5.重启服务测试
nagios -v /etc/nagios/nagios.cfg
#检查配置文件语法错误
service nagios restart
五、nagios邮件报警
1.配置contact.cfg
vim /etc/nagios/objects/contacts.cfg #底端增加如下:
define contact{
contact_name 123
use generic-contact
alias szk
email szk5043@139.com
}
define contact{
contact_name 456
use generic-contact
alias szk
email szk5043@139.com
}
define contactgroup{
contactgroup_name common
alias common
members 123,456
} # 需要在配置文件默认底端members nagiosadmin,szk 这一行加上szk组员逗号隔开 2.配置192.168.1.201.cfg文件
#在需要告警的服务里加上contactgroup
vim /etc/nagios/conf.d/192.168.1.201.cfg
define service{
use generic-service
host_name 192.168.1.201
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
contact_groups common #common 是在 /etc/nagios/objects/contacts.cfg 定义的收件用户组
notifications_enabled 1
notification_period 24x7
notification_options c,r #这四行配置加在需要发送告警邮件的服务后面
notifications_enabled 1 ;是否开启提醒功能。1为开启,0为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义>,效果相同。
notification_period 24x7 ;发送提醒的时间段。非常重要的主机(服务)我定义为7×24,一般的主机(服务)就定义为上>班时间。如果不在定义的时间段内,无论什么问题发生,都不会发送提醒。
notification_options:w,u,c,r ;这个是service的状态。w为waning, u为unknown, c为critical, r为recover(恢复了),>类似的还有一个 host对应的状态:d,u,r d = 状态为DOWN, u = 状态为UNREACHABLE , r = 状态恢复为OK,需要加入到host的定义配>置里。
}
nagios -v /etc/nagios/nagios.cfg #必须检测配置文件
service nagios restart #重启服务 3.若接收不到邮件
a.在服务端查看 /var/log/nagios/nagios.log 里是否有包含 SERVICE NOTIFICATION 的行
b.在服务端查看邮件软件 sendmail 或 postfix 是否启动,默认监听25端口 netstat -lnp ,查看邮件日志/var/log/maillog 是否有告警邮件发出
c.手动测试是否能发出邮件 mail -s "test" szk5043@139.com < /etc/inittab
d.vim /etc/nagios/conf.d/192.168.1.160.cfg 检查服务端上给客户端的配置文件是否给需要邮件告警的服务添加以下四行:
contact_groups common
notifications_enabled 1
notification_period 24x7
notification_options c,r
若没添加添加后检测配置文件、重启nagios服务