2013年4月2日星期二

Nagios

Define User
# 先定义user
define contact{
        contact_name   A
        alias   A
        email   A.test.com
        address1      112312312315
        host_notifications_enabled     1
        host_notification_options       d,u,r,f,s
        host_notification_period        24x7
        host_notification_commands      notify-host-by-email,notify-by-sms
        service_notifications_enabled         1
        service_notification_period     24x7
        service_notification_options    w,u,c,r,f,s
        service_notification_commands   notify-service-by-email,notify-by-sms
        }

# 把user加入到 group
define contactgroup {
        contactgroup_name vip
        members A
}

# 服务中定义
# Define CheckTCP8080
define service {
use centos-service
host_name 192.168.1.29
service_description CheckTCP8080
check_command check_tcp!8080
normal_check_interval 2
contact_groups vip
notifications_enabled 1
}

客户端
# Nagios 报警
yum install openssl-devel
# Add User 新建该用户的时候 自动建立 id 为 1200 的 组
useradd -M -u 1101 -s /sbin/nologin nagios
# Install nrpe-2.13
cd /usr/local/src
wget http://www.myciscolab.net/sources/nrpe-2.13.tar.gz
tar xzvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios --enable-command-args
make all && make install-plugin && make install-daemon && make install-daemon-config && make install-xinetd
# Install nagios-plugins
cd /usr/local/src
wget http://www.myciscolab.net/sources/nagios-plugins-1.4.11.tar.gz
tar xzvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make && make install
# 配置文件 /usr/local/nagios/etc/nrpe.cfg
echo '' > /usr/local/nagios/etc/nrpe.cfg
echo 'log_facility=daemon' >> /usr/local/nagios/etc/nrpe.cfg
echo 'pid_file=/var/run/nrpe.pid' >> /usr/local/nagios/etc/nrpe.cfg
echo 'server_port=5666' >> /usr/local/nagios/etc/nrpe.cfg
echo 'nrpe_user=nagios' >> /usr/local/nagios/etc/nrpe.cfg
echo 'nrpe_group=nagios' >> /usr/local/nagios/etc/nrpe.cfg
echo 'allowed_hosts=127.0.0.1' >> /usr/local/nagios/etc/nrpe.cfg
echo 'dont_blame_nrpe=1' >> /usr/local/nagios/etc/nrpe.cfg
echo 'debug=0' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command_timeout=60' >> /usr/local/nagios/etc/nrpe.cfg
echo 'connection_timeout=300' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -s Z' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_memory]=/usr/local/nagios/libexec/check_memory -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_users]=/usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_dns]=/usr/local/nagios/libexec/check_dns -H $ARG1$ -s $ARG2$ -a $ARG3$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
# 下载Check脚本
# 脚本 check_memory
cd /usr/local/nagios/libexec/
wget http://www.myciscolab.net/sources/check_memory
chmod a+x /usr/local/nagios/libexec/check_memory
# Modify nrpe access ips
sed -i -e "s/127.0.0.1/127.0.0.1\ 192.168.199.1\ 192.168.200.1\ 211.103.199.27/g" /etc/xinetd.d/nrpe
#
echo 'nrpe 5666/tcp # nrpe' >> /etc/services
# Restart Server
service xinetd restart



服务器端配置 Client监控
# nagios 服务器端配置
define host{
        use centos-host
        host_name       192.168.199.10_n1.lb.l99.com
        alias n1.lb.l99.com
        address 192.168.199.10
        }

# Define CheckPing
define service{
        use                             centos-service
        host_name                       192.168.199.10_n1.lb.l99.com
        service_description             CheckPing
        check_command                   check_ping!100.0,20%!500.0,60%
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}
# Define CheckSSHD6022
define service{
        use     centos-service
        host_name    192.168.199.10_n1.lb.l99.com
        service_description     CheckSSHD6022
        check_command   check_tcp!6022
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}                                                       #
# Define CheckMemory
define service{
        use centos-service
        host_name  192.168.199.10_n1.lb.l99.com
        service_description CheckMemory
        check_command check_nrpe2!check_memory!80!90
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1     
}

# Define CheckLoad
define service{
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckLoad
        check_command check_nrpe2!check_load!15,10,5!30,25,20
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}

# Define CheckDiskRoot
define service{
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckDiskRoot
        check_command check_nrpe3!check_disk!30%!15%!/
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1     
}

# Define CheckDiskNginxLog     _               
define service{
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckDiskNginx_log
        check_command check_nrpe3!check_disk!30%!15%!/nginx_log
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 0
}

# Define CheckSwap
define service {
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckSwap
        check_command check_nrpe2!check_swap!98%!80%
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}

# Define CheckActiveUsers
define service {
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckActiveUsers
        check_command check_nrpe2!check_users!1!3
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 0
}

# Define CheckZombieProcs
define service {
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckZombieProcess
        check_command check_nrpe2!check_zombie_procs!1!4             
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}

自定义命令
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/php /bin/phpmail $CONTACTEMAIL$ "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" `/usr/bin/printf "%b" "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info: $SERVICEOUTPUT$ "` /bin/1.txt
        }

没有评论:

发表评论