-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

When I run the script in localhost it is working :

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

When I run the script from remote server it is not working :

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

Please suggest solution.

ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
boovan
  • 1
  • 1

1 Answers1

0

This is usually a permissions issue. If the nrpe or nagios user can't access the path you are trying to stat, you'll get that. And I see your example is trying to access a file under the /root directory, which is only readable by the superuser.

So, I guess you're running your local example as root, but the remote check is run as nrpe or nagios. If you really need to access that path, you have to configure permissions accordingly.

ilvidel
  • 322
  • 1
  • 4
  • 13