|
|
package com.monitor.javaserver.schedule;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.monitor.common.service.AlarmMsgService;
|
|
|
import com.util.GetUsersInfoUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.net.URI;
|
|
|
|
|
|
/**
|
|
|
* Created by craig.qin on 2017/10/16.
|
|
|
* 监控一个url:联盟跳转,wap首页
|
|
|
*/
|
|
|
@Component
|
|
|
public class WapUrlAlarm
|
|
|
{
|
|
|
public static final Logger logger = LoggerFactory.getLogger(ResourcesSimplePiceAlarm.class);
|
|
|
|
|
|
public static final String WATCH_URL = "https://webunion.yohobuy.com/union/go?union_type=4&union_data=D00kvbdf4jrh3m59jj6B&go_url=https%3A%2F%2Fm.yohobuy.com&tracking_id=7869446178";
|
|
|
|
|
|
/**
|
|
|
* 根据报警组名称取成员的手机号码
|
|
|
*/
|
|
|
@Autowired
|
|
|
private GetUsersInfoUtil getUsersInfoUtil;
|
|
|
|
|
|
@Autowired
|
|
|
public AlarmMsgService alarmMsgService;
|
|
|
|
|
|
@Resource(name = "javaapiRestTemplate")
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
/**
|
|
|
* 十分钟监控一次
|
|
|
*/
|
|
|
@Scheduled(cron = "0 * * * * ?")
|
|
|
public void alarm() {
|
|
|
//发送拦截短信
|
|
|
String mobile_user = "15051889346";//葛正文的电话//getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
|
|
|
try {
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
|
|
|
//WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
|
|
|
URI uri = builder.build(true).encode().toUri();
|
|
|
// String alarmData = restTemplate.getForObject(uri, String.class);
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.add("Content-Type", "text/html");
|
|
|
headers.add("Cache-Control", "max-age=0");
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, String.class);
|
|
|
HttpStatus status = responseEntity.getStatusCode();
|
|
|
if (200!=status.value()){
|
|
|
alarm("联盟跳转页面访问异常,code="+status.value(),mobile_user);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e);
|
|
|
alarm("联盟跳转页面访问异常,探测异常",mobile_user);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void alarm(String content,String mobile) {
|
|
|
alarmMsgService.sendSms("watchuri.wap.index", content, mobile);
|
|
|
}
|
|
|
} |
...
|
...
|
|