I am using the check_file_exists plugin from Github linked from Nagios Exchange.
BUT... I am getting the opposite results on the web console than I am from the command line eg:
My check_file_exists file =
Code: Select all
#!/bin/sh
#
# Author : Diego Martin Gardella [dgardella@gmail.com]
# Desc : Plugin to verify if a file exists
#
# v1.0: Initial version by (Diego Martin Gardella [dgardella@gmail.com])
# v1.1: Add negate support (Elan Ruusamäe )
# v1.2: Also check if file is folder (Simon Smit)
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
usage() {
echo "Usage: $PROGRAM [-n] [file]
Options:
-n, --negate negate the result
"
}
state_name() {
case "$STATE" in
$STATE_OK)
echo OK
;;
$STATE_CRITICAL)
echo CRITICAL
;;
esac
}
exists() {
$negate && STATE=$STATE_CRITICAL || STATE=$STATE_OK
echo "$(state_name) - $1 EXISTS"
}
exists_dir() {
$negate && STATE=$STATE_CRITICAL || STATE=$STATE_OK
echo "$(state_name) - $1 EXISTS :: Directory"
}
not_exists() {
$negate && STATE=$STATE_OK || STATE=$STATE_CRITICAL
echo "$(state_name) - $1 Does NOT exist"
}
# parse command line args
t=$(getopt -o n --long negate -n "$PROGNAME" -- "$@")
[ $? != 0 ] && exit $?
eval set -- "$t"
negate=false
while :; do
case "$1" in
-n|--negate)
negate=true
;;
--)
shift
break
;;
*)
echo >&2 "$PROGRAM: Internal error: [$1] not recognized!"
exit 1
;;
esac
shift
done
STATE=$STATE_UNKNOWN
if [ "$1" = "" ]; then
usage
exit $STATE
fi
if [ -f "$1" ]; then
exists "$1"
elif [ -d "$1" ]; then
exists_dir "$1"
else
not_exists "$1"
fi
exit $STATE
Code: Select all
# 'check_file_exists' command definition
define command {
command_name check_file_exists
command_line $USER1$/check_file_exists $ARG1$
}
Code: Select all
define service{
use generic-service
host_name my_server_name
service_description Check Backup - Nagios
check_command check_file_exists!/root/backups/nagios/nagios.tar.gz
}
Code: Select all
[root@centos libexec]# ./check_file_exists /root/backups/nagios
OK - /root/backups/nagios EXISTS :: Directory
[root@centos libexec]# ./check_file_exists /root/backups/nagios/nagios.tar.gz
OK - /root/backups/nagios/nagios.tar.gz EXISTS
[root@centos libexec]# ./check_file_exists /root/backups/nagios/nagios.tar
CRITICAL - /root/backups/nagios/nagios.tar Does NOT exist
Check Backup - Nagios | CRITICAL | 16-08-2018 10:22:41 | 0d 0h 58m 5s | 3/3 | CRITICAL - /root/backups/nagios/nagios.tar.gz Does NOT exist
Any ideas as to why I would be getting the opposite result ??
Thanks