Random Project

Getting opposite results to command line

Hi,

Firstly, thanks for the script(s).

BUT… I am getting the opposite results on the web console than I am from the command line eg:

My check_file_exists file =
#!/bin/sh
#
# Author : Diego Martin Gardella [[email protected]]
# Desc : Plugin to verify if a file exists
#
# v1.0: Initial version by (Diego Martin Gardella [[email protected]])
# 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

==========
In my commands.cfg =
# ‘check_file_exists’ command definition
define command {
command_name check_file_exists
command_line $USER1$/check_file_exists $ARG1$
}

==========
In my_server_name.cfg =
define service{
use generic-service
host_name my_server_name
service_description Check Backup – Nagios
check_command heck_file_exist!/root/backups/nagios/nagios.tar.gz
}

==========
When I run from the command line…
[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

In the web console…

Check Backup – Nagios | CRITICAL | 27-06-2018 14:22:37 | 0d 0h 0m 30s | 1/3 | CRITICAL – /root/backups/nagios/nagios.tar.gz Does NOT exist

Any ideas as to why I would be getting the opposite result ??

Thanks