标签:pnp4nagios 图形化监控 邮件告警
紧接centos7.4安装监控软件系列2:nagios(1)yum install -y \
cairo pango \
perl-rrdtool rrdtool \ //rrd插件必需,可设置阿里云仓库获取
librrds-perl \
zlib zlib-devel \
freetype freetype-devel \
gd gd-devel
tar xf pnp4nagios-0.6.26.tar.gz
cd pnp4nagios-0.6.26
./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagios
make all
make install
make install-webconf
make install-config
make install-init
cd sample-config/
make install-webconf
cd /usr/local/pnp4nagios/etc/
mv misccommands.cfg-sample misccommands.cfg
mv rra.cfg-sample rra.cfg
mv nagios.cfg-sample nagios.cfg
cd pages/
mv web_traffic.cfg-sample web_traffic.cfg
cd ../check_commands/
mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
mv check_nrpe.cfg-sample check_nrpe.cfg
mv check_nwstat.cfg-sample check_nwstat.cfg
systemctl enable npcd
systemctl start npcd //启动图形化插件
ps aux | grep npcd
vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1 //改成1,开启
以下行需要替换修改(按照以下内容替换):
‘# service performance data
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata 835行
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$ 848行
service_perfdata_file_mode=a 859行
service_perfdata_file_processing_interval=15 870行
service_perfdata_file_processing_command=process-service-perfdata-file 880行
’# host performance data starting with Nagios
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata 834行
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$ 846行
host_perfdata_file_mode=a 857行
host_perfdata_file_processing_interval=15 868行
host_perfdata_file_processing_command=process-host-perfdata-file 878行
vi /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name process-service-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata
}
define command{
command_name process-host-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata
}
vi /usr/local/nagios/etc/objects/templates.cfg
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=HOST
register 0
}
define service {
name service-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
cd /usr/local/nagios/etc/conf
vi host81.cfg //在主机配置开头插入
define host{
use linux-server,host-pnp //添加调用host-pnp模块
vi service81.cfg //在每段service上开头插入,本例共需添加四处
define service{
use generic-service,service-pnp //在每一个区域添加调用use
/etc/init.d/nagios checkconfig //检查语法
service nagios restart
service httpd restart
win10再次访问192.168.80.80/nagios/
rm -rf /usr/local/pnp4nagios/share/install.php //平台会提示删除文件.此文件是php测试页面,必须删除,否则看不到图表
至此图表部分配置完毕
添加邮件警告,当出现事件时,按照规定的时间内发送邮件通知管理员
之前的vi objects/contacts.cfg配置文件里,我们已经修改过接收报警的管理员邮箱
email aa@163.com; //管理员邮箱(收信人邮箱)
但邮件不是凭空发送的,监控平台自己必须也要有邮箱(也就是发信人邮箱),
所以,就要安装发信软件mailx
yum install mailx
vi /etc/mail.rc //配置发信人邮箱(以客户端授权码方式登陆)
文件末尾新增:
set from=bb@163.com
set smtp=smtp.163.com
set smtp-auth-user=bb@163.com
set smtp-auth-password=abc123 //客户端授权码,需要自己登陆到相关邮箱设置
set smtp-auth=login
echo "bbbbb" | mail -s "testmail" aa@163.com //测试发信是否正常
到此,邮件警告也配置完毕
测试触发一个告警机制,观察是否有邮件发送至邮箱
本例中,在主配置文件server81.cfg中定义了 check_ssh ,
在80.81被控端手动关闭ssh,过会检查bb@163.com里是否有告警邮件
标签:pnp4nagios 图形化监控 邮件告警
原文地址:http://blog.51cto.com/13469709/2094085