grafana提示告警发送到dingding
Showing
1 changed file
with
29 additions
and
3 deletions
@@ -146,6 +146,32 @@ public class OuterIntfCtrl { | @@ -146,6 +146,32 @@ public class OuterIntfCtrl { | ||
146 | 146 | ||
147 | 147 | ||
148 | /** | 148 | /** |
149 | + * | ||
150 | + * Grafana alert webhook. refer to:http://docs.grafana.org/alerting/notifications/ | ||
151 | + * | ||
152 | + * <pre> | ||
153 | + * | ||
154 | + * { | ||
155 | + "title": "My alert", | ||
156 | + "ruleId": 1, | ||
157 | + "ruleName": "Load peaking!", | ||
158 | + "ruleUrl": "http://url.to.grafana/db/dashboard/my_dashboard?panelId=2", | ||
159 | + "state": "alerting", | ||
160 | + "imageUrl": "http://s3.image.url", | ||
161 | + "message": "Load is peaking. Make sure the traffic is real and spin up more webfronts", | ||
162 | + "evalMatches": [ | ||
163 | + { | ||
164 | + "metric": "requests", | ||
165 | + "tags": {}, | ||
166 | + "value": 122 | ||
167 | + } | ||
168 | + ] | ||
169 | + } | ||
170 | + * </pre> | ||
171 | + * | ||
172 | + * Created by chunhua.zhang on 2017/5/26. | ||
173 | + */ | ||
174 | + /** | ||
149 | * 接口:grafana报警提示 | 175 | * 接口:grafana报警提示 |
150 | * @param request | 176 | * @param request |
151 | * @return | 177 | * @return |
@@ -154,7 +180,7 @@ public class OuterIntfCtrl { | @@ -154,7 +180,7 @@ public class OuterIntfCtrl { | ||
154 | @ResponseBody | 180 | @ResponseBody |
155 | public BaseResponse grafanaWebHook(HttpServletRequest request) { | 181 | public BaseResponse grafanaWebHook(HttpServletRequest request) { |
156 | try { | 182 | try { |
157 | - String jsonBody = IOUtils.toString(request.getInputStream()); | 183 | + String jsonBody = IOUtils.toString(request.getInputStream(),"utf-8"); |
158 | log.info("receive grafana webhook message:{}", jsonBody); | 184 | log.info("receive grafana webhook message:{}", jsonBody); |
159 | JSONObject alert = (JSONObject) JSON.parse(jsonBody); | 185 | JSONObject alert = (JSONObject) JSON.parse(jsonBody); |
160 | String title = ""; | 186 | String title = ""; |
@@ -164,8 +190,8 @@ public class OuterIntfCtrl { | @@ -164,8 +190,8 @@ public class OuterIntfCtrl { | ||
164 | if(alert!=null){ | 190 | if(alert!=null){ |
165 | title = alert.getString("title"); | 191 | title = alert.getString("title"); |
166 | state = alert.getString("state"); | 192 | state = alert.getString("state"); |
167 | - imgUrl = alert.getString("imageUrl"); | ||
168 | - message = alert.getString("message"); | 193 | + imgUrl = alert.get("imageUrl")==null?"":alert.getString("imageUrl"); |
194 | + message = alert.get("message")==null?"":alert.getString("message"); | ||
169 | } | 195 | } |
170 | 196 | ||
171 | Map<String, String> map=new HashMap<>(); | 197 | Map<String, String> map=new HashMap<>(); |
-
Please register or login to post a comment