2017-09-01 148 views
-1
#!/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 

當我在本地主機上運行腳本這是工作:NRPE:無法讀取輸出

./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 

請建議解決方案。

+0

檢查'nrpe.cfg'文件,以查找命令名'check_ratify'。 – Jdamian

回答

0

這通常是一個權限問題。如果nrpenagios用戶無法訪問您要stat的路徑,你會得到。我看到你的例子試圖訪問/root目錄,這是隻能由超級用戶可讀下的文件。

所以,我想你是以root身份運行你的本地例子,但遠程檢查運行爲nrpenagios。如果你真的需要訪問路徑,您必須配置相應的權限。