Browse Source

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

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

113
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;
}
@ -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