Browse Source

[Fix-16569][alert] Feishu send alert message failed (#16588)

dev
saowu 4 months ago committed by GitHub
parent
commit
e4db2d6b87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java
  2. 117
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java
  3. 5
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java

2
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java

@ -31,7 +31,7 @@ public final class FeiShuAlertChannel implements AlertChannel {
AlertData alertData = alertInfo.getAlertData();
Map<String, String> paramsMap = alertInfo.getAlertParams();
if (null == paramsMap) {
return new AlertResult(false, "fei shu params is null");
return new AlertResult(false, "feishu params is null");
}
return new FeiShuSender(paramsMap).sendFeiShuMsg(alertData);
}

117
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java

@ -37,6 +37,10 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -83,25 +87,24 @@ public final class FeiShuSender {
alertResult.setSuccess(false);
if (org.apache.commons.lang3.StringUtils.isBlank(result)) {
alertResult.setMessage("send fei shu msg error");
log.info("send fei shu msg error,fei shu server resp is null");
alertResult.setMessage("send feishu msg error: feishu server resp is blank.");
log.info("send feishu msg error: feishu server resp is blank.");
return alertResult;
}
FeiShuSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, FeiShuSendMsgResponse.class);
if (null == sendMsgResponse) {
alertResult.setMessage("send fei shu msg fail");
log.info("send fei shu msg error,resp error");
alertResult.setMessage("send feishu msg error: feishu server resp parse error is null.");
log.info("send feishu msg error: feishu server resp parse error is null.");
return alertResult;
}
if (sendMsgResponse.statusCode == 0) {
if (sendMsgResponse.code == 0) {
alertResult.setSuccess(true);
alertResult.setMessage("send fei shu msg success");
alertResult.setMessage("send feishu msg success.");
return alertResult;
}
alertResult.setMessage(String.format("alert send fei shu msg error : %s", sendMsgResponse.getStatusMessage()));
log.info("alert send fei shu msg error : {} ,Extra : {} ", sendMsgResponse.getStatusMessage(),
sendMsgResponse.getExtra());
alertResult.setMessage(String.format("alert send feishu msg error: %s", sendMsgResponse.getMsg()));
log.info("alert send feishu msg error: {}", sendMsgResponse);
return alertResult;
}
@ -134,10 +137,10 @@ public final class FeiShuSender {
String resp = sendMsg(alertData);
return checkSendFeiShuSendMsgResult(resp);
} catch (Exception e) {
log.error("send fei shu alert failed:", e);
log.error("send feishu alert failed:", e);
alertResult = new AlertResult();
alertResult.setSuccess(false);
alertResult.setMessage("send fei shu alert fail.");
alertResult.setMessage("send feishu alert fail.");
}
return alertResult;
}
@ -167,95 +170,25 @@ public final class FeiShuSender {
} finally {
response.close();
}
log.info("Fei Shu send title :{} ,content :{}, resp: {}", alertData.getTitle(), alertData.getContent(),
log.info("feishu send title: {}, content: {}, resp: {}", alertData.getTitle(), alertData.getContent(),
resp);
return resp;
} finally {
httpClient.close();
}
}
@AllArgsConstructor
@Builder
@Data
@NoArgsConstructor
static final class FeiShuSendMsgResponse {
@JsonProperty("Extra")
private String extra;
@JsonProperty("StatusCode")
private Integer statusCode;
@JsonProperty("StatusMessage")
private String statusMessage;
public FeiShuSendMsgResponse() {
}
public String getExtra() {
return this.extra;
}
@JsonProperty("Extra")
public void setExtra(String extra) {
this.extra = extra;
}
public Integer getStatusCode() {
return this.statusCode;
}
@JsonProperty("StatusCode")
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
public String getStatusMessage() {
return this.statusMessage;
}
@JsonProperty("data")
private Object data;
@JsonProperty("code")
private Integer code;
@JsonProperty("msg")
private String msg;
@JsonProperty("StatusMessage")
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
public boolean equals(final Object o) {
if (o == this) {
return true;
}
if (!(o instanceof FeiShuSendMsgResponse)) {
return false;
}
final FeiShuSendMsgResponse other = (FeiShuSendMsgResponse) o;
final Object this$extra = this.getExtra();
final Object other$extra = other.getExtra();
if (this$extra == null ? other$extra != null : !this$extra.equals(other$extra)) {
return false;
}
final Object this$statusCode = this.getStatusCode();
final Object other$statusCode = other.getStatusCode();
if (this$statusCode == null ? other$statusCode != null : !this$statusCode.equals(other$statusCode)) {
return false;
}
final Object this$statusMessage = this.getStatusMessage();
final Object other$statusMessage = other.getStatusMessage();
if (this$statusMessage == null ? other$statusMessage != null
: !this$statusMessage.equals(other$statusMessage)) {
return false;
}
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $extra = this.getExtra();
result = result * PRIME + ($extra == null ? 43 : $extra.hashCode());
final Object $statusCode = this.getStatusCode();
result = result * PRIME + ($statusCode == null ? 43 : $statusCode.hashCode());
final Object $statusMessage = this.getStatusMessage();
result = result * PRIME + ($statusMessage == null ? 43 : $statusMessage.hashCode());
return result;
}
public String toString() {
return "FeiShuSender.FeiShuSendMsgResponse(extra=" + this.getExtra() + ", statusCode="
+ this.getStatusCode() + ", statusMessage=" + this.getStatusMessage() + ")";
}
}
}

5
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java

@ -89,9 +89,10 @@ public class FeiShuSenderTest {
AlertResult alertResult = feiShuSender.checkSendFeiShuSendMsgResult("");
Assertions.assertFalse(alertResult.isSuccess());
AlertResult alertResult2 = feiShuSender.checkSendFeiShuSendMsgResult("123");
Assertions.assertEquals("send fei shu msg fail", alertResult2.getMessage());
Assertions.assertEquals("send feishu msg error: feishu server resp parse error is null.",
alertResult2.getMessage());
String response = "{\"StatusCode\":\"0\",\"extra\":\"extra\",\"StatusMessage\":\"StatusMessage\"}";
String response = "{\"code\":\"0\",\"data\":{},\"msg\":\"success\"}";
AlertResult alertResult3 = feiShuSender.checkSendFeiShuSendMsgResult(response);
Assertions.assertTrue(alertResult3.isSuccess());
}

Loading…
Cancel
Save