From 12a40d724436f7d0a81a706fc306d5f314ec5bdb Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Wed, 18 Apr 2018 19:17:33 +0200 Subject: [PATCH] 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 --- etc/icinga2/scripts/mail-host-notification.sh | 14 +++++++------- etc/icinga2/scripts/mail-service-notification.sh | 15 +++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/etc/icinga2/scripts/mail-host-notification.sh b/etc/icinga2/scripts/mail-host-notification.sh index c63f63b4d..cecb2d754 100755 --- a/etc/icinga2/scripts/mail-host-notification.sh +++ b/etc/icinga2/scripts/mail-host-notification.sh @@ -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!" diff --git a/etc/icinga2/scripts/mail-service-notification.sh b/etc/icinga2/scripts/mail-service-notification.sh index 8831df5d2..c53d4d022 100755 --- a/etc/icinga2/scripts/mail-service-notification.sh +++ b/etc/icinga2/scripts/mail-service-notification.sh @@ -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!"