9.重新加载nagios.cfg配置文件:
通过浏览器访问nagios的web页面,查看新添加的swap资源的监控情况:

注解信息:
在services.cfg中使用check_nrpe的时候要带上“!”参数:
在/usr/local/nagios/etc/objects/services.cfg 添加如下内容:

define service {
use local-service
host_name mysqlhost
service_groups mysqlgroup
service_description SWAP
check_command check_nrpe!check_swap
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,r,c
}
define service {
use local-service
host_name mysqlhost
service_groups mysqlgroup
service_description CPUload
check_command check_nrpe!check_load
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,r,c
}
define service {
use local-service
host_name mysqlhost
service_groups mysqlgroup
service_description Free Space
check_command check_nrpe!check_disk
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,r,c
}
define service {
use local-service
host_name mysqlhost
service_groups mysqlgroup
service_description TotalProcesses
check_command check_nrpe!check_total_procs
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,r,c
}
define service {
use local-service ——使用的模板
host_name mysqlhost ——被监控主机名,该主机名必须是linux且运行着nrpe,而且必须是hosts.cfg中定义的
service_groups mysqlgroup
service_description ZombieProcesses ——监控项目的描述
check_command check_nrpe!check_zombie_procs ——监控命令是check_nrpe,在commands.cfg中定义,check_disk参数是nrpe.cfg中定义的
contact_groups admins
notification_interval 10 ——通知间隔
notification_period 24x7 ——通知周期设置
notification_options w,u,r,c ——定义状态报警设置
}


通过访问http://192.168.10.1/nagios来查看监控信息,显示信息如下:



nagios通过邮件发送报警信息:
nagios除了丰富的监控功能外,报警功能相当的强大(常见的报警方法有:邮件和短信):
邮件报警的配置
在/usr/local/nagios/etc/object/contact.cfg的配置文件中的email后添加管理员的邮箱:
define contact {
contact_name nagiosadmin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email root@localhost.localdomain #报警邮箱,以root为例。
}
截图如下:

注解:

-
在commands.cfg文件中要定义发邮件的命令默认就存在。
-
在hosts.cfg和services.cfg文件添加有关发通知的联系人信息和间隔等。
-
nagios利用本地的sendmail或postfix邮件服务器发送邮件,只要启动本地服务器的sendmail或postfix就可以了。
整个nagios部署到此告一段落,不足之处,请谅解。
