...
|
...
|
@@ -146,6 +146,32 @@ public class OuterIntfCtrl { |
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Grafana alert webhook. refer to:http://docs.grafana.org/alerting/notifications/
|
|
|
*
|
|
|
* <pre>
|
|
|
*
|
|
|
* {
|
|
|
"title": "My alert",
|
|
|
"ruleId": 1,
|
|
|
"ruleName": "Load peaking!",
|
|
|
"ruleUrl": "http://url.to.grafana/db/dashboard/my_dashboard?panelId=2",
|
|
|
"state": "alerting",
|
|
|
"imageUrl": "http://s3.image.url",
|
|
|
"message": "Load is peaking. Make sure the traffic is real and spin up more webfronts",
|
|
|
"evalMatches": [
|
|
|
{
|
|
|
"metric": "requests",
|
|
|
"tags": {},
|
|
|
"value": 122
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
* </pre>
|
|
|
*
|
|
|
* Created by chunhua.zhang on 2017/5/26.
|
|
|
*/
|
|
|
/**
|
|
|
* 接口:grafana报警提示
|
|
|
* @param request
|
|
|
* @return
|
...
|
...
|
@@ -154,7 +180,7 @@ public class OuterIntfCtrl { |
|
|
@ResponseBody
|
|
|
public BaseResponse grafanaWebHook(HttpServletRequest request) {
|
|
|
try {
|
|
|
String jsonBody = IOUtils.toString(request.getInputStream());
|
|
|
String jsonBody = IOUtils.toString(request.getInputStream(),"utf-8");
|
|
|
log.info("receive grafana webhook message:{}", jsonBody);
|
|
|
JSONObject alert = (JSONObject) JSON.parse(jsonBody);
|
|
|
String title = "";
|
...
|
...
|
@@ -164,8 +190,8 @@ public class OuterIntfCtrl { |
|
|
if(alert!=null){
|
|
|
title = alert.getString("title");
|
|
|
state = alert.getString("state");
|
|
|
imgUrl = alert.getString("imageUrl");
|
|
|
message = alert.getString("message");
|
|
|
imgUrl = alert.get("imageUrl")==null?"":alert.getString("imageUrl");
|
|
|
message = alert.get("message")==null?"":alert.getString("message");
|
|
|
}
|
|
|
|
|
|
Map<String, String> map=new HashMap<>();
|
...
|
...
|
|