]> granicus.if.org Git - icinga2/commitdiff
Fixed URL encoding for HOSTNAME and SERVICENAME in mail notification
authorDirk Goetz <dirk.goetz@netways.de>
Wed, 14 Feb 2018 12:21:59 +0000 (13:21 +0100)
committerJean Flach <jean-marcel.flach@icinga.com>
Tue, 20 Feb 2018 13:16:43 +0000 (14:16 +0100)
Refs #5540

etc/icinga2/scripts/mail-host-notification.sh
etc/icinga2/scripts/mail-service-notification.sh

index 8512a8c87fc64760080f687c2089eb0f93748fa3..c63f63b4dc1cb39211abe84bac41567c82e08352 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 #
 # 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`"
 ICINGA2HOST="`hostname`"
@@ -49,6 +50,16 @@ Error() {
   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
 while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt
 do
@@ -128,7 +139,7 @@ fi
 if [ -n "$ICINGAWEB2URL" ] ; then
   NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
 
-$ICINGAWEB2URL/monitoring/host/show?host=$HOSTNAME"
+$ICINGAWEB2URL/monitoring/host/show?host=$(urlencode "$HOSTNAME")"
 fi
 
 ## Check whether verbose mode was enabled and log to syslog.
index 5f31814861fa1c246a057e1c3ef92514ac4c9d4a..8831df5d2182bb0b34925929335464f2c4eeacd7 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 #
 # 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`"
 ICINGA2HOST="`hostname`"
@@ -51,6 +52,16 @@ Error() {
   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
 while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt
 do
@@ -134,7 +145,7 @@ fi
 if [ -n "$ICINGAWEB2URL" ] ; then
   NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
 
-$ICINGAWEB2URL/monitoring/service/show?host=$HOSTNAME&service=$SERVICENAME"
+$ICINGAWEB2URL/monitoring/service/show?host=$(urlencode "$HOSTNAME")&service=$(urlencode "$SERVICENAME")"
 fi
 
 ## Check whether verbose mode was enabled and log to syslog.