设为首页 收藏本站
查看: 883|回复: 0

在nagios中使用nrpe自定义脚本

[复制链接]

尚未签到

发表于 2015-9-8 08:21:02 | 显示全部楼层 |阅读模式
  nrpe的安装
    tar xvfz nrpe-2.13.tar.gz
    cd nrpe-2.13
    ./configure
    make all
    make install-plugin
    make install-daemon
    make install-daemon-config
    yum install xinetd
    make install-xinetd

[iyunv@nhserver2 ~]# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.5.10

[iyunv@nhserver2 ~]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1 192.168.5.10   # 这个IP可以不变,为本机
}

[iyunv@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
[iyunv@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.10    #192.168.5.10为nagios服务器的ip
NRPE v2.12
[iyunv@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110   #192.168.5.110还未开机
Connection refused or timed out
[iyunv@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110   #192.168.5.110开机
CHECK_NRPE: Error - Could not complete SSL handshake.

[iyunv@nhserver2 ~]# service xinetd restart  #重启nrpe服务
=========================================================================================================================
在192.168.5.110被监控端安装nrpe
1.安装nrpe依赖包
yum -y install gcc glibc glibc-common openssl openssl-devel
2.安装nagios-plugin
useradd nagios
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download
tar zxf nagios-plugins-1.4.15.tar.gz && cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chown -R nagios.nagios /usr/local/nagios
3.安装nrpe
wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
tar zxf nrpe-2.12.tar.gz && cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
4.启动nrpe并设置开机自启动
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local


[iyunv@nhserver1 ~]# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.5.10   #将nagios的服务端IP加上

[iyunv@nhserver1 ~]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1 192.168.5.10   #将nagios的服务端IP加上

}
==============  在nagios服务端测试 ====================
[iyunv@nhserver2 ~]#
NRPE v2.12

=================================================================

要在被监控端192.168.5.110加入自定义的脚本
[iyunv@nhserver1 libexec]# vim /usr/local/nagios/libexec/nh_check_users
#!/bin/bash
# for nrpe check user
U=`who | wc -l`
if [ $U -le 3 ];then
echo "OK,current user is.$U"
exit 0
elif [ $U -gt 6 ];then
echo "CRITICAL,current user is.$U"
exit 2
else
echo "WARNING,current user is.$U"
exit 1
fi

  定义该脚本为nagios用户和nagios组
  [iyunv@nhserver1 libexec]# chown nagios.nagios /usr/local/nagios/libexec/nh_check_91

  在NRPE上加入该自定义命令
  [iyunv@nhserver1 libexec]# vim /usr/local/nagios/etc/nrpe.cfg
  command[nh_check_users]=/usr/local/nagios/libexec/nh_check_users
在服务端测试192.168.5.10,直接使用命令行
[iyunv@nhserver2 libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110 -c nh_check_users
OK,current user is.1

=========================================================================
在服务端测试192.168.5.10的nagios中加入自定义脚本
[iyunv@nhserver2 objects]# cd /usr/local/nagios/etc/objects
[iyunv@nhserver2 objects]# vim hosts_192.168.5.110.cfg
define host{
        use                     linux-server
        host_name               192.168.5.110
        alias                   192.168.5.110
        address                 192.168.5.110
        }
define hostgroup{
        hostgroup_name          nh_linuxs
        alias                   nh_linuxs
        members                 192.168.5.110
        }
define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     check-host-alive
        check_command           check-host-alive
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
     }
define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     SSH
        check_command           check_ssh
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        }
define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     check_nrpe_check_users
        check_command           check_nrpe!nh_check_users
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        }
过一下,在nagios中就能观察到check_nrpe_check_users自定义服务的状态了,"OK,current user is.1".
[iyunv@nhserver2 objects]# service nagios reload

Host Sort by host name (ascending)Sort by host name (descending)    Service Sort by service name (ascending)Sort by service name (descending)   
Status Sort by service status (ascending)Sort by service status (descending)    Last Check Sort by last check time (ascending)Sort by last check time
(descending)    Duration Sort by state duration (ascending)Sort by state duration time (descending)    Attempt Sort by current attempt (ascending)Sort by
current attempt (descending)    Status Information
192.168.5.110
   
   
SSH
   
    OK     04-04-2014 20:22:01     0d 0h 1m 56s     1/5     SSH OK - OpenSSH_5.3 (protocol 2.0)
   
check-host-alive
   
    OK     04-04-2014 20:22:50     0d 0h 2m 56s     1/5     PING OK - Packet loss = 0%, RTA = 0.61 ms
   
check_nrpe_check_users
   
    OK     04-04-2014 20:23:38     0d 0h 0m 19s     1/5     OK,current user is.1

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-110770-1-1.html 上篇帖子: redhat--nagios插件--check_traffic.sh 下篇帖子: nagios二次开发(四)---nagios监控原理和nagios架构简介
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表