zoukankan      html  css  js  c++  java
  • 在nagios中使用nrpe自定义脚本

    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


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


    [root@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可以不变,为本机
    }


    [root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H localhost
    NRPE v2.12

    [root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.10    #192.168.5.10为nagios服务器的ip
    NRPE v2.12

    [root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110   #192.168.5.110还未开机
    Connection refused or timed out

    [root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110   #192.168.5.110开机
    CHECK_NRPE: Error - Could not complete SSL handshake.


    [root@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




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


    [root@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服务端测试 ====================
    [root@nhserver2 ~]#
    NRPE v2.12


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


    要在被监控端192.168.5.110加入自定义的脚本

    [root@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组

    [root@nhserver1 libexec]# chown nagios.nagios /usr/local/nagios/libexec/nh_check_91

    在NRPE上加入该自定义命令

    [root@nhserver1 libexec]# vim /usr/local/nagios/etc/nrpe.cfg

    command[nh_check_users]=/usr/local/nagios/libexec/nh_check_users

    在服务端测试192.168.5.10,直接使用命令行
    [root@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中加入自定义脚本
    [root@nhserver2 objects]# cd /usr/local/nagios/etc/objects

    [root@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".
    [root@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

  • 相关阅读:
    每日练习
    AttributeError: module 'torch.jit' has no attribute 'get_trace_graph
    2020.3-SEAN: Image Synthesis with Semantic Region-Adaptive Normalization
    2019-11-DHAN~Towards Ghost-free Shadow Removal via Dual Hierarchical Aggregation Network and Shadow Matting GAN
    2020.2-DMFN-Image Fine-grained Inpainting
    Face completion with Hybrid Dilated Convolution
    FCSR-GAN: Joint Face Completion and Super-resolution via Multi-task Learning
    Joint Face Completion and Super-resolution using Multi-scale Feature Relation Learning
    浮点数转化为字符串
    Sublime Text2使用技巧
  • 原文地址:https://www.cnblogs.com/nhlinkin/p/3645951.html
Copyright © 2011-2022 走看看