Authored by qinchao

grafana提示告警发送到dingding

... ... @@ -71,6 +71,13 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
... ...
package com.ui.ctrl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Sets;
... ... @@ -7,6 +8,7 @@ import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.MonitAlarmInfo;
import com.ui.model.WebHooksReleaseBO;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
... ... @@ -17,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;
/**
... ... @@ -141,5 +145,35 @@ public class OuterIntfCtrl {
}
/**
* 接口:grafana报警提示
* @param request
* @return
*/
@RequestMapping(value = "/grafanaWebHook")
@ResponseBody
public BaseResponse grafanaWebHook(HttpServletRequest request) {
try {
String jsonBody = IOUtils.toString(request.getInputStream());
log.info("receive grafana webhook message:{}", jsonBody);
JSONObject alert = (JSONObject) JSON.parse(jsonBody);
String title = alert.getString("title");
String state = alert.getString("state");
String imgUrl = alert.getString("imageUrl");
String message = alert.getString("message");
Map<String, String> map=new HashMap<>();
map.put("title",title);
map.put("state",state);
map.put("imgUrl",imgUrl);
map.put("message",message);
return httpClient.defaultGet("/grafanaAlert/sendDing",BaseResponse.class,map);
} catch (IOException e) {
e.printStackTrace();
}
return new BaseResponse(201);
}
}
... ...