Authored by qinchao

短信添加开关

... ... @@ -2,9 +2,12 @@ package com.monitor.awstools.comp;
import com.monitor.awstools.constant.Constants;
import com.monitor.awstools.task.AwsTask;
import com.monitor.common.util.ZkClientUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.*;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.apache.curator.utils.ZKPaths;
import org.quartz.JobKey;
import org.slf4j.Logger;
... ... @@ -23,7 +26,7 @@ public class TaskListener {
public static final Logger DEBUG = LoggerFactory.getLogger(TaskListener.class);
@Autowired
ZkClient zkClient;
ZkClientUtil zkClient;
@Autowired
TaskScheduler taskScheduler;
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.awstools.comp;
import com.monitor.awstools.constant.Constants;
import com.monitor.awstools.constant.JobType;
import com.monitor.awstools.task.AwsTask;
import com.monitor.common.util.ZkClientUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.CreateMode;
... ... @@ -26,7 +27,7 @@ public class TaskSaver {
public static final Logger DEBUG = LoggerFactory.getLogger(TaskSaver.class);
@Autowired
ZkClient zkClient;
ZkClientUtil zkClient;
public void storeJob(Map<String, String> proMaps) {
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.awstools.comp;
import com.monitor.awstools.constant.Constants;
import com.monitor.awstools.constant.TaskStatus;
import com.monitor.common.util.ZkClientUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.curator.utils.ZKPaths;
import org.quartz.JobExecutionContext;
... ... @@ -21,7 +22,7 @@ public class TriggerListenerImpl implements TriggerListener {
public static final Logger DEBUG = LoggerFactory.getLogger(TriggerListenerImpl.class);
@Autowired
ZkClient zkClient;
ZkClientUtil zkClient;
@Override
public String getName() {
... ...
... ... @@ -5,6 +5,7 @@ import com.monitor.common.config.SendsmsConfig;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.common.service.HttpRestClientService;
import com.monitor.common.util.MD5Util;
import com.monitor.common.util.ZkClientUtil;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.MonitorAlarmMapper;
import com.monitor.model.domain.QcloudSms;
... ... @@ -37,6 +38,9 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
@Autowired
private MonitorAlarmMapper monitorAlarmMapper;
@Autowired
private ZkClientUtil zkClient;
private Logger logger = LoggerFactory.getLogger(AlarmMsgServiceImpl.class);
... ... @@ -44,6 +48,9 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
private Map<String, Long> msgSentLogMap = new HashMap<>();
private String ZK_PATH = "/yh/config/";
private String smsSendSwitch="ops.sendsms.open";
/**
* 发送短信
*
... ... @@ -70,21 +77,18 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
}
private boolean sendSmsPrivate(String type, String content, String alarmInfo, String mobile,boolean checkZkOpen) {
/*
//所有的发送信息都不需要校验了
if(checkZkOpen){
String open = zookeeperService.getData("ops.sendsms.open");
if (!"true".equals(open)){
logger.info("Send msg type {} content {} alarmInfo {} moniole {}...refused open {}", type, content, alarmInfo, mobile,open);
return false;
}
}*/
//无需发送
/* if (true) {
return true;
//根据zk的开关判断是否需要发送数据
String open="";
try{
//zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendSwitch,"true".getBytes("UTF-8"));
open = new String(zkClient.getCuratorFramework().getData().forPath(ZK_PATH + smsSendSwitch));
} catch (Exception e) {
logger.error("Send msg type get ZK_PATH smsSendSwitch error",e);
}
*/
if(StringUtils.isNotBlank(open)&&"false".equals(open)){
return false;//短信开关关掉了,不再发送短信
}
//无需发送
if (!checkSentOrNo(type, content, mobile)) {
return true;
... ...
package com.monitor.awstools.comp;
package com.monitor.common.util;
import lombok.Getter;
import org.apache.curator.RetryPolicy;
... ... @@ -16,8 +16,8 @@ import javax.annotation.PostConstruct;
* Created by yoho on 2016/8/30.
*/
@Component
public class ZkClient {
public static final Logger DEBUG = LoggerFactory.getLogger(ZkClient.class);
public class ZkClientUtil {
public static final Logger DEBUG = LoggerFactory.getLogger(ZkClientUtil.class);
@Value("${zookeeper.address}")
private String zkAddress;
... ...
package com.monitor.other.sms.ctrl;
import com.monitor.model.response.BaseResponse;
import com.monitor.other.sms.service.SmsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by craig.qin on 2017/10/20.
*/
@Controller
@RequestMapping("/OpsSmsOnOff")
public class OpsSmsOnOffController {
@Autowired
SmsLogService smsLogService;
@RequestMapping("/turn")
@ResponseBody
public BaseResponse turn(String key){
return smsLogService.setSmsTurnOnOff(key);
}
}
... ...
... ... @@ -4,7 +4,6 @@ import com.model.SMSLogs;
import com.monitor.model.request.SmsLogReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.SMSLogsMapper;
import com.monitor.other.sms.service.SmsLogService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
... ... @@ -15,8 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* Created by yoho on 2016/11/29.
*/
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.other.sms.service;
import com.model.SMSLogs;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
/**
... ... @@ -10,4 +11,6 @@ import com.monitor.model.response.PageResponse;
public interface SmsLogService {
PageResponse<SMSLogs> getSmsLogs(PageRequest req);
BaseResponse setSmsTurnOnOff(String key);
}
... ...
package com.monitor.other.sms.service.impl;
import com.model.SMSLogs;
import com.model.WorkJob;
import com.monitor.influxdb.util.DateFormatUtil;
import com.monitor.common.util.ZkClientUtil;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageRequest;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.SMSLogsMapper;
import com.monitor.mysql.mapper.WorkJobMapper;
import com.monitor.other.sms.service.SmsLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
... ... @@ -23,9 +21,33 @@ import java.util.List;
@Service
public class SmsLogServiceImpl implements SmsLogService {
public static final Logger logger = LoggerFactory.getLogger(SmsLogServiceImpl.class);
@Autowired
private SMSLogsMapper smsLogsMapper;
@Autowired
private ZkClientUtil zkClient;
private String ZK_PATH = "/yh/config/";
private String smsSendSwitch="ops.sendsms.open";
public BaseResponse setSmsTurnOnOff(String key){
BaseResponse res=null;
try{
String value="true";
if("off".equals(key)){
value="false";
}
zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendSwitch,"false".getBytes("UTF-8"));
res= new BaseResponse(200,"ok");
} catch (Exception e) {
logger.error("set ZK_PATH smsSendSwitch error",e);
res=new BaseResponse("set zk data error");
}
return res;
}
public PageResponse<SMSLogs> getSmsLogs(PageRequest req){
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
... ...