Fixed URL encoding for HOSTNAME and SERVICENAME in mail notification

Refs #5540
This commit is contained in:
Dirk Goetz 2018-02-14 13:21:59 +01:00 committed by Jean Flach
parent f3e747509c
commit 87f8ca5b79
2 changed files with 24 additions and 2 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) # Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)
# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license
PROG="`basename $0`" PROG="`basename $0`"
ICINGA2HOST="`hostname`" ICINGA2HOST="`hostname`"
@ -49,6 +50,16 @@ Error() {
exit 1; exit 1;
} }
urlencode() {
local LANG=C i c e=''
for ((i=0;i<${#1};i++)); do
c=${1:$i:1}
[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c"
e+="$c"
done
echo "$e"
}
## Main ## Main
while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt
do do
@ -128,7 +139,7 @@ fi
if [ -n "$ICINGAWEB2URL" ] ; then if [ -n "$ICINGAWEB2URL" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
$ICINGAWEB2URL/monitoring/host/show?host=$HOSTNAME" $ICINGAWEB2URL/monitoring/host/show?host=$(urlencode "$HOSTNAME")"
fi fi
## Check whether verbose mode was enabled and log to syslog. ## Check whether verbose mode was enabled and log to syslog.

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) # Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)
# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license
PROG="`basename $0`" PROG="`basename $0`"
ICINGA2HOST="`hostname`" ICINGA2HOST="`hostname`"
@ -51,6 +52,16 @@ Error() {
exit 1; exit 1;
} }
urlencode() {
local LANG=C i c e=''
for ((i=0;i<${#1};i++)); do
c=${1:$i:1}
[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c"
e+="$c"
done
echo "$e"
}
## Main ## Main
while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt
do do
@ -134,7 +145,7 @@ fi
if [ -n "$ICINGAWEB2URL" ] ; then if [ -n "$ICINGAWEB2URL" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
$ICINGAWEB2URL/monitoring/service/show?host=$HOSTNAME&service=$SERVICENAME" $ICINGAWEB2URL/monitoring/service/show?host=$(urlencode "$HOSTNAME")&service=$(urlencode "$SERVICENAME")"
fi fi
## Check whether verbose mode was enabled and log to syslog. ## Check whether verbose mode was enabled and log to syslog.