Authored by qinchao

短信接口修改

package com.monitor.javaserver.bigdata.ctrl;
package com.monitor.common.alarm.ctrl;
import com.contants.AlarmGroupContants;
import com.monitor.common.alarm.model.MonitAlarmInfo;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.javaserver.bigdata.MonitAlarmInfo;
import com.monitor.model.response.BaseResponse;
import com.util.GetUsersInfoUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
... ... @@ -29,6 +32,23 @@ public class MonitAlarmCtrl {
@Autowired
private GetUsersInfoUtil getUsersInfoUtil;
/**
* 对外提供报警接口:
*
*/
@RequestMapping("/recvMonitAlarmInfo")
@ResponseBody
public BaseResponse recvMonitAlarmInfo(@RequestBody MonitAlarmInfo monitAlarmInfo ) {
DEBUG.info("monit alarm info {} ", monitAlarmInfo);
String mobiles=monitAlarmInfo.getMobiles();
if(StringUtils.isBlank(mobiles)){
mobiles = getUsersInfoUtil.getMobileByAlarmGroup(monitAlarmInfo.getGroup());
}
boolean result=alarmMsgService.sendSmsWithIdc(StringUtils.isBlank(monitAlarmInfo.getType())?"service_exception":monitAlarmInfo.getType(), monitAlarmInfo.getInfo(), mobiles,StringUtils.isBlank(monitAlarmInfo.getIdc())?"":monitAlarmInfo.getIdc());
return new BaseResponse(result);
}
@RequestMapping("/recvMonitAlarm")
public void recvMonitAlarm(@RequestBody MonitAlarmInfo info) {
... ... @@ -38,25 +58,7 @@ public class MonitAlarmCtrl {
}
/**
* 对外提供报警接口:
*
* @param info 报警内容
* @param mobiles 电话号码以逗号隔开 156xxxxx,187xxxxxx
*/
@RequestMapping("/recvMonitAlarmInfo")
public void recvMonitAlarmInfo(String info, String mobiles,String type ) {
DEBUG.info("mip monit alarm info {} ,type {}: ", info,type);
if (info == null) {
info = "";
}
if(type==null||type==""){
type= "service_exception";
}
alarmMsgService.sendSms(type, info.toString(), mobiles);
}
/**
* 风控告警
... ...
package com.monitor.javaserver.bigdata;
package com.monitor.common.alarm.model;
import lombok.Data;
... ... @@ -12,5 +12,22 @@ public class MonitAlarmInfo {
String service;
//报警内容
String info;
//号码
String mobiles;
//报警组名
String group;
//源头
String idc;
//报警类别
String type;
}
... ...
... ... @@ -10,6 +10,8 @@ public interface AlarmMsgService {
*/
boolean sendSms(String type, String content, String mobile);
boolean sendSmsWithIdc(String type, String content, String mobile,String idc);
/**
* 发送短信,抑制功能
*/
... ...
... ... @@ -56,6 +56,8 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
private String ZK_PATH = "/yh/config/";
private String smsSendSwitch="ops.sendsms.open";
private final String SYSTEM_IDC="yohops_aws";
/**
* 发送短信
*
... ... @@ -63,7 +65,17 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
*/
@Override
public boolean sendSms(String type, String content, String mobile) {
return sendSmsPrivate(type, content, "", mobile,true);
return sendSmsPrivate(type, content, "", mobile,true,SYSTEM_IDC);
}
/**
* 发送短信,指定发送源
*
* @throws UnsupportedEncodingException
*/
@Override
public boolean sendSmsWithIdc(String type, String content, String mobile,String idc) {
return sendSmsPrivate(type, content, "", mobile,true,idc);
}
/**
... ... @@ -71,7 +83,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
*/
@Override
public boolean sendSmsAlways(String type, String content, String mobile){
return sendSmsPrivate(type, content, "", mobile,false);
return sendSmsPrivate(type, content, "", mobile,false,SYSTEM_IDC);
}
... ... @@ -79,7 +91,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
* 默认开启短信抑制功能
* @return
*/
private boolean sendSmsPrivate(String type, String content, String alarmInfo, String mobile,boolean checkSendBeforeMinus) {
private boolean sendSmsPrivate(String type, String content, String alarmInfo, String mobile,boolean checkSendBeforeMinus,String idc) {
//根据zk的开关判断是否需要发送数据
String open="";
try{
... ... @@ -101,7 +113,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
}
logger.info("Send msg type {} content {} alarmInfo {} moniole {}...", type, content, alarmInfo, mobile);
logger.info("Send msg type {} content {} alarmInfo {} mobiles {} idc {}...", type, content, alarmInfo, mobile,idc);
if (StringUtils.isBlank(content)) {
return false;
}
... ... @@ -121,7 +133,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
}
try {
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "faild", resultJsonString,mobile);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "faild", resultJsonString,mobile,idc);
} catch (Exception e) {
logger.error("insert sms into influxdb failed", e);
}
... ...
... ... @@ -105,7 +105,7 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms));
String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms));
DEBUG.info("send voice notice msg,result:{}", result);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile,"yohops_aws");
}
dingDingService.insertMsg("yhops语音告警:"+promptfile);
... ...
... ... @@ -9,7 +9,9 @@ public interface MonitorAlarmMapper {
* @param influxDBName
* @param snsContent
*/
void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile);
//void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile);
void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile,String idc);
/**
* 查询type的tag-value
... ...
... ... @@ -15,7 +15,7 @@ public class MonitorAlarmMapperImpl implements MonitorAlarmMapper {
@Autowired
private InfluxDataReporter influxDataReporter;
/**
/*
* 插入告警短信
*
* @param influxDBName
... ... @@ -24,27 +24,33 @@ public class MonitorAlarmMapperImpl implements MonitorAlarmMapper {
* @param alarmInfo
*/
@Override
public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile) {
public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile,String idc) {
Point point = Point.measurement("monitor_alarm")
.tag("type", alarmType)
.tag("send_status", sendStatus)
.tag("event", "alarm")
.tag("idc","yohops_aws")
.tag("idc",idc)
.addField("sms_content", snsContent)
.addField("result", result)
.addField("mobile", mobile)
.addField("alarm_info", alarmInfo).build();
influxDataReporter.report(influxDBName,InfluxDBContants.YOHO_MONITOR,point);
/* BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.YOHO_MONITOR).tag("event", "alarm").retentionPolicy("default")
.build();
batchPoints.point(point);
influxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB()
.write(batchPoints);*/
}
/*
* 插入告警短信
*
* @param influxDBName
* @param alarmType
* @param snsContent
* @param alarmInfo
*/
/* @Override
public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result,String mobile) {
//
this.insertAlarmMsg(influxDBName, alarmType, snsContent, alarmInfo, sendStatus,result,mobile,"yohops_aws");
}*/
/**
* 查询type的tag-value
*
... ...