Showing
7 changed files
with
80 additions
and
39 deletions
1 | -package com.monitor.javaserver.bigdata.ctrl; | 1 | +package com.monitor.common.alarm.ctrl; |
2 | 2 | ||
3 | import com.contants.AlarmGroupContants; | 3 | import com.contants.AlarmGroupContants; |
4 | +import com.monitor.common.alarm.model.MonitAlarmInfo; | ||
4 | import com.monitor.common.config.SnsMobileConfig; | 5 | import com.monitor.common.config.SnsMobileConfig; |
5 | import com.monitor.common.service.AlarmMsgService; | 6 | import com.monitor.common.service.AlarmMsgService; |
6 | -import com.monitor.javaserver.bigdata.MonitAlarmInfo; | 7 | +import com.monitor.model.response.BaseResponse; |
7 | import com.util.GetUsersInfoUtil; | 8 | import com.util.GetUsersInfoUtil; |
9 | +import org.apache.commons.lang.StringUtils; | ||
8 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
9 | import org.slf4j.LoggerFactory; | 11 | import org.slf4j.LoggerFactory; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.web.bind.annotation.RequestBody; | 13 | import org.springframework.web.bind.annotation.RequestBody; |
12 | import org.springframework.web.bind.annotation.RequestMapping; | 14 | import org.springframework.web.bind.annotation.RequestMapping; |
15 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
13 | import org.springframework.web.bind.annotation.RestController; | 16 | import org.springframework.web.bind.annotation.RestController; |
14 | 17 | ||
15 | /** | 18 | /** |
@@ -29,6 +32,23 @@ public class MonitAlarmCtrl { | @@ -29,6 +32,23 @@ public class MonitAlarmCtrl { | ||
29 | @Autowired | 32 | @Autowired |
30 | private GetUsersInfoUtil getUsersInfoUtil; | 33 | private GetUsersInfoUtil getUsersInfoUtil; |
31 | 34 | ||
35 | + /** | ||
36 | + * 对外提供报警接口: | ||
37 | + * | ||
38 | + */ | ||
39 | + @RequestMapping("/recvMonitAlarmInfo") | ||
40 | + @ResponseBody | ||
41 | + public BaseResponse recvMonitAlarmInfo(@RequestBody MonitAlarmInfo monitAlarmInfo ) { | ||
42 | + DEBUG.info("monit alarm info {} ", monitAlarmInfo); | ||
43 | + String mobiles=monitAlarmInfo.getMobiles(); | ||
44 | + if(StringUtils.isBlank(mobiles)){ | ||
45 | + mobiles = getUsersInfoUtil.getMobileByAlarmGroup(monitAlarmInfo.getGroup()); | ||
46 | + } | ||
47 | + boolean result=alarmMsgService.sendSmsWithIdc(StringUtils.isBlank(monitAlarmInfo.getType())?"service_exception":monitAlarmInfo.getType(), monitAlarmInfo.getInfo(), mobiles,StringUtils.isBlank(monitAlarmInfo.getIdc())?"":monitAlarmInfo.getIdc()); | ||
48 | + return new BaseResponse(result); | ||
49 | + } | ||
50 | + | ||
51 | + | ||
32 | @RequestMapping("/recvMonitAlarm") | 52 | @RequestMapping("/recvMonitAlarm") |
33 | public void recvMonitAlarm(@RequestBody MonitAlarmInfo info) { | 53 | public void recvMonitAlarm(@RequestBody MonitAlarmInfo info) { |
34 | 54 | ||
@@ -38,25 +58,7 @@ public class MonitAlarmCtrl { | @@ -38,25 +58,7 @@ public class MonitAlarmCtrl { | ||
38 | 58 | ||
39 | } | 59 | } |
40 | 60 | ||
41 | - /** | ||
42 | - * 对外提供报警接口: | ||
43 | - * | ||
44 | - * @param info 报警内容 | ||
45 | - * @param mobiles 电话号码以逗号隔开 156xxxxx,187xxxxxx | ||
46 | - */ | ||
47 | - @RequestMapping("/recvMonitAlarmInfo") | ||
48 | - public void recvMonitAlarmInfo(String info, String mobiles,String type ) { | ||
49 | - | ||
50 | - DEBUG.info("mip monit alarm info {} ,type {}: ", info,type); | ||
51 | - if (info == null) { | ||
52 | - info = ""; | ||
53 | - } | ||
54 | - if(type==null||type==""){ | ||
55 | - type= "service_exception"; | ||
56 | - } | ||
57 | - alarmMsgService.sendSms(type, info.toString(), mobiles); | ||
58 | 61 | ||
59 | - } | ||
60 | 62 | ||
61 | /** | 63 | /** |
62 | * 风控告警 | 64 | * 风控告警 |
1 | -package com.monitor.javaserver.bigdata; | 1 | +package com.monitor.common.alarm.model; |
2 | 2 | ||
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | 4 | ||
@@ -12,5 +12,22 @@ public class MonitAlarmInfo { | @@ -12,5 +12,22 @@ public class MonitAlarmInfo { | ||
12 | 12 | ||
13 | String service; | 13 | String service; |
14 | 14 | ||
15 | + | ||
16 | + //报警内容 | ||
15 | String info; | 17 | String info; |
18 | + | ||
19 | + //号码 | ||
20 | + String mobiles; | ||
21 | + | ||
22 | + //报警组名 | ||
23 | + String group; | ||
24 | + | ||
25 | + //源头 | ||
26 | + String idc; | ||
27 | + | ||
28 | + //报警类别 | ||
29 | + String type; | ||
30 | + | ||
31 | + | ||
32 | + | ||
16 | } | 33 | } |
@@ -10,6 +10,8 @@ public interface AlarmMsgService { | @@ -10,6 +10,8 @@ public interface AlarmMsgService { | ||
10 | */ | 10 | */ |
11 | boolean sendSms(String type, String content, String mobile); | 11 | boolean sendSms(String type, String content, String mobile); |
12 | 12 | ||
13 | + boolean sendSmsWithIdc(String type, String content, String mobile,String idc); | ||
14 | + | ||
13 | /** | 15 | /** |
14 | * 发送短信,抑制功能 | 16 | * 发送短信,抑制功能 |
15 | */ | 17 | */ |
@@ -56,6 +56,8 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -56,6 +56,8 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
56 | private String ZK_PATH = "/yh/config/"; | 56 | private String ZK_PATH = "/yh/config/"; |
57 | private String smsSendSwitch="ops.sendsms.open"; | 57 | private String smsSendSwitch="ops.sendsms.open"; |
58 | 58 | ||
59 | + private final String SYSTEM_IDC="yohops_aws"; | ||
60 | + | ||
59 | /** | 61 | /** |
60 | * 发送短信 | 62 | * 发送短信 |
61 | * | 63 | * |
@@ -63,7 +65,17 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -63,7 +65,17 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
63 | */ | 65 | */ |
64 | @Override | 66 | @Override |
65 | public boolean sendSms(String type, String content, String mobile) { | 67 | public boolean sendSms(String type, String content, String mobile) { |
66 | - return sendSmsPrivate(type, content, "", mobile,true); | 68 | + return sendSmsPrivate(type, content, "", mobile,true,SYSTEM_IDC); |
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * 发送短信,指定发送源 | ||
73 | + * | ||
74 | + * @throws UnsupportedEncodingException | ||
75 | + */ | ||
76 | + @Override | ||
77 | + public boolean sendSmsWithIdc(String type, String content, String mobile,String idc) { | ||
78 | + return sendSmsPrivate(type, content, "", mobile,true,idc); | ||
67 | } | 79 | } |
68 | 80 | ||
69 | /** | 81 | /** |
@@ -71,7 +83,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -71,7 +83,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
71 | */ | 83 | */ |
72 | @Override | 84 | @Override |
73 | public boolean sendSmsAlways(String type, String content, String mobile){ | 85 | public boolean sendSmsAlways(String type, String content, String mobile){ |
74 | - return sendSmsPrivate(type, content, "", mobile,false); | 86 | + return sendSmsPrivate(type, content, "", mobile,false,SYSTEM_IDC); |
75 | } | 87 | } |
76 | 88 | ||
77 | 89 | ||
@@ -79,7 +91,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -79,7 +91,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
79 | * 默认开启短信抑制功能 | 91 | * 默认开启短信抑制功能 |
80 | * @return | 92 | * @return |
81 | */ | 93 | */ |
82 | - private boolean sendSmsPrivate(String type, String content, String alarmInfo, String mobile,boolean checkSendBeforeMinus) { | 94 | + private boolean sendSmsPrivate(String type, String content, String alarmInfo, String mobile,boolean checkSendBeforeMinus,String idc) { |
83 | //根据zk的开关判断是否需要发送数据 | 95 | //根据zk的开关判断是否需要发送数据 |
84 | String open=""; | 96 | String open=""; |
85 | try{ | 97 | try{ |
@@ -101,7 +113,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -101,7 +113,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
101 | } | 113 | } |
102 | 114 | ||
103 | 115 | ||
104 | - logger.info("Send msg type {} content {} alarmInfo {} moniole {}...", type, content, alarmInfo, mobile); | 116 | + logger.info("Send msg type {} content {} alarmInfo {} mobiles {} idc {}...", type, content, alarmInfo, mobile,idc); |
105 | if (StringUtils.isBlank(content)) { | 117 | if (StringUtils.isBlank(content)) { |
106 | return false; | 118 | return false; |
107 | } | 119 | } |
@@ -121,7 +133,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -121,7 +133,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
121 | } | 133 | } |
122 | 134 | ||
123 | try { | 135 | try { |
124 | - monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "faild", resultJsonString,mobile); | 136 | + monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "faild", resultJsonString,mobile,idc); |
125 | } catch (Exception e) { | 137 | } catch (Exception e) { |
126 | logger.error("insert sms into influxdb failed", e); | 138 | logger.error("insert sms into influxdb failed", e); |
127 | } | 139 | } |
@@ -105,7 +105,7 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -105,7 +105,7 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
105 | DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); | 105 | DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); |
106 | String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); | 106 | String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); |
107 | DEBUG.info("send voice notice msg,result:{}", result); | 107 | DEBUG.info("send voice notice msg,result:{}", result); |
108 | - monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile); | 108 | + monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile,"yohops_aws"); |
109 | } | 109 | } |
110 | 110 | ||
111 | dingDingService.insertMsg("yhops语音告警:"+promptfile); | 111 | dingDingService.insertMsg("yhops语音告警:"+promptfile); |
@@ -9,7 +9,9 @@ public interface MonitorAlarmMapper { | @@ -9,7 +9,9 @@ public interface MonitorAlarmMapper { | ||
9 | * @param influxDBName | 9 | * @param influxDBName |
10 | * @param snsContent | 10 | * @param snsContent |
11 | */ | 11 | */ |
12 | - void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile); | 12 | + //void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile); |
13 | + | ||
14 | + void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile,String idc); | ||
13 | 15 | ||
14 | /** | 16 | /** |
15 | * 查询type的tag-value | 17 | * 查询type的tag-value |
@@ -15,7 +15,7 @@ public class MonitorAlarmMapperImpl implements MonitorAlarmMapper { | @@ -15,7 +15,7 @@ public class MonitorAlarmMapperImpl implements MonitorAlarmMapper { | ||
15 | @Autowired | 15 | @Autowired |
16 | private InfluxDataReporter influxDataReporter; | 16 | private InfluxDataReporter influxDataReporter; |
17 | 17 | ||
18 | - /** | 18 | + /* |
19 | * 插入告警短信 | 19 | * 插入告警短信 |
20 | * | 20 | * |
21 | * @param influxDBName | 21 | * @param influxDBName |
@@ -24,27 +24,33 @@ public class MonitorAlarmMapperImpl implements MonitorAlarmMapper { | @@ -24,27 +24,33 @@ public class MonitorAlarmMapperImpl implements MonitorAlarmMapper { | ||
24 | * @param alarmInfo | 24 | * @param alarmInfo |
25 | */ | 25 | */ |
26 | @Override | 26 | @Override |
27 | - public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile) { | ||
28 | - | 27 | + public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile,String idc) { |
29 | Point point = Point.measurement("monitor_alarm") | 28 | Point point = Point.measurement("monitor_alarm") |
30 | .tag("type", alarmType) | 29 | .tag("type", alarmType) |
31 | .tag("send_status", sendStatus) | 30 | .tag("send_status", sendStatus) |
32 | .tag("event", "alarm") | 31 | .tag("event", "alarm") |
33 | - .tag("idc","yohops_aws") | 32 | + .tag("idc",idc) |
34 | .addField("sms_content", snsContent) | 33 | .addField("sms_content", snsContent) |
35 | .addField("result", result) | 34 | .addField("result", result) |
36 | .addField("mobile", mobile) | 35 | .addField("mobile", mobile) |
37 | .addField("alarm_info", alarmInfo).build(); | 36 | .addField("alarm_info", alarmInfo).build(); |
38 | influxDataReporter.report(influxDBName,InfluxDBContants.YOHO_MONITOR,point); | 37 | influxDataReporter.report(influxDBName,InfluxDBContants.YOHO_MONITOR,point); |
39 | - | ||
40 | - /* BatchPoints batchPoints = BatchPoints | ||
41 | - .database(InfluxDBContants.YOHO_MONITOR).tag("event", "alarm").retentionPolicy("default") | ||
42 | - .build(); | ||
43 | - batchPoints.point(point); | ||
44 | - influxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB() | ||
45 | - .write(batchPoints);*/ | ||
46 | } | 38 | } |
47 | 39 | ||
40 | + /* | ||
41 | + * 插入告警短信 | ||
42 | + * | ||
43 | + * @param influxDBName | ||
44 | + * @param alarmType | ||
45 | + * @param snsContent | ||
46 | + * @param alarmInfo | ||
47 | + */ | ||
48 | + /* @Override | ||
49 | + public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile) { | ||
50 | + // | ||
51 | + this.insertAlarmMsg(influxDBName, alarmType, snsContent, alarmInfo, sendStatus,result,mobile,"yohops_aws"); | ||
52 | + }*/ | ||
53 | + | ||
48 | /** | 54 | /** |
49 | * 查询type的tag-value | 55 | * 查询type的tag-value |
50 | * | 56 | * |
-
Please register or login to post a comment