Authored by jack-xue

fix bug

@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils; @@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
22 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.beans.factory.annotation.Qualifier; 23 import org.springframework.beans.factory.annotation.Qualifier;
24 import org.springframework.beans.factory.annotation.Value; 24 import org.springframework.beans.factory.annotation.Value;
  25 +import org.springframework.http.client.SimpleClientHttpRequestFactory;
25 import org.springframework.stereotype.Component; 26 import org.springframework.stereotype.Component;
26 import org.springframework.util.LinkedMultiValueMap; 27 import org.springframework.util.LinkedMultiValueMap;
27 import org.springframework.util.MultiValueMap; 28 import org.springframework.util.MultiValueMap;
@@ -7,6 +7,7 @@ import com.monitor.common.config.SnsMobileConfig; @@ -7,6 +7,7 @@ import com.monitor.common.config.SnsMobileConfig;
7 import com.monitor.common.service.AlarmMsgService; 7 import com.monitor.common.service.AlarmMsgService;
8 import com.monitor.javaserver.common.JavaApiStatics; 8 import com.monitor.javaserver.common.JavaApiStatics;
9 import com.monitor.javaserver.handle.IJavaApiHadnler; 9 import com.monitor.javaserver.handle.IJavaApiHadnler;
  10 +import org.apache.commons.lang.StringUtils;
10 import org.slf4j.Logger; 11 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,31 +37,36 @@ public class MsgJavaApiHandler extends IJavaApiHadnler { @@ -36,31 +37,36 @@ public class MsgJavaApiHandler extends IJavaApiHadnler {
36 37
37 @Override 38 @Override
38 public void handler(JavaApiStatics javaApiStatics) { 39 public void handler(JavaApiStatics javaApiStatics) {
39 - String key = buildKey(javaApiStatics);  
40 - //开关关闭、告警次数未设置、无错  
41 - if (javaApiStatics.getJavaApiInfo().getApiToggle() == 0 ||  
42 - javaApiStatics.getJavaApiInfo().getApiWarnTrigger() <= 0 ||  
43 - javaApiStatics.isHasException() == false) {  
44 - if (mapStatics.containsKey(key)) {  
45 - mapStatics.remove(key); 40 + try {
  41 + String key = buildKey(javaApiStatics);
  42 + //开关关闭、告警次数未设置、无错
  43 + if (javaApiStatics.getJavaApiInfo().getApiToggle() == 0 ||
  44 + javaApiStatics.getJavaApiInfo().getApiWarnTrigger() <= 0 ||
  45 + javaApiStatics.isHasException() == false) {
  46 + if (mapStatics.containsKey(key)) {
  47 + mapStatics.remove(key);
  48 + }
  49 + return;
46 } 50 }
47 - return;  
48 - }  
49 -  
50 - int num = 0;  
51 - mapStatics.putIfAbsent(key, new AtomicInteger(0));  
52 - num = mapStatics.get(key).incrementAndGet();  
53 51
54 - JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo();  
55 - if (javaApiInfo.getApiWarnTrigger() > 0 &&  
56 - num >= javaApiInfo.getApiWarnTrigger() &&  
57 - javaApiInfo.getApiToggle() == 1) {  
58 - //告警  
59 - String msg = buildErrMsg(num, javaApiStatics);  
60 - log.info("send error msg : {} .", msg);  
61 - alarmMsgService.sendSms("java_api", msg, snsMobileConfig.getBaseMobile()); 52 + int num = 0;
  53 + mapStatics.putIfAbsent(key, new AtomicInteger(0));
  54 + num = mapStatics.get(key).incrementAndGet();
  55 +
  56 + JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo();
  57 + if (javaApiInfo.getApiWarnTrigger() > 0 &&
  58 + num >= javaApiInfo.getApiWarnTrigger() &&
  59 + javaApiInfo.getApiToggle() == 1) {
  60 + //告警
  61 + String msg = buildErrMsg(num, javaApiStatics);
  62 + log.info("send error msg : {} .", msg);
  63 + alarmMsgService.sendSms("java_api", msg, snsMobileConfig.getBaseMobile());
  64 + }
  65 + } catch (Exception e) {
  66 + log.error("Failed to handle {} send msg , error {} ", javaApiStatics, e);
62 } 67 }
63 68
  69 +
64 } 70 }
65 71
66 @Override 72 @Override
@@ -87,7 +93,11 @@ public class MsgJavaApiHandler extends IJavaApiHadnler { @@ -87,7 +93,11 @@ public class MsgJavaApiHandler extends IJavaApiHadnler {
87 .append("TYPE:" + javaApiInfo.getServiceType()).append(" , "); 93 .append("TYPE:" + javaApiInfo.getServiceType()).append(" , ");
88 94
89 if (javaApiInfo.getApiUrlCustom() != null && javaApiInfo.getApiUrlCustom() == 1) { 95 if (javaApiInfo.getApiUrlCustom() != null && javaApiInfo.getApiUrlCustom() == 1) {
90 - msgBuilder.append("URL:" + javaApiInfo.getApiUrl().substring(0, javaApiInfo.getApiUrl().indexOf("?") - 1)).append(" . "); 96 + if (StringUtils.contains(javaApiInfo.getApiUrl(), "?")) {
  97 + msgBuilder.append("URL:" + javaApiInfo.getApiUrl().substring(0, javaApiInfo.getApiUrl().indexOf("?") - 1)).append(" . ");
  98 + } else {
  99 + msgBuilder.append("URL:" + javaApiInfo.getApiUrl());
  100 + }
91 } else { 101 } else {
92 msgBuilder.append("IP:" + mObjectInfo.getMoHostIp()).append(" ."); 102 msgBuilder.append("IP:" + mObjectInfo.getMoHostIp()).append(" .");
93 } 103 }