Implement better way to check parameters in notification scripts

This changes the function for checking required parameters in the notification scripts.
This also enhances the error message.

refs #5812
This commit is contained in:
Michael Insel 2018-04-18 19:17:33 +02:00
parent a8b5d8e64a
commit 12a40d7244
2 changed files with 14 additions and 15 deletions

View File

@ -90,14 +90,14 @@ done
shift $((OPTIND - 1))
## Check required parameters (TODO: better error message)
## Keep formatting in sync with mail-service-notification.sh
if [ ! "$LONGDATETIME" ] \
|| [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \
|| [ ! "$HOSTOUTPUT" ] || [ ! "$HOSTSTATE" ] \
|| [ ! "$USEREMAIL" ] || [ ! "$NOTIFICATIONTYPE" ]; then
Error "Requirement parameters are missing."
fi
for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME HOSTOUTPUT HOSTSTATE USEREMAIL NOTIFICATIONTYPE ; do
eval "PAR=\$${P}"
if [ ! "$PAR" ] ; then
Error "Required parameter '$P' is missing."
fi
done
## Build the message's subject
SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!"

View File

@ -94,15 +94,14 @@ done
shift $((OPTIND - 1))
## Check required parameters (TODO: better error message)
## Keep formatting in sync with mail-host-notification.sh
if [ ! "$LONGDATETIME" ] \
|| [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \
|| [ ! "$SERVICENAME" ] || [ ! "$SERVICEDISPLAYNAME" ] \
|| [ ! "$SERVICEOUTPUT" ] || [ ! "$SERVICESTATE" ] \
|| [ ! "$USEREMAIL" ] || [ ! "$NOTIFICATIONTYPE" ]; then
Error "Requirement parameters are missing."
fi
for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME SERVICENAME SERVICEDISPLAYNAME SERVICEOUTPUT SERVICESTATE USEREMAIL NOTIFICATIONTYPE ; do
eval "PAR=\$${P}"
if [ ! "$PAR" ] ; then
Error "Required parameter '$P' is missing."
fi
done
## Build the message's subject
SUBJECT="[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!"