nagios部署配置流程

nagios部署配置流程

nagios服务端:
1、部署nagios服务端(参考nagios官方部署文档)、nagios-plugin、php、apache2

2、需要在服务端添/etc/hosts中添加解析

3、配置文件说明
nagios.cfg中配置需要监控的主机目录dir_cfg=path/to/somewhere 该路径下的文件均以主机名命名,以.cfg结尾

commands.cfg
配置接受nrpe传过来的command需要在 commands.cfg 配置,模板如下:

# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

#配置邮箱报警、微信报警
define command {
command_name sendEmail
command_line $USER1$/sendEmail/sendEmail.pl -f "security@test.cn" -t $CONTACTEMAIL$ -s smtp.mxhichina.com:80 -u "** $HOSTNAME$—— $HOSTNAME$ $HOSTSTATE$ **" -xu security@test.cn -xp 'Z2h0o1g6n0z4h2i9cheng@' -m "***** New_NAGIOS Notification ***** Notification type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ HOSTNAME: $HOSTALIAS$ IP$HOSTNAME$ STATUS: $SERVICESTATE$ Time: $LONGDATETIME$ SERVICEOUTPUT: $SERVICEOUTPUT$"}

define command {
command_name wei_baojing
command_line $USER1$/wei_baojing.py "通知类型: $NOTIFICATIONTYPE$<br><br>服务: $SERVICEDESC$<br>主机: $HOSTALIAS$<br>IP地址: $HOSTNAME$<br>状态: $SERVICESTATE$<br><br>日期时间: $LONGDATEME$<br><br>附加信息:<br><br>$SERVICEOUTPUT$"
}

templates.cfg 需要配置监控的模板
define service {
service_description generic-zzcbj
name generic-zzcbj
contacts zzcbj
check_period 24x7
notification_period 24x7
max_check_attempts 1
check_interval 3
retry_interval 1
notification_interval 5
notification_options w,u,c,r,f
first_notification_delay 0
register 0
active_checks_enabled 1
passive_checks_enabled 1
notifications_enabled 1
}

localhost.cfg 监控本机配置


contacts.cfg
#配置微信 邮件报警

define contact {
contact_name zzcbj
alias zzcbj
email 939598325@qq.com,210355875@qq.com
pager admin
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r,f,s
service_notification_options w,u,c,r,f,s
register 1
host_notification_commands sendEmail,wei_baojing
service_notification_commands sendEmail,wei_baojing
#host_notification_commands weixin_ywts
#service_notification_commands weixin_ywts
}

配置文件配置完成后可以检查配置文件是否有问题
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

/etc/init.d/nagios configtest

客户端: nrpe nagios-plugins 安装
监控脚本放在/usr/local/nagios/libexec/
/usr/local/nagios/etc/nrpe.cfg 配置nagios服务端地址
/usr/local/nagios/etc/nrpe.cfg 文件中配置需要监控的脚本路径 脚本来源于/usr/local/nagios/libexec/

原文地址:https://www.cnblogs.com/wclwcw/p/7727257.html