Authored by qinchao

定时监控url的可访问行:

@@ -46,9 +46,9 @@ public class ResourcesSimplePiceAlarm { @@ -46,9 +46,9 @@ public class ResourcesSimplePiceAlarm {
46 private RestTemplate restTemplate; 46 private RestTemplate restTemplate;
47 47
48 /** 48 /**
49 - * 分钟监控一次 49 + * 3分钟监控一次
50 */ 50 */
51 - @Scheduled(cron = "0 2/10 * * * ?") 51 + @Scheduled(cron = "0 2/3 * * * ?")
52 public void alarm() { 52 public void alarm() {
53 //发送拦截短信 53 //发送拦截短信
54 String mobile_user = "13770338135";//耿超的电话//getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN); 54 String mobile_user = "13770338135";//耿超的电话//getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
@@ -56,33 +56,43 @@ public class ResourcesSimplePiceAlarm { @@ -56,33 +56,43 @@ public class ResourcesSimplePiceAlarm {
56 UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL); 56 UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
57 //WATCH_URL 包含了特殊字符,但不需要编码转义:build(true) 57 //WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
58 URI uri = builder.build(true).encode().toUri(); 58 URI uri = builder.build(true).encode().toUri();
59 - String alarmData = restTemplate.getForObject(uri, String.class);  
60 59
61 - if(alarmData==null||alarmData.length()==0){  
62 - alarm("RESOURCES.SIMPLE.PICE接口访问异常:接口返回值为null异常",mobile_user);  
63 - return;  
64 - } 60 + int failTimes=0;
  61 + for(int i=0;i<15;i++){
  62 + String alarmData = restTemplate.getForObject(uri, String.class);
65 63
66 - JSONObject jsonObject=JSON.parseObject(alarmData);  
67 - if(jsonObject.get("code")==null||200!=(Integer)jsonObject.get("code")){  
68 - alarm("RESOURCES.SIMPLE.PICE接口访问异常:code="+(String) jsonObject.get("code"),mobile_user);  
69 - return;  
70 - }  
71 - boolean correctData=false;  
72 - JSONObject dataJO=(JSONObject)jsonObject.get("data");  
73 - if(dataJO!=null){  
74 - if(dataJO.get("sk")!=null){  
75 - String sk=(String)dataJO.get("sk");  
76 - if(sk!=null&&sk.length()>0){  
77 - correctData=true; 64 + if(alarmData==null||alarmData.length()==0){
  65 + failTimes++;
  66 + //alarm("RESOURCES.SIMPLE.PICE接口访问异常:接口返回值为null异常",mobile_user);
  67 + return;
  68 + }
  69 +
  70 + JSONObject jsonObject=JSON.parseObject(alarmData);
  71 + if(jsonObject.get("code")==null||200!=(Integer)jsonObject.get("code")){
  72 + failTimes++;
  73 + //alarm("RESOURCES.SIMPLE.PICE接口访问异常:code="+(String) jsonObject.get("code"),mobile_user);
  74 + return;
  75 + }
  76 + boolean correctData=false;
  77 + JSONObject dataJO=(JSONObject)jsonObject.get("data");
  78 + if(dataJO!=null){
  79 + if(dataJO.get("sk")!=null){
  80 + String sk=(String)dataJO.get("sk");
  81 + if(sk!=null&&sk.length()>0){
  82 + correctData=true;
  83 + }
78 } 84 }
79 } 85 }
80 - }  
81 - if(!correctData){  
82 - alarm("RESOURCES.SIMPLE.PICE接口访问异常:data="+dataJO,mobile_user);  
83 - return; 86 + if(!correctData){
  87 + failTimes++;
  88 + //alarm("RESOURCES.SIMPLE.PICE接口访问异常:data="+dataJO,mobile_user);
  89 + return;
  90 + }
84 } 91 }
85 92
  93 + if(failTimes>=10){
  94 + alarm("RESOURCES.SIMPLE.PICE接口访问异常",mobile_user);
  95 + }
86 } catch (Exception e) { 96 } catch (Exception e) {
87 logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e); 97 logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e);
88 alarm("RESOURCES.SIMPLE.PICE接口访问异常,探测异常",mobile_user); 98 alarm("RESOURCES.SIMPLE.PICE接口访问异常,探测异常",mobile_user);