add an optional -w
authorMartin Zobel-Helas <zobel@debian.org>
Sat, 24 Jul 2010 13:47:07 +0000 (15:47 +0200)
committerMartin Zobel-Helas <zobel@debian.org>
Sat, 24 Jul 2010 13:47:07 +0000 (15:47 +0200)
dsa-nagios-checks/checks/dsa-check-file

index e53d3e6..61cd6cf 100755 (executable)
@@ -36,28 +36,36 @@ $0: usage:
        File checker for nagios.  Will alert if the named file does not exist
 
        -h      This help message
+       -w      If the file does not exist, this is only warning
        -f      File to check
 EOF
 
        exit $ret
 }
 
-while getopts f:i:h opt ; do
+while getopts f:hw opt ; do
        case "$opt" in
                f) FILE="$OPTARG" ;;
+               w) LEVEL="WARNING";;
                h) usage 0
        esac
 done
 
+if [ "$LEVEL" = "WARNING" ]; then
+       EXIT=1
+else
+       EXIT=2
+       LEVEL="CRITICAL"
+fi
+
 if [ -z "$FILE" ]; then
        echo "Need file argument!" >&2
        usage 3
 fi
 
 if [ ! -f "$FILE" ]; then
-       printf "CRITICAL: file %s is missing\n" $FILE
-       exit 2
+       printf "%s: file %s is missing\n" $LEVEL $FILE
+       exit $EXIT
 fi
 
-
 printf "OK: file %s does exist %s\n" $FILE