nagios安装完了,只有数字输出监控内容是不是不炫丽呢?是不是想像CACTI 一样出炫丽的图呢?那你可以选择PNP,他可以满足你的需求,只要你的脚本符合perfdata规则,那么rrdtool就可以出数据,PNP就可以用图给你画出来。
安装pnp4nagios
# yum -y install pnp4nagios
重载apache
# service httpd reload
配置nagios
# vim /etc/nagios/nagios.cfg
修改以下参数
process_performance_data=1 将0改为1,并在下面添加如下内容
# *** the template definition differs from the one in the original nagios.cfg # service_perfdata_file=/var/log/pnp4nagios/service-perfdata service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$ service_perfdata_file_mode=a service_perfdata_file_processing_interval=15 service_perfdata_file_processing_command=process-service-perfdata-file # *** the template definition differs from the one in the original nagios.cfg # host_perfdata_file=/var/log/pnp4nagios/host-perfdata host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$ host_perfdata_file_mode=a host_perfdata_file_processing_interval=15 host_perfdata_file_processing_command=process-host-perfdata-file
修改commands.cfg
# vim /etc/nagios/objects/commands.cfg
注释掉原有对process-host-perfdata和process-service-perfdata,重新定义
# # Bulk with NPCD mode # define command { command_name process-service-perfdata-file command_line /bin/mv /var/log/pnp4nagios/service-perfdata /var/spool/pnp4nagios/service-perfdata.$TIMET$ } define command { command_name process-host-perfdata-file command_line /bin/mv /var/log/pnp4nagios/host-perfdata /var/spool/pnp4nagios/host-perfdata.$TIMET$ }
修改templates.cfg
# vim /etc/nagios/objects/templates.cfg
添加如下内容
define host { name host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ register 0 } define service { name srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 }
如果将pnp4nagios集成到nagios web中,而不需要点击任何图标,请添加如下内容:
#Popups define host { name host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ register 0 } define service { name srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 }
并复制status-header.ssi到nagios网站目录下
# cp /usr/share/doc/pnp4nagios-0.6.22/contrib/ssi/status-header.ssi /usr/share/nagios/html/ssi/
修改linux-server,添加host-pnp
define host{ name linux-server ; The name of this host template use generic-host,host-pnp
修改windows-server,添加host-pnp
define host{ name windows-server ; The name of this host template use generic-host,host-pnp
修改service,添加srv-pnp
define service{ name local-service ; The name of this service template use generic-service,srv-pnp
启动npcd
# service npcd start
将npcd加到开机启动
# chkconfig npcd on
重新加载nagios配置
# service nagios reload
pnp4nagios模板位置
自定义模板位置:/usr/share/nagios/html/pnp4nagios/templates
pnp包自带的模板位置:/usr/share/nagios/html/pnp4nagios/templates.dist
自定义监控脚本存放位置
/usr/lib64/nagios/plugins
注意:自定义的脚本要给执行权限