Authored by zhengyouwei

add

Showing 21 changed files with 710 additions and 1 deletions
... ... @@ -143,6 +143,28 @@
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>com.xuanwu</groupId>-->
<!--<artifactId>postmsg-ump</artifactId>-->
<!--<version>2.4.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.protobuf</groupId>-->
<!--<artifactId>protobuf-java</artifactId>-->
<!--<version>2.4.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>xpp3</groupId>-->
<!--<artifactId>xpp3_min</artifactId>-->
<!--<version>1.1.4c</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.thoughtworks.xstream</groupId>-->
<!--<artifactId>xstream</artifactId>-->
<!--<version>1.3.1</version>-->
<!--</dependency>-->
</dependencies>
</project>
\ No newline at end of file
... ...
package com.monitor.common.service;
import java.io.UnsupportedEncodingException;
/**
* Created by zhengyouwei on 2016/5/26.
*/
public interface VoiceMsgService {
void sendVoide(String mobile) throws UnsupportedEncodingException;
}
... ...
package com.monitor.common.service.impl;
//import com.esms.MessageData;
//import com.esms.PostMsg;
//import com.esms.common.entity.Account;
//import com.esms.common.entity.GsmsResponse;
//import com.esms.common.entity.MTPack;
import com.monitor.common.service.HttpRestClientService;
import com.monitor.common.service.VoiceMsgService;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.MonitorAlarmMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.UUID;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Service
public class VoiceMsgServiceImpl implements VoiceMsgService {
@Autowired
private MonitorAlarmMapper monitorAlarmMapper;
@Autowired
private HttpRestClientService httpRestClientService;
public final Logger DEBUG = LoggerFactory.getLogger(getClass());
@Override
public void sendVoide(String mobile) throws UnsupportedEncodingException {
try {
// Account account = new Account("yoho@yoho", "yoho@9646");//
// PostMsg pm = new PostMsg();
// pm.getCmHost().setHost("211.147.239.62", 9050);//设置网关的IP和port,用于发送信息
// MTPack pack = new MTPack();
// pack.setBatchID(UUID.randomUUID());
// pack.setBatchName("语音短信");
// pack.setMsgType(MTPack.MsgType.VOICE_CODE);//设置语音发送类型
// pack.setBizType(0);//设置UMP配置的语音专用业务类型
// pack.setDistinctFlag(false);
// ArrayList<MessageData> msgs = new ArrayList<MessageData>();
//
// /** 群发,多号码一内容 */
// pack.setSendType(MTPack.SendType.MASS);
// String content = "ABCDEFG";//设置语音验证码内容
// msgs.add(MessageData.getInstance("15905144483", content));
//
// GsmsResponse resp = pm.post(account, pack);
// StringBuilder smsUrl = new StringBuilder();
// smsUrl.append("http://211.147.239.62:20510/cgi-bin/sendsms");
// smsUrl.append("?username=yoho@yoho");
// smsUrl.append("&password=yoho@9646");
// smsUrl.append("&to=");
// String[] mobiles = mobile.split(",");
// for (String str : mobiles) {
// smsUrl.append(str + " ");
// }
// smsUrl.append("&text=" + URLEncoder.encode("yoho", "GBK"));
// smsUrl.append("&subid=");
// smsUrl.append("&msgtype=9"); //msgtype:1 短信
// String result = httpRestClientService.doGet(smsUrl.toString(), null);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", "yh", null, "");
} catch (Exception e) {
DEBUG.error("sendVoide error ", e);
}
}
}
... ...
... ... @@ -44,4 +44,11 @@ public interface MonitorAlarmMapper {
* @return
*/
QueryResult selectAlarmMsgCount(String influxDBName, String type);
/**
* 查询是否需要进行语音告警
* @param influxDBName
* @return
*/
QueryResult selectVoiceAlarm(String influxDBName, int min);
}
... ...
package com.monitor.influxdb.mapper;
import com.monitor.model.request.SmsUp;
import org.influxdb.dto.QueryResult;
/**
* Created by yoho on 2016/8/4.
*/
public interface SmsUpMapper {
void insert(SmsUp smsUp);
QueryResult select(int min);
}
... ...
... ... @@ -97,4 +97,12 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
"WHERE event = 'alarm' AND type = '" + type + "'";
return query(influxDBName, command, InfluxDBContants.YOMO_MONITOR);
}
@Override
public QueryResult selectVoiceAlarm(String influxDBName, int min) {
// String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m and type != 'work_system'";
String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
return query(influxDBName, command, InfluxDBContants.YOMO_MONITOR);
}
}
... ...
package com.monitor.influxdb.mapper.impl;
import com.monitor.influxdb.InfluxDBQuery;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.SmsUpMapper;
import com.monitor.model.request.SmsUp;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.QueryResult;
import org.springframework.stereotype.Component;
/**
* Created by yoho on 2016/8/4.
*/
@Component
public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper {
@Override
public void insert(SmsUp smsUp) {
BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.YOMO_MONITOR).retentionPolicy("default")
.build();
Point point = Point.measurement("sms_up")
.addField("SmsType", smsUp.getSmsType())
.addField("SrcMobile", StringUtils.isBlank(smsUp.getSrcMobile())?" ":smsUp.getSrcMobile())
.addField("AppendID", StringUtils.isBlank(smsUp.getAppendID())?" ":smsUp.getAppendID())
.addField("Content", StringUtils.isBlank(smsUp.getContent())?" ":smsUp.getContent())
.addField("RecvTime", StringUtils.isBlank(smsUp.getRecvTime())?" ":smsUp.getRecvTime())
.addField("SendTime", StringUtils.isBlank(smsUp.getSendTime())?" ":smsUp.getSendTime())
.addField("Status", StringUtils.isBlank(smsUp.getStatus()) ? " " : smsUp.getStatus()).build();
batchPoints.point(point);
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(batchPoints);
}
@Override
public QueryResult select(int min) {
String command = "SELECT count(SrcMobile) FROM sms_up where time > now() - "+ min+"m";
return query(InfluxDBContants.AWS, command, InfluxDBContants.YOMO_MONITOR);
}
}
... ...
package com.monitor.model.domain;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class VoiceSms {
private Tel tel;
private int prompttype;
private String promptfile;
private String sig ;
private String ext;
static class Tel{
private String nationcode;
private String phone;
public String getNationcode() {
return nationcode;
}
public void setNationcode(String nationcode) {
this.nationcode = nationcode;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
}
... ...
package com.monitor.model.request;
import com.monitor.model.page.PageRequest;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class AbTestReq extends PageRequest{
private String configType;
private String abType;
}
... ...
package com.monitor.model.request;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class SmsUp {
private String SmsType;
private String SrcMobile;
private String AppendID;
private String Content;
private String RecvTime;
private String SendTime;
private String Status;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class ABTest {
private int id;
private String name;
private String abType;
private String configType;
private String value;
private String comment;
private String createTime;
private String updateTime;
}
... ...
package com.monitor.mysql.mapper;
import com.model.ABTest;
import com.model.AuthModule;
import com.monitor.model.domain.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Created by zhengyouwei on 2016/7/13.
*/
public interface ABTestMapper {
int insert(ABTest abTest);
int update(ABTest abTest);
List<ABTest> selectAllByParam(ABTest abTest);
List<ABTest> selectByPage(PageBean page);
int selectCount(PageBean page);
int delete(@Param("id") int id);
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.ABTestMapper" >
<resultMap id="BaseResultMap" type="com.model.ABTest" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="ab_type" property="abType" jdbcType="VARCHAR" />
<result column="config_type" property="configType" jdbcType="VARCHAR" />
<result column="value" property="value" jdbcType="VARCHAR" />
<result column="comment" property="comment" jdbcType="VARCHAR" />
<result column="createTime" property="createTime" jdbcType="VARCHAR" />
<result column="updateTime" property="updateTime" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, name, ab_type, config_type, value, comment,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime,DATE_FORMAT(update_time,'%Y-%m-%d %H:%i:%S') AS updateTime
</sql>
<insert id="insert" parameterType="com.model.ABTest" >
insert into ab_test
(name,ab_type,config_type, value, comment, create_time, update_time)
values
(#{name,jdbcType=VARCHAR},#{abType,jdbcType=INTEGER},
#{configType,jdbcType=VARCHAR},#{value,jdbcType=VARCHAR},
#{comment,jdbcType=VARCHAR},
now(),now())
</insert>
<update id="update" parameterType="com.model.AuthModule" >
update ab_test
set
value = #{value,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectAllByParam" resultMap="BaseResultMap" parameterType="com.model.AuthModule" >
select
<include refid="Base_Column_List" />
from ab_test
where ab_type = #{abType,jdbcType=VARCHAR} and config_type = #{configType,jdbcType=VARCHAR}
</select>
<select id="selectByPage" resultMap="BaseResultMap" parameterType="com.model.AuthModule" >
select
<include refid="Base_Column_List" />
from ab_test
where
1=1
<if test="params.configType != null &amp;&amp; params.configType != ''" >
and config_type = #{configType,jdbcType=VARCHAR}
</if>
<if test="params.abType != null &amp;&amp; params.abType != ''" >
and ab_type = #{params.abType}
</if>
order by create_time desc
limit #{startIndex},#{pageSize}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ab_test
</select>
<select id="selectCount" resultType="java.lang.Integer">
select
count(1)
from ab_test
where
1=1
<if test="params.configType != null &amp;&amp; params.configType != ''" >
and config_type = #{configType,jdbcType=VARCHAR}
</if>
<if test="params.abType != null &amp;&amp; params.abType != ''" >
and ab_type = #{params.abType}
</if>
</select>
<delete id="delete" parameterType="java.lang.Integer" >
delete from ab_test
where id = #{id,jdbcType=INTEGER}
</delete>
</mapper>
\ No newline at end of file
... ...
package com.monitor.other.abtest.ctrl;
import com.model.ABTest;
import com.model.BuildProcessHistory;
import com.model.DBWorkJob;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageResponse;
import com.monitor.model.request.AbTestReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.other.abtest.service.ABTestService;
import com.monitor.other.worksystem.service.DBService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Controller
@RequestMapping("/abtest")
public class ABTestCtrl {
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private ABTestService abTestService;
/**
* 新增
* @return
*/
@RequestMapping("/insert")
@ResponseBody
public BaseResponse<Integer> insert(@RequestBody ABTest abTest) {
try {
int result = abTestService.insert(abTest);
return new BaseResponse<>(result);
}catch (Exception e){
logger.error("insert ~",e);
return new BaseResponse<>(-1);
}
}
/**
* 更新
* @return
*/
@RequestMapping("/update")
@ResponseBody
public BaseResponse<Integer> update(@RequestBody ABTest abTest) {
try {
int result = abTestService.update(abTest);
return new BaseResponse<>(result);
}catch (Exception e){
logger.error("update ~",e);
return new BaseResponse<>(-1);
}
}
/**
* 删除
* @return
*/
@RequestMapping("/delete")
@ResponseBody
public BaseResponse<Integer> delete(int id) {
try {
int result = abTestService.delete(id);
return new BaseResponse<>(result);
}catch (Exception e){
logger.error("delete ~",e);
return new BaseResponse<>(-1);
}
}
/**
* 获取
* @return
*/
@RequestMapping("/get")
@ResponseBody
public BaseResponse<PageResponse<ABTest>> get(@RequestBody AbTestReq req) {
try {
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = abTestService.selectCount(page);
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return new BaseResponse<>();
}
// 获取列表
List<ABTest> abTests = abTestService.selectByPage(page);
PageResponse<ABTest> response = new PageResponse<ABTest>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(abTests);
return new BaseResponse<PageResponse<ABTest>>(response);
}catch (Exception e){
logger.error("update ~",e);
return new BaseResponse<>();
}
}
}
... ...
package com.monitor.other.abtest.service;
import com.model.ABTest;
import com.monitor.model.domain.PageBean;
import java.util.List;
/**
* Created by zhengyouwei on 2016/12/16.
*/
public interface ABTestService {
int insert(ABTest abTest);
int update(ABTest abTest);
List<ABTest> selectByPage(PageBean page);
int selectCount(PageBean page);
int delete(int id);
}
... ...
package com.monitor.other.abtest.service.impl;
import com.model.ABTest;
import com.monitor.model.domain.PageBean;
import com.monitor.mysql.mapper.ABTestMapper;
import com.monitor.other.abtest.service.ABTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Service
public class ABTestServiceImpl implements ABTestService {
@Autowired
private ABTestMapper abTestMapper;
@Override
public int insert(ABTest abTest) {
return abTestMapper.insert(abTest);
}
@Override
public int update(ABTest abTest) {
return abTestMapper.update(abTest);
}
@Override
public List<ABTest> selectByPage(PageBean page) {
return abTestMapper.selectByPage(page);
}
@Override
public int selectCount(PageBean page) {
return abTestMapper.selectCount(page);
}
@Override
public int delete(int id) {
return abTestMapper.delete(id);
}
}
... ...
package com.monitor.other.smsUp;
import com.alibaba.fastjson.JSON;
import com.monitor.influxdb.mapper.SmsUpMapper;
import com.monitor.model.request.SmsUp;
import com.monitor.model.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Controller
@RequestMapping("/smsup")
public class SmsUpctrl {
public final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private SmsUpMapper smsUpMapper;
/**
* 删除
* @return
*/
@RequestMapping("/smsup")
@ResponseBody
public BaseResponse smsup(@RequestBody SmsUp smsUp) {
logger.info("smsup req :{}", JSON.toJSONString(smsUp));
try {
smsUpMapper.insert(smsUp);
}catch (Exception e){
logger.error("smsup",e);
}
return new BaseResponse();
}
}
... ...
package com.monitor.other.task.someTask;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.VoiceMsgService;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.MonitorAlarmMapper;
import com.monitor.influxdb.mapper.SmsUpMapper;
import com.monitor.influxdb.util.QueryResultUtil;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Component
public class AlarmSendVoiceTask {
@Autowired
private MonitorAlarmMapper monitorAlarmMapper;
@Autowired
private VoiceMsgService voiceMsgService;
@Autowired
private SmsUpMapper smsUpMapper;
@Autowired
private SnsMobileConfig snsMobileConfig;
public static long lastTime = 0;
@Scheduled(cron = "${cron_task_alarm_voice}")
public void alarmSendVoice() {
try {
long now = System.currentTimeMillis();
QueryResult queryResult = monitorAlarmMapper.selectVoiceAlarm(InfluxDBContants.AWS, 120);
int count = QueryResultUtil.getCount(queryResult);
if (count > 5){//大于无
//todo 查询是否需要语音通知
boolean needVoice = true;
QueryResult queryResult1 = smsUpMapper.select(30);
int voiceCount = QueryResultUtil.getCount(queryResult1);
if (voiceCount > 1){
if (lastTime == 0){
lastTime = now;
}else {
if (now - lastTime < 30 * 60 * 1000){//三十分钟内不再发送
needVoice = false;
}
}
}
if (needVoice){
lastTime = now;
voiceMsgService.sendVoide(snsMobileConfig.getBaseMobile());
}
}
}catch (Exception e){
e.printStackTrace();
}
}
}
... ...
... ... @@ -4,7 +4,7 @@ sendsms.username=yohoyw
sendsms.pwd=NCftHmJ9
sendsms.notice.productid=8
base_mobile=18751986615,18652008443,18502542319
base_mobile=18751986615,18652008443,18502542319,15150509659,13515100825,18252034289
swaith_mobile=15905144483,18751986615
dns_exception_mobile=13915992579,18751986615,18652008443
... ...
... ... @@ -24,3 +24,5 @@ cron_task_javaservice_alarm=0/30 * * * * ?
cron_task_memcached=0 0/1 * * * ?
cron_task_alarm_voice=0 0 0 * * ?
... ...
... ... @@ -30,3 +30,5 @@ cron_task_zabbix_scan=0 0 0 * * ?
cron_task_javaservice_alarm=0 0 0 * * ?
cron_task_memcached=0 0 0 * * ?
cron_task_alarm_voice=0 0/1 * * * ?
... ...