惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - 菲一打

【转】Linux从入门到精通——运维工程师成长路线图——CTO马哥Linux视频教学 【转】 要做linux运维工程师的朋友,必须要掌握以下几个工具才行 【转】Linux shell笔记 【转】Linux上vi(vim)编辑器使用教程 无法远程连接SQLSERVER2000的解决方法 Python类的__getitem__和__setitem__特殊方法 让Python支持中文注释 【转】python入门指引 【转】布同:如何循序渐进学习Python语言 在nagios中监控windows主机系统地址的状态 nagios中监测dns 227.7.128.68的网络状态 【转】新手该如何学python怎么学好python? 在nagios中使用python脚本监控linux主机 【转】手游公司运维之从一个人运维到运维主管 【转】VMware 克隆 Linux 系统后找不到 eth0 网卡问题 【转】sed & awk常用正则表达式 【转】Linux 服务器安全配置 【转】shell脚本实现多台服务器自动巡检--可参考学习 【转】nagios 命令解释
在nagios中使用nrpe自定义脚本
菲一打 · 2014-04-04 · via 博客园 - 菲一打

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