服务模板配置
[root@nagios objects]# pwd /usr/local/nagios/etc/objects [root@nagios objects]# vi services.cfg 添加下面内容 ###########172.16.0.18################## define service{ use generic-service host_name nagios service_description Load check_command check_nrpe!check_load #这里的check_nrpe不是服务端/usr/local/nagios/libexec/check_nrpe,而是command.cfg里定义的命令 } define service{ use generic-service host_name nagios service_description Disk check_command check_nrpe!check_disk } define service{ use generic-service host_name nagios service_description memory check_command check_nrpe!check_mem } define service{ use generic-service host_name nagios service_description Ping check_command check-ping!172.16.0.18 } define service{ use generic-service host_name nagios service_description port_3306 check_command check-tcp!3306 } ###########172.16.0.20################## define service{ use generic-service host_name client1 service_description Load check_command check_nrpe!check_load } define service{ use generic-service host_name client1 service_description Disk check_command check_nrpe!check_disk } define service{ use generic-service host_name client1 service_description memory check_command check_nrpe!check_mem } define service{ use generic-service host_name client1 service_description Ping check_command check-ping!172.16.0.20 } define service{ use generic-service host_name client1 service_description port_3306 check_command check-tcp!3306 }重启nagios服务
[root@nagios objects]# /etc/init.d/nagios restart打开浏览器访问
点击hosts
点击services
ok,我们的配置告一段落了。
出图部分
下载pnp4nagios源码包
安装依赖包
[root@nagios software]# yum install cairo pango perl-rrdtool rrdtool librrds-perl zlib zlib-devel freetype freetype-devel gd gd-devel -y解压pnp4nagios源码包
[root@nagios software]# tar zxf pnp4nagios-0.6.25.tar.gz进入解压后的目录配置png
[root@nagios pnp4nagios-0.6.25]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios编译及安装
[root@nagios pnp4nagios-0.6.25]# make all [root@nagios pnp4nagios-0.6.25]# make install [root@nagios pnp4nagios-0.6.25]# make install-webconf [root@nagios pnp4nagios-0.6.25]# make install-config [root@nagios pnp4nagios-0.6.25]# make install-init [root@nagios pnp4nagios-0.6.25]# cd sample-config/ [root@nagios sample-config]# make install-webconf配置pnp4nagios
[root@nagios sample-config]# cd /usr/local/pnp4nagios/etc/ [root@nagios etc]# mv misccommands.cfg-sample misccommands.cfg [root@nagios etc]# mv rra.cfg-sample rra.cfg [root@nagios etc]# mv nagios.cfg-sample nagios.cfg [root@nagios etc]# cd pages/ [root@nagios pages]# mv web_traffic.cfg-sample web_traffic.cfg [root@nagios pages]# cd ../check_commands/ [root@nagios check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg [root@nagios check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg [root@nagios check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg [root@nagios check_commands]# systemctl enable npcd [root@nagios check_commands]# systemctl start npcd配置Nagios数据输出接口(以BULK模式运行)详情参考官网:
[root@nagios check_commands]# vi /usr/local/nagios/etc/nagios.cfg process_performance_data=1 #默认为0,修改为1 并在该文件中添加下面的内容 # # service performance data # service_perfdata_file=/usr/local/pnp4nagios/var/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 # # host performance data starting with Nagios # host_perfdata_file=/usr/local/pnp4nagios/var/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配置command.cfg
[root@nagios check_commands]# 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 }在模板配置文件中添加图表图标模板:
[root@nagios check_commands]# 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 }在监控主机和服务中调用图表模板(在主机和服务后面添加新的模板):
[root@nagios check_commands]# vi /usr/local/nagios/etc/objects/hosts.cfg 主机内容修改如下 ###########172.16.0.18################## define host { use linux-server,host-pnp host_name nagios alias nagios address 172.16.0.18 check_command check-host-alive max_check_attempts 3 normal_check_interval 2 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options d,u,r contact_groups admins process_perf_data 1 } ###########172.16.0.18################## define host { use linux-server,host-pnp host_name client1 alias client1 address 172.16.0.20 check_command check-host-alive max_check_attempts 3 normal_check_interval 2 retry_check_interval 2 check_period 24x7 notification_interval 300 notification_period 24x7 notification_options d,u,r contact_groups admins process_perf_data 1 } [root@nagios check_commands]# vi /usr/local/nagios/etc/objects/services.cfg 服务内容修改如下 ###########172.16.0.18################## define service{ use generic-service,service-pnp host_name nagios service_description Load check_command check_nrpe!check_load #这里的check_nrpe不是服务端/usr/local/nagios/libexec/check_nrpe,而是command.cfg里定义的命令 } define service{ use generic-service,service-pnp host_name nagios service_description Disk check_command check_nrpe!check_disk } define service{ use generic-service,service-pnp host_name nagios service_description memory check_command check_nrpe!check_mem } define service{ use generic-service,service-pnp host_name nagios service_description Ping check_command check-ping!172.16.0.18 } define service{ use generic-service,service-pnp host_name nagios service_description port_3306 check_command check-tcp!3306 } ###########172.16.0.20################## define service{ use generic-service,service-pnp host_name client1 service_description Load check_command check_nrpe!check_load } define service{ use generic-service,service-pnp host_name client1 service_description Disk check_command check_nrpe!check_disk } define service{ use generic-service,service-pnp host_name client1 service_description memory check_command check_nrpe!check_mem } define service{ use generic-service,service-pnp host_name client1 service_description Ping check_command check-ping!172.16.0.20 } define service{ use generic-service,service-pnp host_name client1 service_description port_3306 check_command check-tcp!3306 }图表展示
重启nagios和apache
访问nagios界面即可看到图表小图标:
点击图标会显示pnp4nagios测试页面:
全是绿色代表配置正常,如果不是全绿,要逐个解决错误。然后移除或修改install.php文件:
再次点击图标就会显示当前监控服务由pnp4nagios生成的图表了