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,16 +56,21 @@ public class ResourcesSimplePiceAlarm { @@ -56,16 +56,21 @@ 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 +
  60 + int failTimes=0;
  61 + for(int i=0;i<15;i++){
59 String alarmData = restTemplate.getForObject(uri, String.class); 62 String alarmData = restTemplate.getForObject(uri, String.class);
60 63
61 if(alarmData==null||alarmData.length()==0){ 64 if(alarmData==null||alarmData.length()==0){
62 - alarm("RESOURCES.SIMPLE.PICE接口访问异常:接口返回值为null异常",mobile_user); 65 + failTimes++;
  66 + //alarm("RESOURCES.SIMPLE.PICE接口访问异常:接口返回值为null异常",mobile_user);
63 return; 67 return;
64 } 68 }
65 69
66 JSONObject jsonObject=JSON.parseObject(alarmData); 70 JSONObject jsonObject=JSON.parseObject(alarmData);
67 if(jsonObject.get("code")==null||200!=(Integer)jsonObject.get("code")){ 71 if(jsonObject.get("code")==null||200!=(Integer)jsonObject.get("code")){
68 - alarm("RESOURCES.SIMPLE.PICE接口访问异常:code="+(String) jsonObject.get("code"),mobile_user); 72 + failTimes++;
  73 + //alarm("RESOURCES.SIMPLE.PICE接口访问异常:code="+(String) jsonObject.get("code"),mobile_user);
69 return; 74 return;
70 } 75 }
71 boolean correctData=false; 76 boolean correctData=false;
@@ -79,10 +84,15 @@ public class ResourcesSimplePiceAlarm { @@ -79,10 +84,15 @@ public class ResourcesSimplePiceAlarm {
79 } 84 }
80 } 85 }
81 if(!correctData){ 86 if(!correctData){
82 - alarm("RESOURCES.SIMPLE.PICE接口访问异常:data="+dataJO,mobile_user); 87 + failTimes++;
  88 + //alarm("RESOURCES.SIMPLE.PICE接口访问异常:data="+dataJO,mobile_user);
83 return; 89 return;
84 } 90 }
  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);