diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java index f323219dab4d..2e400efbceb7 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java @@ -405,7 +405,9 @@ public void deleteFile(File file) { */ private void handleException(AlertResult alertResult, Exception e) { log.error("Send email to {} failed", receivers, e); - alertResult.setMessage("Send email to {" + String.join(",", receivers) + "} failed," + e.toString()); + alertResult.setMessage( + String.format("Send email to: %s, failed: %s", + String.join(",", receivers), e.getMessage())); } } diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java index bdd6cf15cd64..32448393ce42 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java @@ -100,7 +100,8 @@ public AlertResult send(String msg) { } catch (Exception e) { log.error("send http alert msg exception : {}", e.getMessage()); alertResult.setStatus("false"); - alertResult.setMessage("send http request alert fail."); + alertResult.setMessage( + String.format("Send http request alert failed: %s", e.getMessage())); } return alertResult; diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java index 568faf167b49..65792c8eae10 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java @@ -21,12 +21,14 @@ import org.apache.dolphinscheduler.alert.api.HttpServiceRetryStrategy; import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -77,11 +79,16 @@ private AlertResult send(AlertResult alertResult, String url, String requestBody CloseableHttpResponse response = httpClient.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8); try { if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) { alertResult.setStatus("true"); alertResult.setMessage("send pager duty alert success"); } else { + alertResult.setMessage( + String.format("send pager duty alert error, statusCode: %s, responseContent: %s", + statusCode, responseContent)); log.info("send pager duty alert fail, statusCode : {}", statusCode); } } finally { diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java index 4a417909e45a..199ccd5ea106 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java @@ -17,6 +17,9 @@ package org.apache.dolphinscheduler.plugin.alert.webexteams; +import lombok.Data; + +@Data public class WebexMessage { private String roomId; @@ -25,52 +28,4 @@ public class WebexMessage { private String text; private String markdown; private String html; - - public String getRoomId() { - return roomId; - } - - public void setRoomId(String roomId) { - this.roomId = roomId; - } - - public String getToPersonId() { - return toPersonId; - } - - public void setToPersonId(String toPersonId) { - this.toPersonId = toPersonId; - } - - public String getToPersonEmail() { - return toPersonEmail; - } - - public void setToPersonEmail(String toPersonEmail) { - this.toPersonEmail = toPersonEmail; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public String getMarkdown() { - return markdown; - } - - public void setMarkdown(String markdown) { - this.markdown = markdown; - } - - public String getHtml() { - return html; - } - - public void setHtml(String html) { - this.html = html; - } } diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java index cd9ca8715707..f8201a40e096 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java @@ -22,12 +22,14 @@ import org.apache.dolphinscheduler.alert.api.HttpServiceRetryStrategy; import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -82,15 +84,21 @@ private void send(AlertResult alertResult, AlertData alertData) throws IOExcepti HttpClients.custom().setRetryHandler(HttpServiceRetryStrategy.retryStrategy).build(); try { - HttpPost httpPost = constructHttpPost(getMessage(alertData), botAccessToken); + WebexMessage message = getMessage(alertData); + HttpPost httpPost = constructHttpPost(message, botAccessToken); CloseableHttpResponse response = httpClient.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8); try { if (statusCode == HttpStatus.SC_OK) { alertResult.setStatus("true"); alertResult.setMessage("send webex teams alert success"); } else { + alertResult.setMessage(String.format( + "send webex teams alert error, message: %s, statusCode: %s, responseContent: %s", message, + statusCode, responseContent)); log.info("send webex teams alert fail, statusCode : {}", statusCode); } } finally {