Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-ui
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
qinchao
7 years ago
Commit
c09a91793dec7cc80ecfdc5577aa2afdc3f05d34
1 parent
41bf7637
grafana提示告警发送到dingding
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
monitor-ui-common/pom.xml
monitor-ui-ctrl/src/main/java/com/ui/ctrl/OuterIntfCtrl.java
monitor-ui-common/pom.xml
View file @
c09a917
...
...
@@ -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>
...
...
monitor-ui-ctrl/src/main/java/com/ui/ctrl/OuterIntfCtrl.java
View file @
c09a917
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
);
}
}
...
...
Please
register
or
login
to post a comment