This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch sync
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git

commit 843f2111d1e754a3def73b15fddd0d8629a65408
Author: benjobs <[email protected]>
AuthorDate: Fri May 31 23:36:23 2024 +0800

    [Improve] DingTalk alert bug fixed
---
 .../src/main/assembly/bin/jvm_opts.sh              |   3 +
 .../src/main/assembly/bin/streampark.sh            | 168 +++++++++------------
 .../console/base/util/BashJavaUtils.java           |  54 +++++++
 .../alert/impl/DingTalkAlertNotifyServiceImpl.java |  98 +++++-------
 .../alert/impl/LarkAlertNotifyServiceImpl.java     |   1 +
 5 files changed, 168 insertions(+), 156 deletions(-)

diff --git 
a/streampark-console/streampark-console-service/src/main/assembly/bin/jvm_opts.sh
 
b/streampark-console/streampark-console-service/src/main/assembly/bin/jvm_opts.sh
index 93fc9083e..2654c1751 100644
--- 
a/streampark-console/streampark-console-service/src/main/assembly/bin/jvm_opts.sh
+++ 
b/streampark-console/streampark-console-service/src/main/assembly/bin/jvm_opts.sh
@@ -17,6 +17,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+-server
 -Xms1g
 -Xmx1g
 -Xmn512m
@@ -33,3 +34,5 @@
 -XX:GCLogFileSize=50M
 -XX:NumberOfGCLogFiles=10
 
+# solved jdk1.8+ dynamic loading of resources to the classpath issue, if jdk > 
1.8, you can enable this parameter
+#--add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens 
jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED
diff --git 
a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
 
b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
index 5791ec333..f3f301be5 100755
--- 
a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
+++ 
b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
@@ -35,6 +35,13 @@
 #                   used
 # -----------------------------------------------------------------------------
 
+# Bugzilla 37848: When no TTY is available, don't output to console
+have_tty=0
+# shellcheck disable=SC2006
+if [[ "`tty`" != "not a tty" ]]; then
+    have_tty=1
+fi
+
 # Bugzilla 37848: When no TTY is available, don't output to console
 have_tty=0
 # shellcheck disable=SC2006
@@ -203,7 +210,7 @@ fi
 
 # Add on extra jar files to CLASSPATH
 # shellcheck disable=SC2236
-if [ ! -z "$CLASSPATH" ]; then
+if [[ ! -z "$CLASSPATH" ]]; then
   CLASSPATH="$CLASSPATH":
 fi
 CLASSPATH="$CLASSPATH"
@@ -222,7 +229,7 @@ if ${cygwin}; then
   CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
 fi
 
-if [ -z "$USE_NOHUP" ]; then
+if [[ -z "$USE_NOHUP" ]]; then
   if $hpux; then
     USE_NOHUP="true"
   else
@@ -230,18 +237,18 @@ if [ -z "$USE_NOHUP" ]; then
   fi
 fi
 unset NOHUP
-if [ "$USE_NOHUP" = "true" ]; then
+if [[ "$USE_NOHUP" = "true" ]]; then
   NOHUP="nohup"
 fi
 
-PARAM_CLI="org.apache.streampark.flink.core.conf.ParameterCli"
+BASH_UTIL="org.apache.streampark.console.base.util.BashJavaUtils"
 
 APP_MAIN="org.apache.streampark.console.StreamParkConsoleBootstrap"
 
 JVM_OPTS_FILE=${APP_HOME}/bin/jvm_opts.sh
 
-JVM_ARGS="-server"
-if [ -f $JVM_OPTS_FILE ]; then
+JVM_ARGS=""
+if [[ -f $JVM_OPTS_FILE ]]; then
   while read line
   do
       if [[ "$line" == -* ]]; then
@@ -265,39 +272,38 @@ print_logo() {
   printf '      %s  ___/ / /_/ /  /  __/ /_/ / / / / / / /_/ / /_/ / /  / ,<   
     %s\n'          $PRIMARY $RESET
   printf '      %s /____/\__/_/   \___/\__,_/_/ /_/ /_/ ____/\__,_/_/  /_/|_|  
     %s\n'          $PRIMARY $RESET
   printf '      %s                                   /_/                       
     %s\n\n'        $PRIMARY $RESET
-  printf '      %s   Version:  2.2.0 %s\n'                                     
                    $BLUE   $RESET
+  printf '      %s   Version:  2.1.4 %s\n'                                     
                    $BLUE   $RESET
   printf '      %s   WebSite:  https://streampark.apache.org%s\n'              
                    $BLUE   $RESET
   printf '      %s   GitHub :  http://github.com/apache/streampark%s\n\n'      
                    $BLUE   $RESET
   printf '      %s   ──────── Apache StreamPark, Make stream processing easier 
ô~ô!%s\n\n'         $PRIMARY  $RESET
 }
 
-parse_yaml() {
-   local prefix=$2
-   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
-   sed -ne "s|^\($s\):|\1|" \
-        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-        -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p"  $1 |
-   awk -F$fs '{
-      indent = length($1)/2;
-      vname[indent] = $2;
-      for (i in vname) {if (i > indent) {delete vname[i]}}
-      if (length($3) > 0) {
-         vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
-         printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
-      }
-   }'
+init_env() {
+  # shellcheck disable=SC2006
+  CONFIG="${APP_CONF}/application.yml"
+  if [[ -f "$CONFIG" ]] ; then
+    echo_y """[WARN] in the \"conf\" directory, found the \"application.yml\" 
file. The \"application.yml\" file is deprecated.
+       For compatibility, this application.yml will be used preferentially. 
The latest configuration file is \"config.yaml\". It is recommended to use 
\"config.yaml\".
+       Note: \"application.yml\" will be completely deprecated in version 
2.2.0. """
+  else
+    CONFIG="${APP_CONF}/config.yaml"
+    if [[ ! -f "$CONFIG" ]] ; then
+      echo_r "can not found config.yaml in \"conf\" directory, please check."
+      exit 1;
+    fi
+  fi
 }
 
 # shellcheck disable=SC2120
 get_pid() {
-  if [ -f "$APP_PID" ]; then
-    if [ -s "$APP_PID" ]; then
+  if [[ -f "$APP_PID" ]]; then
+    if [[ -s "$APP_PID" ]]; then
       # shellcheck disable=SC2155
       # shellcheck disable=SC2006
       local PID=`cat "$APP_PID"`
       kill -0 $PID >/dev/null 2>&1
       # shellcheck disable=SC2181
-      if [ $? -eq 0 ]; then
+      if [[ $? -eq 0 ]]; then
         echo $PID
         exit 0
       fi
@@ -307,31 +313,25 @@ get_pid() {
   fi
 
   # shellcheck disable=SC2006
-  local PROPER="${APP_CONF}/application.yml"
-  if [[ ! -f "$PROPER" ]] ; then
-    echo_r "ERROR: config file application.yml invalid or not found! ";
+  local serverPort=`$_RUNJAVA -cp "$APP_LIB/*" $BASH_UTIL --get_yaml 
"server.port" "$CONFIG"`
+  if [[ x"${serverPort}" == x"" ]]; then
+    echo_r "server.port is required, please check $CONFIG"
     exit 1;
-  fi
-
-  # shellcheck disable=SC2046
-  eval $(parse_yaml "${PROPER}" "conf_")
-  # shellcheck disable=SC2154
-  # shellcheck disable=SC2155
-  # shellcheck disable=SC2116
-  local serverPort=$(echo "$conf_server_port")
-  # shellcheck disable=SC2006
-  # shellcheck disable=SC2155
-  local used=`lsof -i:"$serverPort" | wc -l`
-  if [ "$used" -gt 0 ]; then
-    # shellcheck disable=SC2006
-    local PID=`jps -l | grep "$APP_MAIN" | awk '{print $1}'`
-    if [ ! -z $PID ]; then
-      echo $PID
-    else
-      echo 0
-    fi
   else
-    echo 0
+     # shellcheck disable=SC2006
+      # shellcheck disable=SC2155
+      local used=`$_RUNJAVA -cp "$APP_LIB/*" $BASH_UTIL --check_port 
"$serverPort"`
+      if [[ x"${used}" == x"used" ]]; then
+        # shellcheck disable=SC2006
+        local PID=`jps -l | grep "$APP_MAIN" | awk '{print $1}'`
+        if [[ ! -z $PID ]]; then
+          echo $PID
+        else
+          echo 0
+        fi
+      else
+        echo 0
+      fi
   fi
 }
 
@@ -340,7 +340,7 @@ start() {
   # shellcheck disable=SC2006
   local PID=$(get_pid)
 
-  if [ $PID -gt 0 ]; then
+  if [[ $PID -gt 0 ]]; then
     # shellcheck disable=SC2006
     echo_r "StreamPark is already running pid: $PID , start aborted!"
     exit 1
@@ -358,31 +358,20 @@ start() {
     echo_w "Using APP_PID:   $APP_PID"
   fi
 
-  local PROPER="${APP_CONF}/application.yml"
-  if [[ ! -f "$PROPER" ]] ; then
-    echo_r "ERROR: config file application.yml invalid or not found! ";
-    exit 1;
-  else
-    echo_g "Usage: config file: $PROPER ";
-  fi
+   # shellcheck disable=SC2006
+   local workspace=`$_RUNJAVA -cp "$APP_LIB/*" $BASH_UTIL --get_yaml 
"streampark.workspace.local" "$CONFIG"`
+   if [[ ! -d $workspace ]]; then
+     echo_r "ERROR: streampark.workspace.local: \"$workspace\" is invalid 
path, Please reconfigure in $CONFIG"
+     echo_r "NOTE: \"streampark.workspace.local\" Do not set under 
APP_HOME($APP_HOME). Set it to a secure directory outside of APP_HOME.  "
+     exit 1;
+   fi
 
-  # shellcheck disable=SC2046
-  eval $(parse_yaml "${PROPER}" "conf_")
-  # shellcheck disable=SC2001
-  # shellcheck disable=SC2154
-  # shellcheck disable=SC2155
-  local workspace=$(echo "$conf_streampark_workspace_local" | sed 's/#.*$//g')
-  if [[ ! -d $workspace ]]; then
-    echo_r "ERROR: streampark.workspace.local: \"$workspace\" is invalid path, 
Please reconfigure in application.yml"
-    echo_r "NOTE: \"streampark.workspace.local\" Do not set under 
APP_HOME($APP_HOME). Set it to a secure directory outside of APP_HOME.  "
-    exit 1;
-  fi
   if [[ ! -w $workspace ]] || [[ ! -r $workspace ]]; then
       echo_r "ERROR: streampark.workspace.local: \"$workspace\" Permission 
denied! "
       exit 1;
   fi
 
-  if [ "${HADOOP_HOME}"x == ""x ]; then
+  if [[ "${HADOOP_HOME}"x == ""x ]]; then
     echo_y "WARN: HADOOP_HOME is undefined on your system env,please check it."
   else
     echo_w "Using HADOOP_HOME:   ${HADOOP_HOME}"
@@ -413,9 +402,7 @@ start() {
   # shellcheck disable=SC2034
   # shellcheck disable=SC2006
   # shellcheck disable=SC2155
-  local ADD_OPENS=`$_RUNJAVA -cp "$APP_CLASSPATH" $PARAM_CLI --vmopt`
-
-  local JAVA_OPTS="$ADD_OPENS $JVM_OPTS $DEBUG_OPTS"
+  local JAVA_OPTS="$JVM_OPTS $DEBUG_OPTS"
 
   echo_g "JAVA_OPTS:  ${JAVA_OPTS}"
 
@@ -423,7 +410,6 @@ start() {
     -classpath "$APP_CLASSPATH" \
     -Dapp.home="${APP_HOME}" \
     -Dlogging.config="${APP_CONF}/logback-spring.xml" \
-    -Dspring.config.location="${PROPER}" \
     -Djava.io.tmpdir="$APP_TMPDIR" \
     $APP_MAIN >> "$APP_OUT" 2>&1 "&"
 
@@ -455,15 +441,7 @@ start_docker() {
     echo_w "Using APP_PID:   $APP_PID"
   fi
 
-  local PROPER="${APP_CONF}/application.yml"
-  if [[ ! -f "$PROPER" ]] ; then
-    echo_r "ERROR: config file application.yml invalid or not found! ";
-    exit 1;
-  else
-    echo_g "Usage: config file: $PROPER ";
-  fi
-
-  if [ "${HADOOP_HOME}"x == ""x ]; then
+  if [[ "${HADOOP_HOME}"x == ""x ]]; then
     echo_y "WARN: HADOOP_HOME is undefined on your system env,please check it."
   else
     echo_w "Using HADOOP_HOME:   ${HADOOP_HOME}"
@@ -490,14 +468,9 @@ start_docker() {
     APP_CLASSPATH+=":${HADOOP_HOME}/etc/hadoop"
   fi
 
-  # shellcheck disable=SC2034
-  # shellcheck disable=SC2006
-  # shellcheck disable=SC2155
-  local ADD_OPENS=`$_RUNJAVA -cp "$APP_CLASSPATH" $PARAM_CLI --vmopt`
-
   JVM_OPTS="${JVM_OPTS} -XX:-UseContainerSupport"
 
-  local JAVA_OPTS="$ADD_OPENS $JVM_OPTS $DEBUG_OPTS"
+  local JAVA_OPTS="$JVM_OPTS $DEBUG_OPTS"
 
   echo_g "JAVA_OPTS:  ${JAVA_OPTS}"
 
@@ -505,14 +478,14 @@ start_docker() {
     -classpath "$APP_CLASSPATH" \
     -Dapp.home="${APP_HOME}" \
     -Dlogging.config="${APP_CONF}/logback-spring.xml" \
-    -Dspring.config.location="${PROPER}" \
     -Djava.io.tmpdir="$APP_TMPDIR" \
     $APP_MAIN
 
 }
 
 debug() {
-  if [ ! -n "$DEBUG_PORT" ]; then
+  # shellcheck disable=SC2236
+  if [[ ! -n "$DEBUG_PORT" ]]; then
     echo_r "If start with debug mode,Please fill in the debug port like: bash 
streampark.sh debug 10002 "
   else
     DEBUG_OPTS="""
@@ -540,17 +513,17 @@ stop() {
   # shellcheck disable=SC2006
   echo_g "StreamPark stopping with the PID: $PID"
 
-  kill -9 $PID
+  kill -9 "$PID"
 
   while [ $SLEEP -ge 0 ]; do
     # shellcheck disable=SC2046
     # shellcheck disable=SC2006
-    kill -0 $PID >/dev/null 2>&1
+    kill -0 "$PID" >/dev/null 2>&1
     # shellcheck disable=SC2181
-    if [ $? -gt 0 ]; then
+    if [[ $? -gt 0 ]]; then
       rm -f "$APP_PID" >/dev/null 2>&1
-      if [ $? != 0 ]; then
-        if [ -w "$APP_PID" ]; then
+      if [[ $? != 0 ]]; then
+        if [[ -w "$APP_PID" ]]; then
           cat /dev/null > "$APP_PID"
         else
           echo_r "The PID file could not be removed."
@@ -560,7 +533,7 @@ stop() {
       break
     fi
 
-    if [ $SLEEP -gt 0 ]; then
+    if [[ $SLEEP -gt 0 ]]; then
        sleep 1
     fi
     # shellcheck disable=SC2006
@@ -568,7 +541,7 @@ stop() {
     SLEEP=`expr $SLEEP - 1 `
   done
 
-  if [ "$SLEEP" -lt 0 ]; then
+  if [[ "$SLEEP" -lt 0 ]]; then
      echo_r "StreamPark has not been killed completely yet. The process might 
be waiting on some system call or might be UNINTERRUPTIBLE."
   fi
 }
@@ -577,7 +550,7 @@ status() {
   # shellcheck disable=SC2155
   # shellcheck disable=SC2006
   local PID=$(get_pid)
-  if [ $PID -eq 0 ]; then
+  if [[ $PID -eq 0 ]]; then
     echo_r "StreamPark is not running"
   else
     echo_g "StreamPark is running pid is: $PID"
@@ -593,6 +566,7 @@ restart() {
 
 main() {
   print_logo
+  init_env
   case "$1" in
     "debug")
         DEBUG_PORT=$2
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/BashJavaUtils.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/BashJavaUtils.java
new file mode 100644
index 000000000..faf8b8ead
--- /dev/null
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/BashJavaUtils.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.console.base.util;
+
+import org.apache.streampark.common.util.PropertiesUtils;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Map;
+
+public class BashJavaUtils {
+
+  public static void main(String[] args) throws IOException {
+    String action = args[0].toLowerCase();
+    String[] actionArgs = Arrays.copyOfRange(args, 1, args.length);
+
+    switch (action) {
+      case "--get_yaml":
+        String key = actionArgs[0];
+        String conf = actionArgs[1];
+        Map<String, String> confMap = PropertiesUtils.fromYamlFileAsJava(conf);
+        String value = confMap.get(key);
+        System.out.println(value);
+        break;
+      case "--check_port":
+        Integer port = Integer.parseInt(actionArgs[0]);
+        try {
+          new ServerSocket(port);
+          System.out.println("free");
+        } catch (Exception e) {
+          System.out.println("used");
+        }
+        break;
+      default:
+        break;
+    }
+  }
+}
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/DingTalkAlertNotifyServiceImpl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/DingTalkAlertNotifyServiceImpl.java
index 38b24dded..a1282ac7c 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/DingTalkAlertNotifyServiceImpl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/DingTalkAlertNotifyServiceImpl.java
@@ -26,6 +26,7 @@ import org.apache.streampark.console.core.bean.RobotResponse;
 import org.apache.streampark.console.core.service.alert.AlertNotifyService;
 
 import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.net.util.Base64;
 
 import freemarker.template.Template;
 import lombok.extern.slf4j.Slf4j;
@@ -37,14 +38,13 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.Nonnull;
+import javax.annotation.PostConstruct;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -55,7 +55,7 @@ import java.util.StringJoiner;
 @Service
 @Lazy
 public class DingTalkAlertNotifyServiceImpl implements AlertNotifyService {
-  private final Template template = 
FreemarkerUtils.loadTemplateFile("alert-dingTalk.ftl");
+  private Template template;
 
   private final RestTemplate alertRestTemplate;
 
@@ -63,6 +63,12 @@ public class DingTalkAlertNotifyServiceImpl implements 
AlertNotifyService {
     this.alertRestTemplate = alertRestTemplate;
   }
 
+  @PostConstruct
+  public void loadTemplateFile() throws Exception {
+    String template = "alert-dingTalk.ftl";
+    this.template = FreemarkerUtils.loadTemplateFile(template);
+  }
+
   @Override
   public boolean doAlert(AlertConfigParams alertConfig, AlertTemplate 
alertTemplate)
       throws AlertException {
@@ -74,59 +80,37 @@ public class DingTalkAlertNotifyServiceImpl implements 
AlertNotifyService {
       if (StringUtils.hasLength(contacts)) {
         Collections.addAll(contactList, contacts.split(","));
       }
-      String title = renderTitle(alertTemplate, contactList);
-      Map<String, Object> contactMap = renderContact(contactList, 
dingTalkParams);
+      String title = alertTemplate.getTitle();
+      if (!contactList.isEmpty()) {
+        StringJoiner joiner = new StringJoiner(",@", title + " @", "");
+        contactList.forEach(joiner::add);
+        title = joiner.toString();
+      }
+      Map<String, Object> contactMap = new HashMap<>();
+      contactMap.put("atMobiles", contactList);
+      contactMap.put("isAtAll", 
BooleanUtils.toBoolean(dingTalkParams.getIsAtAll()));
+
       // format markdown
       String markdown = FreemarkerUtils.format(template, alertTemplate);
-      Map<String, String> contentMap = renderContent(title, markdown);
-      Map<String, Object> bodyMap = renderBody(contentMap, contactMap);
 
-      sendMessage(dingTalkParams, bodyMap);
+      Map<String, String> content = new HashMap<>();
+      content.put("title", title);
+      content.put("text", markdown);
+
+      Map<String, Object> body = new HashMap<>();
+      body.put("msgtype", "markdown");
+      body.put("markdown", content);
+      body.put("at", contactMap);
+
+      sendMessage(dingTalkParams, body);
       return true;
     } catch (AlertException alertException) {
       throw alertException;
     } catch (Exception e) {
-      throw new AlertException("Failed send DingTalk alert", e);
+      throw new AlertException("Failed send dingTalk alert", e);
     }
   }
 
-  @Nonnull
-  private Map<String, Object> renderBody(
-      Map<String, String> content, Map<String, Object> contactMap) {
-    Map<String, Object> body = new HashMap<>();
-    body.put("msgtype", "markdown");
-    body.put("markdown", content);
-    body.put("at", contactMap);
-    return body;
-  }
-
-  @Nonnull
-  private Map<String, String> renderContent(String title, String markdown) {
-    Map<String, String> content = new HashMap<>();
-    content.put("title", title);
-    content.put("text", markdown);
-    return content;
-  }
-
-  @Nonnull
-  private Map<String, Object> renderContact(
-      List<String> contactList, AlertDingTalkParams dingTalkParams) {
-    Map<String, Object> contactMap = new HashMap<>();
-    contactMap.put("atMobiles", contactList);
-    contactMap.put("isAtAll", 
BooleanUtils.toBoolean(dingTalkParams.getIsAtAll()));
-    return contactMap;
-  }
-
-  private String renderTitle(AlertTemplate alertTemplate, List<String> 
contactList) {
-    String title = alertTemplate.getTitle();
-    if (!contactList.isEmpty()) {
-      StringJoiner joiner = new StringJoiner(",@", title + " @", "");
-      contactList.forEach(joiner::add);
-      title = joiner.toString();
-    }
-    return title;
-  }
-
   private void sendMessage(AlertDingTalkParams params, Map<String, Object> 
body)
       throws AlertException {
     // get webhook url
@@ -141,16 +125,16 @@ public class DingTalkAlertNotifyServiceImpl implements 
AlertNotifyService {
     } catch (Exception e) {
       log.error("Failed to request DingTalk robot alarm,\nurl:{}", url, e);
       throw new AlertException(
-          String.format("Failed to request DingTalk robot alert,%nurl:%s", 
url), e);
+          String.format("Failed to request DingTalk robot alert,\nurl:%s", 
url), e);
     }
     if (robotResponse == null) {
       throw new AlertException(
-          String.format("Failed to request DingTalk robot alert,%nurl:%s", 
url));
+          String.format("Failed to request DingTalk robot alert,\nurl:%s", 
url));
     }
     if (robotResponse.getErrcode() != 0) {
       throw new AlertException(
           String.format(
-              "Failed to request DingTalk robot 
alert,%nurl:%s,%nerrorCode:%d,%nerrorMsg:%s",
+              "Failed to request DingTalk robot 
alert,\nurl:%s,\nerrorCode:%d,\nerrorMsg:%s",
               url, robotResponse.getErrcode(), robotResponse.getErrmsg()));
     }
   }
@@ -162,23 +146,19 @@ public class DingTalkAlertNotifyServiceImpl implements 
AlertNotifyService {
    * @return the webhook
    */
   private String getWebhook(AlertDingTalkParams params) {
-    String urlPef = "https://oapi.dingtalk.com/robot/send";;
+    String urlPrefix = "https://oapi.dingtalk.com/robot/send";;
     if (StringUtils.hasLength(params.getAlertDingURL())) {
-      urlPef = params.getAlertDingURL();
+      urlPrefix = params.getAlertDingURL().replaceFirst("\\?.*", "");
     }
-    if (!urlPef.endsWith("access_token=")) {
-      urlPef += "?access_token=";
-    }
-
     String url;
     if (params.getSecretEnable()) {
       Long timestamp = System.currentTimeMillis();
       url =
           String.format(
-              "%s%s&timestamp=%d&sign=%s",
-              urlPef, params.getToken(), timestamp, 
getSign(params.getSecretToken(), timestamp));
+              "%s?access_token=%s&timestamp=%d&sign=%s",
+              urlPrefix, params.getToken(), timestamp, 
getSign(params.getSecretToken(), timestamp));
     } else {
-      url = String.format("%s%s", urlPef, params.getToken());
+      url = String.format("%s?access_token=%s", urlPrefix, params.getToken());
     }
     if (log.isDebugEnabled()) {
       log.debug("The alarm robot url of DingTalk contains signature is {}", 
url);
@@ -203,7 +183,7 @@ public class DingTalkAlertNotifyServiceImpl implements 
AlertNotifyService {
       Mac mac = Mac.getInstance("HmacSHA256");
       mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), 
"HmacSHA256"));
       byte[] signData = 
mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
-      String sign = URLEncoder.encode(new 
String(Base64.getEncoder().encode(signData)), "UTF-8");
+      String sign = URLEncoder.encode(new 
String(Base64.encodeBase64(signData)), "UTF-8");
       if (log.isDebugEnabled()) {
         log.debug("Calculate the signature success, sign:{}", sign);
       }
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/LarkAlertNotifyServiceImpl.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/LarkAlertNotifyServiceImpl.java
index 86382c5f0..3dd899aae 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/LarkAlertNotifyServiceImpl.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/LarkAlertNotifyServiceImpl.java
@@ -134,6 +134,7 @@ public class LarkAlertNotifyServiceImpl implements 
AlertNotifyService {
    * @return the webhook
    */
   private String getWebhook(AlertLarkParams params) {
+    larkProxyUrl = larkProxyUrl.replaceFirst("/open-apis/bot/v2/hook/(.*)", 
"");
     String url = String.format(larkProxyUrl + "/open-apis/bot/v2/hook/%s", 
params.getToken());
     if (log.isDebugEnabled()) {
       log.debug("The alarm robot url of Lark is {}", url);

Reply via email to