...
|
...
|
@@ -29,7 +29,8 @@ import java.util.*; |
|
|
* Created by yoho on 2016/8/1.
|
|
|
*/
|
|
|
@Service("dnsMonitorService")
|
|
|
public class DNSMonitorServiceImpl implements IDNSMonitorService{
|
|
|
public class DNSMonitorServiceImpl implements IDNSMonitorService {
|
|
|
public static final Logger DEBUG = LoggerFactory.getLogger(DNSMonitorServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
DNSConfig dnsConfig;
|
...
|
...
|
@@ -56,7 +57,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
|
|
|
/**
|
|
|
* 监控DNS域名解析是否出现异常
|
|
|
*
|
|
|
* <p>
|
|
|
* host + uid 组合遍历
|
|
|
* 1.是否能解析出ip
|
|
|
* 2.ip是否能访问并且返回预期数据
|
...
|
...
|
@@ -79,7 +80,10 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
|
|
|
for (String uid : dnsConfig.getUids()) {
|
|
|
|
|
|
String result = restTemplateNoEncode.doGet(buildDNSUrl(host,uid));
|
|
|
String result = restTemplateNoEncode.doGet(buildDNSUrl(host, uid));
|
|
|
|
|
|
DEBUG.info("query dns result {} from host {}", result, host);
|
|
|
|
|
|
List<String> ipModelList = parseIPModels(result);
|
|
|
|
|
|
if (null == ipModelList) {
|
...
|
...
|
@@ -117,12 +121,13 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
|
|
|
/**
|
|
|
* 检测ip是否能正常访问,并且返回预期数据,否则短信告警
|
|
|
*
|
|
|
* <p>
|
|
|
* m.yoho.com域名返回为网页,其他域名不注明则为api接口
|
|
|
*
|
|
|
* @param host
|
|
|
* @param ipList
|
|
|
*/
|
|
|
private void monitIPConnection(String host,String uid, List<String> ipList,
|
|
|
private void monitIPConnection(String host, String uid, List<String> ipList,
|
|
|
Map<String, List<IPConnectModel>> ipConnectionMaps) {
|
|
|
|
|
|
if (InterVar.M_YOHOBUY_COM.equals(host)) {
|
...
|
...
|
@@ -200,7 +205,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
IDNSMonitorMapper.RETURN_DATA_CODE_NOT_200, response);
|
|
|
|
|
|
ipConnectModels.add(new IPConnectModel(ip, InterVar.FAILED,
|
|
|
InterVar.RETURN_DATA_CODE_NOT_200 + " " + response) );
|
|
|
InterVar.RETURN_DATA_CODE_NOT_200 + " " + response));
|
|
|
|
|
|
logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {}, response {} ",
|
|
|
host, uid, ip, response);
|
...
|
...
|
@@ -226,9 +231,10 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
|
|
|
/**
|
|
|
* 监控m.yohobuy.com dns的ip是否正常
|
|
|
*
|
|
|
* <p>
|
|
|
* 1.ip通
|
|
|
* 2.返回预期数据
|
|
|
*
|
|
|
* @param host
|
|
|
* @param uid
|
|
|
* @param ipList
|
...
|
...
|
@@ -272,7 +278,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
InterVar.HTTPS + ip + dnsConfig.getServices().get(host));
|
|
|
|
|
|
//验证返回网页是否正确 如果不含有该字符串则返回结果错误
|
|
|
if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) {
|
|
|
if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) {
|
|
|
errorIPs.add(ip);
|
|
|
|
|
|
alarmInfo.append(" ip: ");
|
...
|
...
|
@@ -315,8 +321,12 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
private List<String> parseIPModels(String result) {
|
|
|
String decodeResult = AESUtil.decode(result);
|
|
|
|
|
|
DNSIPsModel dnsiPsModel = JSON.parseObject(decodeResult, DNSIPsModel.class);
|
|
|
List<IPModel> ipModelList = JSON.parseArray(dnsiPsModel.getContent() , IPModel.class);
|
|
|
DEBUG.info("decode dns result {} ", decodeResult);
|
|
|
DNSIPsModel dnsiPsModel = JSON.parseObject(decodeResult, DNSIPsModel.class);
|
|
|
|
|
|
DEBUG.info("parse DNSIPsModel result {} ", dnsiPsModel.getContent());
|
|
|
|
|
|
List<IPModel> ipModelList = JSON.parseArray(dnsiPsModel.getContent(), IPModel.class);
|
|
|
|
|
|
if (null == ipModelList) {
|
|
|
return null;
|
...
|
...
|
@@ -324,13 +334,14 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
|
|
|
List<String> ipList = new ArrayList<String>();
|
|
|
for (IPModel ipModel : ipModelList) {
|
|
|
ipList.add(ipModel.getIp());
|
|
|
ipList.add(ipModel.getIp());
|
|
|
}
|
|
|
return ipList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成dns api url 包括param的加密
|
|
|
*
|
|
|
* @param host
|
|
|
* @param uid
|
|
|
* @return
|
...
|
...
|
@@ -349,8 +360,8 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
/**
|
|
|
* dns解析ip访问失败 告警短信生成
|
|
|
*
|
|
|
* @param host 域名
|
|
|
* @param ips 域名通过dns接口返回的ip组
|
|
|
* @param host 域名
|
|
|
* @param ips 域名通过dns接口返回的ip组
|
|
|
* @param connectFailedIps 访问失败的ip组
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -371,6 +382,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ |
|
|
|
|
|
/**
|
|
|
* 域名解析接口 返回解析后的ip失败 告警信息生成方法
|
|
|
*
|
|
|
* @param host dns解析域名
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
|