Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1154731
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: Python/Ruby

2014-04-27 22:27:38


nagios监控绘图之一键安装pnp4nagios脚本
     很多公司,有时候总是要你搭建个监控用来监控机器,就这样一次又一次的搭建,要知道重复性的工作越干越没有劲,于是我就写个脚本,下次安装时就一次生成,这一篇是关于pnp4nagios一键安装脚本,可以在新安装的机器运行,也可以重复性执行。如果要安装cacti和npc的话,把cacti_npc.sh和该脚本放在一起执行就就行了。其中cacti_npc.sh脚本内容:http://blog.chinaunix.net/uid-25046147-id-4228848.html
 
系统测试版本:Centos release 5.5


点击(此处)折叠或打开

  1. #/bin/bash/
  2. ##Auther Gavin
  3. ##Mail wkgbc456@163.com
  4. #Blog http://wkgbc.blog.chinaunix.net/

  5. NSTALL_LOG=/tmp/install_log
  6. NPREFIX=/var/www/html/nagios
  7. PNPPATH=/var/www/html/pnp4nagios

  8. read -p read -p "You select fist install,Input F,Reinstall Input R,Uinstall Input U,exit Input other... " INSTALL
  9. case $INSTALL in
  10. f|F)
  11.   echo -e "Starting install ....."
  12.  ;;
  13. r|R)
  14. /etc/init.d npcd stop
  15. /etc/init.d nagios stop
  16. rm -rf $PNPPATH
  17. rm -rf /etc/init.d/npcd
  18. rm -rf /etc/httpd/conf.d/pnp4nagios.conf
  19. cp $NPREFIX/etc/{nagios.cfg.pnp_bak,nagios.cfg}
  20. cp $NPREFIX/etc/{command.cfg.pnp_bak,command.cfg}
  21. cp $NPREFIX/etc/objects/{templates.cfg.pnp_bak,templates.cfg}
  22. cp $NPREFIX/etc/objects/{localhost.pnp_bak,localhost,cfg}
  23. /etc/init.d/nagios reload
  24. /etc/init.d/httpd reload
  25.  ;;
  26. u|U)
  27. rm -rf /var/www/html/pnp4nagios
  28. rm -rf /etc/init.d/npcd
  29. rm -rf /etc/httpd/conf.d/pnp4nagios.conf
  30. cp $NPREFIX/etc/{nagios.cfg.pnp_bak,nagios.cfg}
  31. cp $NPREFIX/etc/{command.cfg.pnp_bak,command.cfg}
  32. cp $NPREFIX/etc/objects/{templates.cfg.pnp_bak,templates.cfg}
  33. cp $NPREFIX/etc/objects/{localhost.pnp_bak,localhost,cfg}
  34. /etc/init.d/nagios reload
  35. /etc/init.d/httpd reload
  36. exit 0
  37.   ;;
  38. *)
  39.   exit 2
  40.   ;;
  41. esac

  42. if [ -f pnp4nagios-0.6.21.tar.gz ];then
  43. tar xvf pnp4nagios-0.6.21.tar.gz
  44. cd pnp4nagios-0.6.21
  45. make clean
  46. ./configure --prefix=/var/www/html/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagcmd --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
  47.  [ $? == "0" ] && make all || exit;
  48.  [ $? == "0" ] && make install || exit;
  49.  [ $? == "0" ] && make install-webconf || exit;
  50.  [ $? == "0" ] && make install-config || exit;
  51.  [ $? == "0" ] && make install-init || exit;
  52. cd ..
  53. mv $PNPPATH/share/{install.php,install.php.bak}
  54. cp $PNPPATH/etc/{misccommands.cfg-sample,misccommands.cfg}
  55. cp $PNPPATH/etc/{nagios.cfg-sample,nagios.cfg}
  56. cp $PNPPATH/etc/{rra.cfg-sample,rra.cfg}
  57. cp $PNPPATH/etc/check_commands/{check_nwstat.cfg-sample,check_nwstat.cfg}
  58. cp $PNPPATH/etc/check_commands/{check_all_local_disks.cfg-sample,check_all_local_disks.cfg}
  59. chown nagios:nagcmd ./* -R

  60. chkconfig npcd on

  61. ###############Mody nagios.cfg
  62. cp $NPREFIX/etc/{nagios.cfg,nagios.cfg.pnp_bak}
  63. cp $NPREFIX/etc/{command.cfg,command.cfg.pnp_bak}
  64. cp $NPREFIX/etc/objects/{templates.cfg,templates.cfg.pnp_bak}
  65. cp $NPREFIX/etc/objects/{localhost.cfg,localhost.pnp_bak}
  66. sed -i 's@process_performance_data=0@process_performance_data=1@g' $NPREFIX/etc/nagios.cfg
  67. sed -i 's@#host_perfdata_command=process-host-perfdata@host_perfdata_command=process-host-perfdata@g' $NPREFIX/etc/nagios.cfg
  68. sed -i 's@#service_perfdata_command=process-service-perfdata@service_perfdata_command=process-service-perfdata@g' $NPREFIX/etc/nagios.cfg


  69. cat >>$NPREFIX/etc/objects/commands.cfg<<EOF
  70. define command {
  71.       command_name process-service-perfdata
  72.       command_line /usr/bin/perl $PNPPATH/libexec/process_perfdata.pl
  73. }
  74. define command {
  75.       command_name process-host-perfdata
  76.       command_line /usr/bin/perl $PNPPATH/libexec/process_perfdata.pl -d HOSTPERFDATA
  77. }
  78. EOF

  79. cat >>$NPREFIX/etc/objects/templates.cfg<<EOF
  80. define host {
  81. name host-pnp
  82. action_url /pnp4nagios/index.php/graph?host=\$HOSTNAME$&srv=_HOST_
  83. register 0
  84. }
  85. define service {
  86. name srv-pnp
  87. action_url /pnp4nagios/index.php/graph?host=\$HOSTNAME$&srv=\$SERVICEDESC$
  88. register 0
  89. }
  90. EOF

  91. else
  92.   echo "The Pnp4nagios isn't..." >>$INSTALL_LOG
  93. fi

  94. ################mody pnp4nagios.conf######

  95. sed -i 's@/usr/local/nagios/@'$NPREFIX/'@g' /etc/httpd/conf.d/pnp4nagios.conf

  96. ################Add Server GUI###############
  97.  sed -i 's@local-service@local-service,srv-pnp@g' $NPREFIX/etc/objects/localhost.cfg
  98.  sed -i '1,40 s@linux-server@linux-server,host-pnp@g' $NPREFIX/etc/objects/localhost.cfg

  99. /etc/init.d/httpd restart
  100. /etc/init.d/npcd restart
  101. /etc/init.d/nagios restart

  102. bash cacti_npc.sh;




其他一键安装脚本,测试系统Centos 5.5

点击(此处)折叠或打开

  1. cacti与npc一键安装脚本链接:http://blog.chinaunix.net/uid-25046147-id-4228848.html

  2. nagios一键安装脚本:http://blog.chinaunix.net/uid-25046147-id-4228845.html

  3. nrpe一键安装:http://blog.chinaunix.net/uid-25046147-id-4228843.html

  4. pnp4nagios一键安装脚本:http://blog.chinaunix.net/uid-25046147-id-4228835.html

  5. 一键安装LAMP:http://blog.chinaunix.net/uid-25046147-id-4226114.html



阅读(3475) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

随风飘云2015-02-10 15:45:38

参考文档:http://docs.pnp4nagios.org/pnp-0.6/webfe

file [line]:
application/models/data.php [148]:
back
解决:
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$&

随风飘云2014-04-27 22:28:01

文明上网,理性发言...