nagios安装:http://note.t4x.org/code/infrastructure-monitoring-nagios-server-config/
pnp4nagios安装:http://note.t4x.org/code/pnp4nagios-rrdtool-config/
本次测试使用:pnp4nagios=0.6.22、nagios=3.5.1、nagios-plugins=2.0.3、nrpe=2.15、RRDtool=1.2.30
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
#!/bin/bash # Author:Byrd # Version:1.0 # Site:note.t4x.org # Contact:root#t4x.org #This script for nagios PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG="en_US.UTF-8" # Check if user is root if [ $UID != "0" ]; then echo "Error: You must be root to run this script, please use root to install lnmp" exit 1 fi clear echo "=========================================================================" echo "nagios" echo "=========================================================================" if [ -f /usr/local/nagios/etc/nagios.cfg ];then cp /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/nagios.cfg.$(date +%F%N) fi if [ `grep "cfg_file=/usr/local/nagios/etc/objects/hosts.cf" /usr/local/nagios/etc/nagios.cfg | wc -l` -eq 0 ];then sed -i "33a cfg_file=/usr/local/nagios/etc/objects/hosts.cfg" /usr/local/nagios/etc/nagios.cfg fi if [ `grep "cfg_file=/usr/local/nagios/etc/objects/hosts.cf" /usr/local/nagios/etc/nagios.cfg | wc -l` -eq 0 ];then sed -i "34a cfg_file=/usr/local/nagios/etc/objects/services.cfg" /usr/local/nagios/etc/nagios.cfg fi sed -i 's#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg#\#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg#g' /usr/local/nagios/etc/nagios.cfg #head -51 /usr/local/nagios/etc/objects/localhost.cfg > /usr/local/nagios/etc/objects/hosts.cfg if [ -f /usr/local/nagios/etc/objects/hosts.cfg ];then cp /usr/local/nagios/etc/objects/hosts.cfg /usr/local/nagios/etc/objects/hosts.cfg.$(date +%F%N) > /usr/local/nagios/etc/objects/hosts.cfg fi if [ -f /usr/local/nagios/etc/objects/services.cfg ];then cp /usr/local/nagios/etc/objects/services.cfg /usr/local/nagios/etc/objects/services.cfg.$(date +%F%N) > /usr/local/nagios/etc/objects/services.cfg fi IP=1.1.1.26,1.1.1.27 for Address in 1.1.1.26 1.1.1.27 do cat >> /usr/local/nagios/etc/objects/hosts.cfg <<HOSTS # Define a host for the local machine define host{ use linux-server check_period 24x7 check_interval 2 retry_interval 1 max_check_attempts 3 notification_period 24x7 notification_interval 2 notification_options d,u,r host_name $Address alias $Address address $Address contact_groups admins # action_url /nagios/pnp/index.php?host=\$HOSTNAME\$&srv=_HOST_ action_url /pnp4nagios/graph?host=\$HOSTNAME\$ } HOSTS for Services in "check_users" "check_load" "check_hda1" "check_zombie_procs" "check_total_procs" do cat >> /usr/local/nagios/etc/objects/services.cfg <<SERVICES define service { use generic-service normal_check_interval 1 retry_check_interval 1 notification_interval 2 notification_options w,u,c,r host_name $IP service_description $Services check_command check_nrpe!$Services # action_url /nagios/pnp/index.php?host=\$HOSTNAME\$&srv=\$SERVICEDESC\$ action_url /pnp4nagios/graph?host=\$HOSTNAME\$&srv=\$SERVICEDESC\$ } SERVICES done done cat >> /usr/local/nagios/etc/objects/hosts.cfg <<By # Define an optional hostgroup for Linux machines define hostgroup{ hostgroup_name linux-servers alias Linux Servers members $IP } By if [ `grep "check_nrpe" /usr/local/nagios/etc/objects/commands.cfg | wc -l` -eq 0 ];then cat >> /usr/local/nagios/etc/objects/commands.cfg <<Rd # Define 'check_nrpe' command definition define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } Rd fi |
nagios安装:http://note.t4x.org/code/infrastructure-monitoring-nagios-server-config/
pnp4nagios安装:http://note.t4x.org/code/pnp4nagios-rrdtool-config/SourceByrd's Weblog-https://note.t4x.org/code/nagios-server-and-define-host-services/
SourceByrd's Weblog-https://note.t4x.org/code/nagios-server-and-define-host-services/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!