|
|
package com.monitor.javaserver.schedule;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.contants.AlarmGroupContants;
|
|
|
import com.monitor.common.config.SnsMobileConfig;
|
|
|
import com.monitor.common.service.AlarmMsgService;
|
|
|
import com.monitor.common.util.HttpRestClient;
|
|
|
import com.monitor.javaserver.bigdata.Vdata;
|
|
|
import com.monitor.javaserver.bigdata.ctrl.MonitAlarmCtrl;
|
|
|
import com.util.GetUsersInfoUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by craig.qin on 2017/10/16.
|
|
|
* 监控一个url
|
|
|
*
|
|
|
*/
|
|
|
@Component
|
|
|
public class ResourcesSimplePiceAlarm {
|
|
|
public static final Logger logger = LoggerFactory.getLogger(ResourcesSimplePiceAlarm.class);
|
|
|
|
|
|
public static final String WATCH_URL = "http://api.yoho.cn/?app_version=6.1.0&client_secret=502635028941287371c61be7e11ef2e5&client_type=android&gender=&method=resources.simple.pice&physical_channel=1&screen_size=1080x1776&session_key=9ed0b5a9eb5d1275ab7b9bd9be8f4fb0&udid=865586024514640f121382564bbe647&uid=500027824&v=7&yh_channel=1&os_version=android4.4.2%3APE-TL20";
|
|
|
|
|
|
/**
|
|
|
* 根据报警组名称取成员的手机号码
|
|
|
*/
|
|
|
@Autowired
|
|
|
private GetUsersInfoUtil getUsersInfoUtil;
|
|
|
|
|
|
@Autowired
|
|
|
public AlarmMsgService alarmMsgService;
|
|
|
|
|
|
@Resource(name = "javaapiRestTemplate")
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
/**
|
|
|
* 十分钟监控一次
|
|
|
*/
|
|
|
@Scheduled(cron = "0 2/10 * * * ?")
|
|
|
public void alarm() {
|
|
|
//发送拦截短信
|
|
|
String mobile_user = "13770338135";//耿超的电话//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);
|
|
|
|
|
|
if(alarmData==null||alarmData.length()==0){
|
|
|
alarm("RESOURCES.SIMPLE.PICE接口访问异常:接口返回值为null异常",mobile_user);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
JSONObject jsonObject=JSON.parseObject(alarmData);
|
|
|
if(jsonObject.get("code")==null||200!=(Integer)jsonObject.get("code")){
|
|
|
alarm("RESOURCES.SIMPLE.PICE接口访问异常:code="+(String) jsonObject.get("code"),mobile_user);
|
|
|
return;
|
|
|
}
|
|
|
boolean correctData=false;
|
|
|
JSONObject dataJO=(JSONObject)jsonObject.get("data");
|
|
|
if(dataJO!=null){
|
|
|
if(dataJO.get("sk")!=null){
|
|
|
String sk=(String)dataJO.get("sk");
|
|
|
if(sk!=null&&sk.length()>0){
|
|
|
correctData=true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(!correctData){
|
|
|
alarm("RESOURCES.SIMPLE.PICE接口访问异常:data="+dataJO,mobile_user);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e);
|
|
|
alarm("RESOURCES.SIMPLE.PICE接口访问异常,探测异常",mobile_user);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void alarm(String content,String mobile) {
|
|
|
alarmMsgService.sendSms("watchuri.resources.simple.pice", content, mobile);
|
|
|
}
|
|
|
} |
...
|
...
|
|