NRPE:无法读取输出

时间:2017-09-01 06:27:12

标签: nagios

#!/usr/bin/env bash


DEFAULT_WARN_SECONDS=60
DEFAULT_CRIT_SECONDS=120


while getopts  'hp:c:w:' option; do
    case $option in
        h) help=1;;
        p) path=$OPTARG;;
        c) crit=$OPTARG;;
        w) warn=$OPTARG;;
    esac
done

if [ -n "$help" ] || [ -z "$path" ]; then
    echo "usage: $0 -p [path (required)] -w [warning threshhold seconds] -c [critical threshhold seconds]" 1>&2
    exit 4
elif ! [ -e "$path" ]; then
    echo "fatal: invalid or unreadable file path provided: $path" 1>&2
    exit 3
fi

if [ -z "$warn" ]; then
    warn=$DEFAULT_WARN_SECONDS
fi
if [ -z "$crit" ]; then
    crit=$DEFAULT_CRIT_SECONDS
fi

seconds=$(($(date +'%s') - $(stat --format='%Y' $path)))

if [ $seconds -gt $crit ]; then
    echo "CRITICAL: $path was last modified $seconds seconds ago"
    exit 1
elif [ $seconds -gt $warn ]; then
    echo "WARNING: $path was last modified $seconds seconds ago"
    exit 2
else
    echo "OK: $path was last modified $seconds seconds ago"
    exit 0
fi

当我在localhost中运行脚本时,它正在运行:

./check_last -p /root/Ratify/apache-tomcat-ratify/target/ratify.log -w 30 -c 40
**output:**
OK: /root/Ratify/apache-tomcat-ratify/target/ratify.log was last modified 24 seconds ago

当我从远程服务器运行脚本时,它无法正常工作:

./check_nrpe -H 00.00.0.00 -c check_ratify
NRPE: Unable to read output

请建议解决方案。

1 个答案:

答案 0 :(得分:0)

这通常是权限问题。如果nrpenagios用户无法访问您尝试stat的路径,那么您将获得该路径。我看到您的示例正在尝试访问/root目录下的文件,该目录只能由超级用户读取。

所以,我猜您是以root身份运行本地示例,但远程检查以nrpenagios运行。如果您确实需要访问该路径,则必须相应地配置权限。