AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[nrpe](server)

Martin Hope
donmelchior
Asked: 2021-10-23 05:50:21 +0800 CST

如何在基于 Powershell 脚本的 check_nrpe 结果中正确显示重音字符?

  • 0

我有一个由 Nagios 使用“check_nrpe”调用的自定义 Powershell 脚本。目前在 Nagios 上显示检查结果时,所有带有特殊字符(如“è”、“é”或“à”的检查结果输出消息都无法正确显示。

如何让那些正确显示?

检查命令

$USER1$/check_nrpe  -H server.tld -c check_foo -a 7 7 7  

nsclient.ini 上的脚本调用

[/settings/external scripts/scripts]
check_foo = cmd /c echo X:\scripts_\check-foo.ps1 -arg1 "$ARG1$" -arg2 "$ARG2$" -arg3 "$ARG3$"; exit($lastexitcode) | powershell.exe -command -

预期结果

CRITICAL - Vérification échouée

实际结果

# UTF-8 BOM (GUI)
CRITICAL - Vrification choue

# UTF-8 BOM (CLI)
CRITICAL - V,rification ,choue,

# UTF-8 (GUI)
CRITICAL - VǸrification ǸchoueǸ 

目前,我的 Powershell 脚本是从 Linux CentOS 7 监控机器和目标服务器(Windows 2016 Server)上的 NSClient++ 远程调用的“check_nrpe”。脚本 itelf 被编码为“UTF-8 BOM”。

powershell nagios nrpe nsclient++
  • 2 个回答
  • 101 Views
Martin Hope
MOBIN TM
Asked: 2020-10-31 22:01:26 +0800 CST

Nagios 服务器未检测客户端 vm 是否已重新启动

  • 0

我已经配置了 nagios 服务器并添加了 30+ 个物理服务器和 25+ 个虚拟机。所有配置已完成,nagios 服务器正在监视服务器、vm 和服务。

但是当我重新启动一个 vm 时,Nagios 服务器没有检测到 vm 不可用,而是在线显示。

有人遇到过这个问题吗?有人可以帮忙吗?

nagios nrpe
  • 1 个回答
  • 358 Views
Martin Hope
JadenBZH
Asked: 2020-09-05 01:12:56 +0800 CST

自从 debian 升级后,一个 check_nrpe 命令在 nagios 服务器上不起作用

  • 1

昨天我将一个服务器从 Debian 9 升级到 Debian 10。这个服务器由 nagios 监督。自升级以来,我收到一个警报,状态未知:

“卷组数组 03-0 无效或未使用“-v 卷组”指定,再见。假

该服务是 VG array03-0 用法,它的命令是 check_nrpe!check_vgs_array03-0。此服务的目标是在阵列上的存储快满时生成警报。

check_nrpe 命令是标准的:

# 'check_NRPE' command definition
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

如果我没记错的话,这意味着我在受监督服务器上的 /etc/nagios/nrpe.cfg 中有一个 check_vgs_array03-0 命令。让我们看一下,这里是:

命令[check_vgs_array03-0]=/usr/lib/nagios/plugins/check_vg_size -w 20 -c 10 -v array03-0

如果我只是在受监督的服务器上键入此命令,我没有错误,它可以工作。

VG array03-0 OK 可用空间为 805 GB;| 数组03-0=805GB;20;10;0;19155

例如,如果我输入了一个不存在的卷组名称,我就会收到错误消息。

check_vg_size 插件脚本是这样的:

#!/bin/bash
#check_vg_size
#set -x
# Plugin for Nagios
# Written by M. Koettenstorfer ([email protected])
# Some additions by J. Schoepfer ([email protected])
# Major changes into functions and input/output values J. Veverka ([email protected])
# Last Modified: 2012-11-06
#
# Description:
#
# This plugin will check howmany space in volume groups is free

# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

SERVICEOUTPUT=""
SERVICEPERFDATA=""

PROGNAME=$(basename $0)

vgs_bin=`/usr/bin/whereis -b -B /sbin /bin /usr/bin /usr/sbin -f vgs | awk '{ print $2 }'`
_vgs="$vgs_bin --units=g"

bc_bin=`/usr/bin/whereis -b -B /sbin /bin /usr/bin /usr/sbin -f bc | awk '{ print $2 }'`

exitstatus=$STATE_OK #default
declare -a volumeGroups;
novg=0; #number of volume groups
allVG=false; #Will we use all volume groups we can find on system?
inPercent=false; #Use percentage for comparison?

unitsGB="GB"
unitsPercent="%"
units=$unitsGB

########################################################################
### DEFINE FUNCTIONS
########################################################################

print_usage() {
        echo "Usage: $PROGNAME  -w <min size warning level in gb> -c <min size critical level in gb> -v <volumegroupname> [-a] [-p]"
        echo "If '-a' and '-v' are specified: all volumegroups defined by -v will be ommited and the remaining groups which are found on system are checked"
        echo "If '-p' is specified: the warning and critical levels are represented as the percent space left on device"
    echo ""
}

print_help() {
        print_usage
        echo ""
        echo "This plugin will check how much space is free in volume groups"
        echo "usage: "
        exit $STATE_UNKNOWN
}


checkArgValidity () {
# Check arguments for validity
        if [[ -z $critlevel || -z $warnlevel ]] # Did we get warn and crit values?
        then
                echo "You must specify a warning and critical level"
                print_usage
                exitstatus=$STATE_UNKNOWN
                exit $exitstatus
        elif [ $warnlevel -le $critlevel ] # Do the warn/crit values make sense?
        then
        if [ $inPercent != 'true' ]
        then
            echo "CRITICAL value of $critlevel GB is less than WARNING level of $warnlevel GB"
            print_usage
            exitstatus=$STATE_UNKNOWN
            exit $exitstatus
        else
            echo "CRITICAL value of $critlevel % is higher than WARNING level of $warnlevel %"
            print_usage
            exitstatus=$STATE_UNKNOWN
            exit $exitstatus
        fi
        fi
}

#Does volume group actually exist?
volumeGroupExists () {
        local volGroup="$@"
        VGValid=$($_vgs 2>/dev/null | grep "$volGroup" | wc -l )

        if [[  -z "$volGroup" ||  $VGValid = 0 ]]
        then
                echo "Volumegroup $volGroup wasn't valid or wasn't specified"
                echo "with \"-v Volumegroup\", bye."
                echo false
                return 1
        else
                #The volume group exists
                echo true
                return 0
        fi
}

getNumberOfVGOnSystem () {
        local novg=$($_vgs 2>/dev/null | wc -l)
        let novg--
        echo $novg
}

getAllVGOnSystem () {
        novg=$(getNumberOfVGOnSystem)
        local found=false;
        for (( i=0; i < novg; i++)); do
                volumeGroups[$i]=$($_vgs | tail -n  $(($i+1)) | head -n 1 | awk '{print $1}')
                found=true;
        done
        if ( ! $found ); then
                echo "$found"
                echo "No Volumegroup wasn't valid or wasn't found"
                exit $STATE_UNKNOWN
        fi
}

getColumnNoByName () {
        columnName=$1
        result=$($_vgs 2>/dev/null | head -n1 | awk -v name=$columnName '
                BEGIN{}
                        { for(i=1;i<=NF;i++){
                              if ($i ~ name)
                                  {print i } }
                        }')

        echo $result
}

convertToPercent () {
#$1 = xx%
#$2 = 100%
    # Make values numbers only
        local input="$(echo $1 | sed 's/g//i')"
        local max="$(echo $2 | sed 's/g//i')"
        local onePercent='';
        local freePercent='';
        if [ -x "$bc_bin" ] ; then
                onePercent=$( echo "scale=2; $max / 100" | bc );
                freePercent=$( echo "$input / $onePercent" | bc );
        else
                freePercent=$(perl -e "print int((($max-$input)*100/$max))")
        fi
        echo $freePercent;
        return 0;
}

getSizesOfVolume () {
        volumeName="$1";
        #Check the actual sizes
        cnFree=`getColumnNoByName "VFree"`;
        cnSize=`getColumnNoByName "VSize"`;
        freespace=`$_vgs $volumeName 2>/dev/null | awk -v n=$cnFree '/[0-9]/{print $n}' | sed -e 's/[\.,\,].*//'`;
        fullspace=`$_vgs $volumeName 2>/dev/null | awk -v n=$cnSize '/[0-9]/{print $n}' | sed -e 's/[\.,\,].*//'`;

        if ( $inPercent ); then
        #Convert to Percents
                freespace="$(convertToPercent $freespace $fullspace)"
        fi
}

setExitStatus () {
        local status=$1
        local volGroup="$2"
        local formerStatus=$exitstatus

        if [ $status -gt $formerStatus ]
        then
                formerStatus=$status
        fi

        if [ $status = $STATE_UNKNOWN ] ; then
                SERVICEOUTPUT="${volGroup}"
                exitstatus=$STATE_UNKNOWN
                return
        fi

        if [ "$freespace" -le "$critlevel" ]
        then
                SERVICEOUTPUT=$SERVICEOUTPUT" VG $volGroup CRITICAL Available space is $freespace $units;"
                exitstatus=$STATE_CRITICAL
        elif [ "$freespace" -le "$warnlevel" ]
        then
                SERVICEOUTPUT=$SERVICEOUTPUT"VG $volGroup WARNING Available space is $freespace $units;"
                exitstatus=$STATE_WARNING
        else
                SERVICEOUTPUT=$SERVICEOUTPUT"VG $volGroup OK Available space is $freespace $units;"
                exitstatus=$STATE_OK
        fi

        SERVICEPERFDATA="$SERVICEPERFDATA $volGroup=$freespace$units;$warnlevel;$critlevel"
        if [ $inPercent != 'true' ] ; then

                SERVICEPERFDATA="${SERVICEPERFDATA};0;$fullspace"
        fi

        if [ $formerStatus -gt $exitstatus ]
        then
                exitstatus=$formerStatus
        fi
}


checkVolumeGroups () {
checkArgValidity
        for (( i=0; i < novg; i++ )); do
                local status="$STATE_OK"
                local currentVG="${volumeGroups[$i]}"

                local groupExists="$(volumeGroupExists "$currentVG" )"

                if [ "$groupExists" = 'true' ]; then
                        getSizesOfVolume "$currentVG"
                        status=$STATE_OK
                else
                        status=$STATE_UNKNOWN
                        setExitStatus $status "${groupExists}"
                        break
                fi

                setExitStatus $status "$currentVG"
        done
}

########################################################################
### RUN PROGRAM
########################################################################


########################################################################
#Read input values
while getopts ":w:c:v:h:ap" opt ;do
        case $opt in
                h)
                        print_help;
                        exit $exitstatus;
                        ;;
                w)
                        warnlevel=$OPTARG;
                        ;;
                c)
                        critlevel=$OPTARG;
                        ;;
                v)
                        if ( ! $allVG ); then
                                volumeGroups[$novg]=$OPTARG;
                                let novg++;
                        fi
                        ;;
                a)
                        allVG=true;
                        getAllVGOnSystem;
                        ;;
                p)
                        inPercent=true;
                        units=$unitsPercent
                        ;;
                \?)
                        echo "Invalid option: -$OPTARG" >&2
                        ;;
        esac
done

checkVolumeGroups


echo $SERVICEOUTPUT"|"$SERVICEPERFDATA
exit $exitstatus

II 对 check_nrpe 命令使用另一个 arg(另一个脚本),它可以工作。

例如 :

root@nagiosserver:/usr/local/nagios# /usr/local/nagios/libexec/check_nrpe -H srv-supervised04 -c check_load OK - 平均负载:3.79, 2.99, 1.83|load1=3.790;25.000;30.000;0; 负载5=2.990;20.000;25.000;0; 负载15=1.830;15.000;20.000;0;

VG array03-0 确实存在:

root@srv-supervised04:/usr/lib/nagios/plugins# vgdisplay --- Volume group --- VG Name array03-0 System ID Format
lvm2 Metadata Areas 1 Metadata Sequence No 34 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 4 Max PV
0 Cur PV 1 Act PV 1 VG Size
<18,71 TiB PE Size 4,00 MiB Total PE
4903887 Alloc PE / Size 4697600 / <17,92 TiB Free PE / Size 206287 / < 805,81 GiB VG UUID
OgzAMF-DGbW-3t3L-Wk7k-gY1g-s6fH-zYEKad

所以。VG确实存在。check_vg_size 插件在本地使用时工作,check_nrpe 命令在与另一个插件一起使用时在 nagios 服务器上工作,但 check_vg_size 在 nagios 服务器上不起作用。错误消息显然是 array03-0 在它存在时不存在。我没有更改所有文件中的任何内容。它出现在 Debian 从 9 到 10 的更新中(在安装过程中,我决定保留我的 nrpe.cfg 修改文件)。

有谁知道它可以从哪里来?Debian 版本?也许是新的 bash 版本?nagios 服务器(仍然是 Debian 9)和受监督的服务器(Debian 10)之间不兼容?

debian nagios upgrade nrpe
  • 1 个回答
  • 266 Views
Martin Hope
nonely
Asked: 2020-02-07 02:11:29 +0800 CST

Nagios - 在同一服务上检查 procs 和 --metric=elapsed

  • 0

在网上工作和搜索了很多天之后,我将作为最后的帮助机会回复您。我实际上正在使用带有 nrpe 的 nagios core 4.4.3 监视 unix 进程。

我的目标是检查:使用命令“java”的确切 1 个进程从最多 23 小时开始运行,仅使用一项服务

这个过程每天都会重新开始。

低于我在 client_host (/etc/nagios/nrpe.cfg) 上的内容:

command[check_java]=/usr/lib64/nagios/plugins/check_procs  -c 1:1  -C java
command[check_java_elapsed]=/usr/lib64/nagios/plugins/check_procs  -c :82800 --metric=ELAPSED  -C java

在服务器上(/usr/local/nagios/etc/client_host.cfg):

define service{
          use                     generic-service
          host_name               client_host
          service_description     java_elapsed
          check_command           check_nrpe!check_java
          check_period                    24x7
          max_check_attempts              3
          normal_check_interval           1
          retry_check_interval            2
}
define service{
          use                     generic-service
          host_name               client_host
          service_description     perl_elapsed
          check_command           check_nrpe!check_java_elapsed
          check_period                    24x7
          max_check_attempts              3
          normal_check_interval           1
          retry_check_interval            2
}

总而言之,我想将这两种服务结合在一个服务中

java monitoring nagios metrics nrpe
  • 1 个回答
  • 325 Views
Martin Hope
Gaurav
Asked: 2016-08-16 23:41:44 +0800 CST

Check_nrpe 无法读取脚本的输出

  • 0

脚本在服务器:

#!/bin/bash


如果 [ !$# == 1]; 然后
echo "使用 check_cluster"
菲;
clu_srv=$1
错误=“停止”
错误1 =“禁用”
error2="可恢复"
host1=`sudo /usr/sbin/clustat|grep $1| awk {'打印 $2'}`
host2=`sudo /usr/sbin/clustat|grep $1| awk {'打印 $3'}`
service1=`sudo /usr/sbin/clustat|grep $clu_srv| awk {'打印 $1'}`
如果 [[ "$host2" == "$error" ]] || [[ "$host2" == "$error1" ]]; 然后
echo "CRITICAL - $host1 上的集群 $clu_srv 服务故障转移,状态为 '$host2'"
别的
echo "OK - 集群 $clu_srv 服务在 $host1 上,状态为 '$host2'"
菲;

##--EndScript


它正确地从脚本接收你的参数。当我从命令行在服务器上手动运行此脚本时,它会返回正确的信息,例如:

# /usr/local/nagios/libexec/check_rhcs-ERS NFSService
好的 - 集群 NFSService 服务在 NODE1 上,状态为“已启动”

但是,当我使用以下命令远程尝试使用脚本(check_nrpe)时,它显示的信息不正确:

# ./check_nrpe -H localhost -c check_rhcs-ERS
好的 - 集群 NFSService 服务已开启且状态为“”

nrpe.cfg:

# 命令[check_rhcs-ERS]=/usr/local/nagios/libexec/check_rhcs-ERS NFSService

脚本有什么问题,如何解决?

linux redhat nagios nrpe
  • 2 个回答
  • 813 Views
Martin Hope
span
Asked: 2014-12-19 02:19:50 +0800 CST

nrpe.d 订单包含哪些内容?

  • 2

我正在运行以下版本的 nagios-nrpe-server:

nagios-nrpe-server: Installed: 2.12-5ubuntu1.2 Candidate: 2.12-5ubuntu1.2 Version table: *** 2.12-5ubuntu1.2 0 500 http://se.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages 100 /var/lib/dpkg/status 2.12-5ubuntu1 0 500 http://se.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

我正在尝试在/etc/nagios/nrpe.d/文件夹中包含多个文件。这些文件被命名为:

1.base.cfg 2.overrides.cfg

我的 nrpe.cfg 文件中的最后一个条目是:include_dir=/etc/nagios/nrpe.d/

基本文件包含一些我希望在覆盖文件中覆盖的命令。然而,似乎覆盖并不总是有效。在某些服务器上,首先加载覆盖文件。

NRPE 不支持这种类型的覆盖吗?

nrpe
  • 1 个回答
  • 2530 Views
Martin Hope
Itai Ganot
Asked: 2014-12-03 05:20:01 +0800 CST

NRPE:`only_from` 指令和`allowed_hosts` 有什么区别,NRPE 更喜欢哪一个?

  • 1

我看到两个不同的地方可以配置我的 NRPE 客户端将与哪个 Nagios 服务器通信。

第一个,同时配置 NRPE 在 xinetd 下运行:

only_from       = 127.0.0.1 mon1.company.com

第二个,在/etc/nagios/nrpe.cfg文件中:

allowed_hosts=127.0.0.1,mon1.company.com

我的问题是:

  1. 万一两者都已配置 (nrpe.cfg和xinetd/nrpe) - 哪个配置更强?意思是,哪一个会覆盖另一个?
  2. 如果它们不相互覆盖,是否应该同时配置它们?
nrpe
  • 1 个回答
  • 1178 Views
Martin Hope
the-wabbit
Asked: 2013-11-12 13:05:16 +0800 CST

NSClient++:带有可选参数的外部脚本

  • 2

我正在尝试定义一个外部脚本,该脚本将在 Windows 上的 NSClient++ 0.4.1 中采用可选参数。按照nsclient-full.ini我定义的示例代码

mycheck=cmd /C echo C:\mydir\myscript.ps1 %ARGS% | powershell.exe -command -

%ARGS%它只是产生作为唯一参数传递给myscript.ps1的字符串,无论我在通过 NRPE 的调用中指定什么(check_nrpe如果重要的话,使用 Nagios)。然后我尝试将定义重写为

mycheck=cmd /C echo C:\mydir\myscript.ps1 $ARG1$ $ARG2$ | powershell.exe -command -

(myscript.ps1最多需要两个参数),这确实有点帮助。至少,如果提供了两个参数,我可以通过args[]数组获取它们。当调用的参数少于两个时,麻烦就开始了——在这种情况下,文字字符串$ARG2和$ARG1$作为参数传递。在myscript.ps1的代码中处理这种情况会使整个参数处理例程变得丑陋。

如果没有指定参数,是否有一种合理的方法可以为外部脚本定义可选参数,该脚本不会传递 NSClient 的变量名?

nrpe
  • 1 个回答
  • 8735 Views
Martin Hope
user125483
Asked: 2012-06-27 20:38:47 +0800 CST

nagios NRPE:无法读取输出

  • 0

我目前设置了一个脚本来重新启动我的 http 服务器 + php5 fpm,但无法让它工作。我已经用谷歌搜索并发现大部分权限是我的错误问题但无法弄清楚。

我开始使用我的脚本

/usr/lib/nagios/plugins/check_nrpe -H bart -c restart_http

这是我要重新启动的节点上系统日志中的输出

 Jun 27 06:29:35 bart nrpe[8926]: Connection from 192.168.133.17 port 25028
    Jun 27 06:29:35 bart nrpe[8926]: Host address is in allowed_hosts
    Jun 27 06:29:35 bart nrpe[8926]: Handling the connection...
    Jun 27 06:29:35 bart nrpe[8926]: Host is asking for command 'restart_http' to be run...
    Jun 27 06:29:35 bart nrpe[8926]: Running command: /usr/bin/sudo /usr/lib/nagios/plugins/http-restart
    Jun 27 06:29:35 bart nrpe[8926]: Command completed with return code 1 and output: 
    Jun 27 06:29:35 bart nrpe[8926]: Return Code: 1, Output: NRPE: Unable to read output
    Jun 27 06:29:35 bart nrpe[8926]: Connection from 192.168.133.17 closed.

如果我自己运行命令,它运行良好(但要求输入密码)(nagios 用户)

这是脚本权限和脚本内容。

-rwxrwxrwx 1 nagios nagios 142 Jun 26 21:41 /usr/lib/nagios/plugins/http-restart

#!/bin/bash
echo "ok" 
/etc/init.d/nginx stop  
/etc/init.d/nginx start 
/etc/init.d/php5-fpm stop 
/etc/init.d/php5-fpm start
echo "done"

我还将这一行添加到 visudo

nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/

我本地的nagios nrpe.cfg

#############################################################################
# Sample NRPE Config File 
# Written by: Ethan Galstad ([email protected])
# 
#
# NOTES:
# This is a sample configuration file for the NRPE daemon.  It needs to be
# located on the remote host that is running the NRPE daemon, not the host
# from which the check_nrpe client is being executed.
#############################################################################


# LOG FACILITY
# The syslog facility that should be used for logging purposes.

log_facility=daemon



# PID FILE
# The name of the file in which the NRPE daemon should write it's process ID
# number.  The file is only written if the NRPE daemon is started by the root
# user and is running in standalone mode.

pid_file=/var/run/nagios/nrpe.pid



# PORT NUMBER
# Port number we should wait for connections on.
# NOTE: This must be a non-priviledged port (i.e. > 1024).
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

server_port=5666



# SERVER ADDRESS
# Address that nrpe should bind to in case there are more than one interface
# and you do not want nrpe to bind on all interfaces.
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

#server_address=127.0.0.1



# NRPE USER
# This determines the effective user that the NRPE daemon should run as.  
# You can either supply a username or a UID.
# 
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

nrpe_user=nagios



# NRPE GROUP
# This determines the effective group that the NRPE daemon should run as.  
# You can either supply a group name or a GID.
# 
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

nrpe_group=nagios



# ALLOWED HOST ADDRESSES
# This is an optional comma-delimited list of IP address or hostnames 
# that are allowed to talk to the NRPE daemon.
#
# Note: The daemon only does rudimentary checking of the client's IP
# address.  I would highly recommend adding entries in your /etc/hosts.allow
# file to allow only the specified host to connect to the port
# you are running this daemon on.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

allowed_hosts=127.0.0.1,192.168.133.17



# COMMAND ARGUMENT PROCESSING
# This option determines whether or not the NRPE daemon will allow clients
# to specify arguments to commands that are executed.  This option only works
# if the daemon was configured with the --enable-command-args configure script
# option.  
#
# *** ENABLING THIS OPTION IS A SECURITY RISK! *** 
# Read the SECURITY file for information on some of the security implications
# of enabling this variable.
#
# Values: 0=do not allow arguments, 1=allow command arguments

dont_blame_nrpe=0



# COMMAND PREFIX
# This option allows you to prefix all commands with a user-defined string.
# A space is automatically added between the specified prefix string and the
# command line from the command definition.
#
# *** THIS EXAMPLE MAY POSE A POTENTIAL SECURITY RISK, SO USE WITH CAUTION! ***
# Usage scenario: 
# Execute restricted commmands using sudo.  For this to work, you need to add
# the nagios user to your /etc/sudoers.  An example entry for alllowing 
# execution of the plugins from might be:
#
# nagios          ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/
#
# This lets the nagios user run all commands in that directory (and only them)
# without asking for a password.  If you do this, make sure you don't give
# random users write access to that directory or its contents!
command_prefix=/usr/bin/sudo 



# DEBUGGING OPTION
# This option determines whether or not debugging messages are logged to the
# syslog facility.
# Values: 0=debugging off, 1=debugging on
debug=1



# COMMAND TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# allow plugins to finish executing before killing them off.

command_timeout=60



# CONNECTION TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# wait for a connection to be established before exiting. This is sometimes
# seen where a network problem stops the SSL being established even though
# all network sessions are connected. This causes the nrpe daemons to
# accumulate, eating system resources. Do not set this too low.

connection_timeout=300



# WEEK RANDOM SEED OPTION
# This directive allows you to use SSL even if your system does not have
# a /dev/random or /dev/urandom (on purpose or because the necessary patches
# were not applied). The random number generator will be seeded from a file
# which is either a file pointed to by the environment valiable $RANDFILE
# or $HOME/.rnd. If neither exists, the pseudo random number generator will
# be initialized and a warning will be issued.
# Values: 0=only seed from /dev/[u]random, 1=also seed from weak randomness

#allow_weak_random_seed=1



# INCLUDE CONFIG FILE
# This directive allows you to include definitions from an external config file.

#include=<somefile.cfg>



# INCLUDE CONFIG DIRECTORY
# This directive allows you to include definitions from config files (with a
# .cfg extension) in one or more directories (with recursion).

#include_dir=<somedirectory>
#include_dir=<someotherdirectory>



# COMMAND DEFINITIONS
# Command definitions that this daemon will run.  Definitions
# are in the following format:
#
# command[<command_name>]=<command_line>
#
# When the daemon receives a request to return the results of <command_name>
# it will execute the command specified by the <command_line> argument.
#
# Unlike Nagios, the command line cannot contain macros - it must be
# typed exactly as it should be executed.
#
# Note: Any plugins that are used in the command lines must reside
# on the machine that this daemon is running on!  The examples below
# assume that you have plugins installed in a /usr/local/nagios/libexec
# directory.  Also note that you will have to modify the definitions below
# to match the argument format the plugins expect.  Remember, these are
# examples only!


# The following examples use hardcoded command arguments...

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200 


# The following examples allow user-supplied arguments and can
# only be used if the NRPE daemon was compiled with support for 
# command arguments *AND* the dont_blame_nrpe directive in this
# config file is set to '1'.  This poses a potential security risk, so
# make sure you read the SECURITY file before doing this.

#command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
#command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
command[restart_http]=/usr/lib/nagios/plugins/http-restart 

#
# local configuration:
#   if you'd prefer, you can instead place directives here
include=/etc/nagios/nrpe_local.cfg

# 
# you can place your config snipplets into nrpe.d/
include_dir=/etc/nagios/nrpe.d/

我的 Sudoers 文件

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults    env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
nagios  ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/

# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

希望有人能帮忙!

nagios nrpe
  • 2 个回答
  • 11567 Views
Martin Hope
Bart B
Asked: 2012-06-27 03:40:46 +0800 CST

NRPE 和 Perl - 不能包含任何内容,否则会中断

  • 6

几个星期以来,我一直在努力摆脱 NRPE 和 Perl。

我决定从绝对第一原则开始,创建一个虚拟的 nagios 插件,它什么都不做,但总是返回 OK。我将其命名为 check_true.pl,将其安装在远程服务器上并配置 NRPE 以将其作为 check_test 提供。

整个脚本只是:

#!/usr/bin/perl

print "OK - this dummy test always returns OK\n";
exit 0;

这适用于 NRPE 没有问题。

以此为起点,我打算慢慢构建我想要的脚本,看看它在什么时候中断了。我根本没走多远。以下打破了 NRPE(但在本地和 SSH 上都可以正常工作):

#!/usr/bin/perl

use strict;

print "OK - this dummy test always returns OK\n";
exit 0;

它给出了可怕的错误:NRPE:无法读取输出。

我不能包含任何内容,否则会出现此错误。这使得我无法做我实际需要做的事情!

我认为这可能是 perl 包含路径的问题,但在 NRPE 上运行以下命令表明它不是(给出与在终端上运行时相同的包含路径):

#!/usr/bin/perl

print "OK - Perl include path: ".join(q{, }, @INC)."\n";
exit 0;

有谁知道为什么 NRPE 使用 Perl 时表现如此糟糕?谁能推荐一个修复程序?或者甚至是解决方法?

更新1:命令在NRPE中定义如下:

command[check_test]=/usr/lib64/nagios/plugins/check_true.pl

更新 2:我做了更多的调试,通过在 perl 脚本周围添加下面的包装器,我能够捕获 STDERR。

#!/bin/sh

out=`/usr/lib64/nagios/plugins/check_true.pl 2>&1`
echo $out

结果让事情变得更加混乱:

Can't locate strict.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/lib64/nagios/plugins/check_true.pl line 3. BEGIN failed--compilation aborted at /usr/lib64/nagios/plugins/check_true.pl line 3.

快速搜索显示 strict.pm 位于 /usr/share/perl5/strict.pm,而 /usr/share/perl5 位于列出的@INC 中!

Perl 怎么会找不到就在那里的文件呢?当在终端中以用户 nagios 身份运行时,这可以完美运行,那么 NRPE 对环境做了什么来搞乱 Perl?

perl nagios nrpe
  • 1 个回答
  • 1605 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve