diff options
| author | wangwenrui <[email protected]> | 2020-12-30 17:48:33 +0800 |
|---|---|---|
| committer | wangwenrui <[email protected]> | 2020-12-30 17:48:33 +0800 |
| commit | 024d439a484850350fd2d8998df3a61e7dea6d7f (patch) | |
| tree | 9420da8480086c8a47aeb6dcfbe8a6efe76d74b5 | |
| parent | c41c67e23ffc370e2bbff3f5ac44b3a4c5a1b885 (diff) | |
EAL4:使用工具类替换原生equals
| -rw-r--r-- | src/main/java/com/nis/entity/TrapMessage.java | 325 | ||||
| -rw-r--r-- | src/main/java/com/nis/job/ConfagentJob.java | 43 | ||||
| -rw-r--r-- | src/main/java/com/nis/server/SNMPTrapServer.java | 24 | ||||
| -rw-r--r-- | src/main/java/com/nis/service/impl/ConfEventServiceImpl.java | 110 | ||||
| -rw-r--r-- | src/main/java/com/nis/service/impl/PromserverServiceImpl.java | 111 | ||||
| -rw-r--r-- | src/main/java/com/nis/service/impl/TrafficServiceImpl.java | 6 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/CommonUtils.java | 4 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/Constant.java | 2 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/DateUtil.java | 9 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/MybatisPlusConfig.java | 2 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/RuntimeUtil.java | 3 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/SnmpUtil.java | 11 | ||||
| -rw-r--r-- | src/main/java/com/nis/util/YamlUtil.java | 154 |
13 files changed, 369 insertions, 435 deletions
diff --git a/src/main/java/com/nis/entity/TrapMessage.java b/src/main/java/com/nis/entity/TrapMessage.java index b69bd74..3e849ff 100644 --- a/src/main/java/com/nis/entity/TrapMessage.java +++ b/src/main/java/com/nis/entity/TrapMessage.java @@ -1,162 +1,163 @@ -package com.nis.entity;
-
-import java.io.Serializable;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.snmp4j.PDU;
-import org.snmp4j.smi.Variable;
-
-public class TrapMessage implements Serializable{
-
- private String agentSendIP;
- private String pduAgentIP;
- private Timestamp receiverTime;
- private int trapVersion;
- private int trapV1GenericType;
- private int trapV1SpecificType;
- private String trapName;
- private String trapOID;
- private List trapPDUOIDs;
- private List trapPDUOIDValues;
- private PDU originalPDU;
- public static final int TrapVersionV1 = 1;
- public static final int TrapVersionV2 = 2;
-
- public TrapMessage()
- {
- agentSendIP = "";
- pduAgentIP = "";
- receiverTime = new Timestamp(System.currentTimeMillis());
- trapVersion = 1;
- trapV1GenericType = -1;
- trapV1SpecificType = -1;
- trapName = "";
- trapOID = "";
- trapPDUOIDs = new ArrayList();
- trapPDUOIDValues = new ArrayList();
- }
-
- public Variable getOIDValue(String s)
- {
- for (int i = 0; i < trapPDUOIDs.size(); i++)
- {
- String s1 = (String)trapPDUOIDs.get(i);
- if (s.equals(s1))
- return (Variable)trapPDUOIDValues.get(i);
- }
-
- return null;
- }
-
- public String getAgentSendIP()
- {
- return agentSendIP;
- }
-
- public void setAgentSendIP(String s)
- {
- agentSendIP = s;
- }
-
- public Timestamp getReceiverTime()
- {
- return receiverTime;
- }
-
- public void setReceiverTime(Timestamp timestamp)
- {
- receiverTime = timestamp;
- }
-
- public int getTrapVersion()
- {
- return trapVersion;
- }
-
- public void setTrapVersion(int i)
- {
- trapVersion = i;
- }
-
- public String getTrapName()
- {
- return trapName;
- }
-
- public void setTrapName(String s)
- {
- trapName = s;
- }
-
- public String getTrapOID()
- {
- return trapOID;
- }
-
- public void setTrapOID(String s)
- {
- trapOID = s;
- }
-
- public String getPduAgentIP()
- {
- return pduAgentIP;
- }
-
- public void setPduAgentIP(String s)
- {
- pduAgentIP = s;
- }
-
- public int getTrapV1GenericType()
- {
- return trapV1GenericType;
- }
-
- public void setTrapV1GenericType(int i)
- {
- trapV1GenericType = i;
- }
-
- public int getTrapV1SpecificType()
- {
- return trapV1SpecificType;
- }
-
- public void setTrapV1SpecificType(int i)
- {
- trapV1SpecificType = i;
- }
-
- public List getTrapPDUOIDs()
- {
- return trapPDUOIDs;
- }
-
- public void setTrapPDUOIDs(List list)
- {
- trapPDUOIDs = list;
- }
-
- public List getTrapPDUOIDValues()
- {
- return trapPDUOIDValues;
- }
-
- public void setTrapPDUOIDValues(List list)
- {
- trapPDUOIDValues = list;
- }
-
- public void setOriginalPDU(PDU pdu)
- {
- originalPDU = pdu;
- }
-
- public PDU getOriginalPDU()
- {
- return originalPDU;
- }
-}
+package com.nis.entity; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +import cn.hutool.core.util.StrUtil; +import org.snmp4j.PDU; +import org.snmp4j.smi.Variable; + +public class TrapMessage implements Serializable{ + + private String agentSendIP; + private String pduAgentIP; + private Timestamp receiverTime; + private int trapVersion; + private int trapV1GenericType; + private int trapV1SpecificType; + private String trapName; + private String trapOID; + private List trapPDUOIDs; + private List trapPDUOIDValues; + private PDU originalPDU; + public static final int TrapVersionV1 = 1; + public static final int TrapVersionV2 = 2; + + public TrapMessage() + { + agentSendIP = ""; + pduAgentIP = ""; + receiverTime = new Timestamp(System.currentTimeMillis()); + trapVersion = 1; + trapV1GenericType = -1; + trapV1SpecificType = -1; + trapName = ""; + trapOID = ""; + trapPDUOIDs = new ArrayList(); + trapPDUOIDValues = new ArrayList(); + } + + public Variable getOIDValue(String s) + { + for (int i = 0; i < trapPDUOIDs.size(); i++) + { + String s1 = (String)trapPDUOIDs.get(i); + if(StrUtil.equals(s,s1)) + return (Variable)trapPDUOIDValues.get(i); + } + + return null; + } + + public String getAgentSendIP() + { + return agentSendIP; + } + + public void setAgentSendIP(String s) + { + agentSendIP = s; + } + + public Timestamp getReceiverTime() + { + return receiverTime; + } + + public void setReceiverTime(Timestamp timestamp) + { + receiverTime = timestamp; + } + + public int getTrapVersion() + { + return trapVersion; + } + + public void setTrapVersion(int i) + { + trapVersion = i; + } + + public String getTrapName() + { + return trapName; + } + + public void setTrapName(String s) + { + trapName = s; + } + + public String getTrapOID() + { + return trapOID; + } + + public void setTrapOID(String s) + { + trapOID = s; + } + + public String getPduAgentIP() + { + return pduAgentIP; + } + + public void setPduAgentIP(String s) + { + pduAgentIP = s; + } + + public int getTrapV1GenericType() + { + return trapV1GenericType; + } + + public void setTrapV1GenericType(int i) + { + trapV1GenericType = i; + } + + public int getTrapV1SpecificType() + { + return trapV1SpecificType; + } + + public void setTrapV1SpecificType(int i) + { + trapV1SpecificType = i; + } + + public List getTrapPDUOIDs() + { + return trapPDUOIDs; + } + + public void setTrapPDUOIDs(List list) + { + trapPDUOIDs = list; + } + + public List getTrapPDUOIDValues() + { + return trapPDUOIDValues; + } + + public void setTrapPDUOIDValues(List list) + { + trapPDUOIDValues = list; + } + + public void setOriginalPDU(PDU pdu) + { + originalPDU = pdu; + } + + public PDU getOriginalPDU() + { + return originalPDU; + } +} diff --git a/src/main/java/com/nis/job/ConfagentJob.java b/src/main/java/com/nis/job/ConfagentJob.java index 8204b17..d9b1780 100644 --- a/src/main/java/com/nis/job/ConfagentJob.java +++ b/src/main/java/com/nis/job/ConfagentJob.java @@ -3,6 +3,7 @@ package com.nis.job; import cn.hutool.core.io.FileUtil; import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; import cn.hutool.log.Log; import com.alibaba.fastjson.JSON; @@ -89,7 +90,7 @@ public class ConfagentJob extends QuartzJobBean { @SuppressWarnings("unchecked") @Override - protected void executeInternal(JobExecutionContext context) throws JobExecutionException { + protected void executeInternal(JobExecutionContext context) { logger.info("task start"); @@ -151,7 +152,7 @@ public class ConfagentJob extends QuartzJobBean { } } catch (Exception e) { logger.error("yamlHanlde center error", e); - e.printStackTrace(); + } } } else if (promserverType.equals(Constant.PromserverType.PER_DATACENTER.getValue())) {// datacenter角色 @@ -179,7 +180,7 @@ public class ConfagentJob extends QuartzJobBean { } } catch (Exception e) { logger.error("yamlHanlde sub error", e); - e.printStackTrace(); + } } } @@ -207,7 +208,7 @@ public class ConfagentJob extends QuartzJobBean { } } catch (Exception e) { logger.error("prometheus global setting error : ", e); - e.printStackTrace(); + }**/ //prometheus启动项相关修改 每次需要判断是否更改来确定是否执行方法 会关闭prometheus并重启 confagent首次启动不会进行prometheus开关操作 @@ -219,7 +220,7 @@ public class ConfagentJob extends QuartzJobBean { logger.info("prometheus 配置本地保存天数" + (prometheusStartHandle ? "成功" : "失败")); } catch (Exception e) { logger.error("prometheus startup setting error : ", e); - e.printStackTrace(); + } } else if (promserverType.equals(Constant.PromserverType.THANOS_RULE.getValue())) { // thanos rule 处理 @@ -277,7 +278,7 @@ public class ConfagentJob extends QuartzJobBean { Integer index=null; if(!subInfos.isEmpty()) { for(int i=0;i<subInfos.size();i++) { - if(subInfos.get(i).getHost().equals(promserver.getHost())) { + if(StrUtil.equals(subInfos.get(i).getHost(),promserver.getHost())) { index=i; } } @@ -299,7 +300,7 @@ public class ConfagentJob extends QuartzJobBean { job.put("job_name", endpointInfos.get(m).getId()); job.put("metrics_path", endpointInfos.get(m).getPath()); List list=new ArrayList(); - if(StringUtils.isNotBlank(type)&&type.equals(ModuleTypeEnum.SNMP.getValue())) { + if(StringUtils.isNotBlank(type)&&StrUtil.equals(type,ModuleTypeEnum.SNMP.getValue())) { list.add(ipaddr+":"+snmpPort); job.put("metrics_path", "/snmp"); }else { @@ -339,7 +340,7 @@ public class ConfagentJob extends QuartzJobBean { job5.put("regex", "job"); job5.put("action", "labeldrop"); // 控制开关 是否保留instance标签 - if(instanceLabel.equals("0")) { + if(StrUtil.equals(instanceLabel,"0")) { Map job6=new LinkedHashMap(); job6.put("regex", "instance"); job6.put("action", "labeldrop"); @@ -351,7 +352,7 @@ public class ConfagentJob extends QuartzJobBean { // 配置metric_relabel_config // 控制开关 是否保留instance标签 - if(instanceLabel.equals("0")) { + if(StrUtil.equals(instanceLabel,"0")) { List list4 =new ArrayList(); Map job7 =new LinkedHashMap(); job7.put("regex", "instance"); @@ -359,7 +360,7 @@ public class ConfagentJob extends QuartzJobBean { list4.add(job7); job.put("metric_relabel_configs", list4); } - if(StringUtils.isNotBlank(type)&&type.equals(ModuleTypeEnum.HTTP.getValue())) { + if(StringUtils.isNotBlank(type)&&StrUtil.equals(type,ModuleTypeEnum.HTTP.getValue())) { //处理endpoint中param字段json串 请求参数 String param = endpointInfos.get(m).getParam(); Map params=null; @@ -375,7 +376,7 @@ public class ConfagentJob extends QuartzJobBean { if(params!=null) { job.put("params",params); } - }else if(StringUtils.isNotBlank(type)&&type.equals(ModuleTypeEnum.SNMP.getValue())) { + }else if(StringUtils.isNotBlank(type)&&StrUtil.equals(type,ModuleTypeEnum.SNMP.getValue())) { Map params=new LinkedHashMap(); List snmpL1=new ArrayList(); snmpL1.add(endpointInfos.get(m).getHost()+":"+endpointInfos.get(m).getPort()); @@ -548,17 +549,17 @@ public class ConfagentJob extends QuartzJobBean { if(!sysConfigs.isEmpty()) { for(SysConfig sysconfig : sysConfigs) { - if(sysconfig.getParamKey().equals(AlertManagerEnum.ALERT_API.getValue())) { + if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.ALERT_API.getValue())) { nezhaMetricsList2.add(sysconfig.getParamValue()); - }else if(sysconfig.getParamKey().equals(AlertManagerEnum.ALERT_PATH_PREFIX.getValue())){ + }else if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.ALERT_PATH_PREFIX.getValue())){ nezhaMetrics.put("metrics_path", sysconfig.getParamValue()+metricsPath); - }else if(sysconfig.getParamKey().equals(AlertManagerEnum.CONFAGENT_PORT.getValue())) { + }else if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.CONFAGENT_PORT.getValue())) { for(String confagentIp : confagentIps) { confagentMetricsList2.add(confagentIp+":"+sysconfig.getParamValue()); } }/*else if(sysconfig.getParamKey().equals(AlertManagerEnum.CONFAGENT_API.getValue())) { confagentMetricsList2.add(sysconfig.getParamValue()); - }*/else if(sysconfig.getParamKey().equals(AlertManagerEnum.CONFAGENT_PATH.getValue())) { + }*/else if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.CONFAGENT_PATH.getValue())) { confagentMetrics.put("metrics_path", sysconfig.getParamValue()+metricsPath); } } @@ -665,7 +666,7 @@ public class ConfagentJob extends QuartzJobBean { //获取配置文件判断是否需要添加endpoint state告警 String endpointAlertPush = sysConfigService.queryValueByParamkey(Constant.ENDPOINT_ALERT_PUSH); - if (ObjectUtils.isNotEmpty(endpointAlertPush) && endpointAlertPush.equals("1")) { + if(ObjectUtils.isNotEmpty(endpointAlertPush) &&StrUtil.equals( endpointAlertPush,"1")) { String endpointAlert = sysConfigService.queryValueByParamkey(Constant.ENDPOINT_ALERT_RULE); Map endpointAlertMap = (Map) JSON.parse(endpointAlert); String alertName = (String) endpointAlertMap.get("alertName"); @@ -709,9 +710,9 @@ public class ConfagentJob extends QuartzJobBean { List alertData = new ArrayList(); if (!sysConfigs.isEmpty()) { for (SysConfig sysconfig : sysConfigs) { - if (sysconfig.getParamKey().equals(AlertManagerEnum.ALERT_API.getValue())) { + if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.ALERT_API.getValue())) { alertData.add(sysconfig.getParamValue()); - } else if (sysconfig.getParamKey().equals(AlertManagerEnum.ALERT_PATH_PREFIX.getValue())) { + } else if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.ALERT_PATH_PREFIX.getValue())) { staticConfigs.put("path_prefix", sysconfig.getParamValue()); } } @@ -851,7 +852,7 @@ public class ConfagentJob extends QuartzJobBean { Pattern p = Pattern.compile("--storage.tsdb.retention.time=\\d*d"); Matcher m = p.matcher(readLine); while (m.find()) { - if (!"".equals(m.group())) { + if(!StrUtil.equals("",m.group())) { String result = m.group(); String str1=result.substring(0, result.indexOf("=")); String str2 = result.substring(str1.length()+1, result.length()); @@ -865,7 +866,7 @@ public class ConfagentJob extends QuartzJobBean { lastPoint = ponit; } // 判断本地的保存时间与数据库的设置时间是否一致 不一致则更新同步 - if(!time.equals(retentionDays)) { + if(!StrUtil.equals(time,retentionDays)) { logger.error("prometheus going to restart , local time is "+ time); /*RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl stop prometheus"}); RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl start prometheus"});*/ @@ -894,7 +895,7 @@ public class ConfagentJob extends QuartzJobBean { readLine = split[1]; } } catch (FileNotFoundException e) { - e.printStackTrace(); + logger.error("获取prometheus.services失败,未找到该文件,路径有误,错误信息是:"+e.getMessage(), e); } catch (IOException e) { logger.error("处理prometheus.service文件失败,错误信息是:"+e.getMessage(), e); diff --git a/src/main/java/com/nis/server/SNMPTrapServer.java b/src/main/java/com/nis/server/SNMPTrapServer.java index b756af8..7363c4d 100644 --- a/src/main/java/com/nis/server/SNMPTrapServer.java +++ b/src/main/java/com/nis/server/SNMPTrapServer.java @@ -2,6 +2,7 @@ package com.nis.server; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; @@ -13,6 +14,7 @@ import java.util.Vector; import javax.annotation.PostConstruct; +import cn.hutool.core.util.StrUtil; import cn.hutool.log.Log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -108,11 +110,11 @@ public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// imp private ConfagentMetrics confagentMetrics; @Override - public void run(ApplicationArguments args) throws Exception { + public void run(ApplicationArguments args) throws IOException { initServer(); } - public void initServer() throws Exception{ + public void initServer() throws IOException { logger.info("snmpTrapThredPoolSize is {}",snmpTrapThredPoolSize); ThreadPool threadPool = ThreadPool.create("Trap", Integer.valueOf(snmpTrapThredPoolSize)); logger.info("snmpTrapThredPoolSize is {}",snmpTrapThredPoolSize); @@ -141,9 +143,9 @@ public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// imp } private OID getAuthProtocol(String auth){ - if (auth.equals("MD5")) { + if(StrUtil.equals(auth,"MD5")) { return AuthMD5.ID; - } else if (auth.equals("SHA")) { + } else if(StrUtil.equals(auth,"SHA")) { return AuthSHA.ID; }else{ return null; @@ -151,14 +153,14 @@ public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// imp } private OID getPrivProtocol(String priv){ - if (priv.equals("DES")) { + if(StrUtil.equals(priv,"DES")) { return PrivDES.ID; } else if ((priv.equals("AES128")) || (priv.equals("AES"))) { return PrivAES128.ID; } else if (priv.equals("AES192")) { return PrivAES192.ID; - } else if (priv.equals("AES256")) { + } else if(StrUtil.equals(priv,"AES256")) { return PrivAES256.ID; }else{ return null; @@ -184,9 +186,9 @@ public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// imp List<SysConfig> sysConfigs = sysConfigService.queryList(); if(!sysConfigs.isEmpty()) { for(SysConfig sysconfig : sysConfigs) { - if(sysconfig.getParamKey().equals(AlertManagerEnum.ALERT_API.getValue())) { + if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.ALERT_API.getValue())) { alertApi=sysconfig.getParamValue(); - }else if(sysconfig.getParamKey().equals(AlertManagerEnum.ALERT_PATH_PREFIX.getValue())){ + }else if(StrUtil.equals(sysconfig.getParamKey(),AlertManagerEnum.ALERT_PATH_PREFIX.getValue())){ alertPathPrefix=sysconfig.getParamValue(); } } @@ -415,7 +417,7 @@ public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// imp bs[i] = (byte) Integer.parseInt(temps[i], 16); return new String(bs, "GB2312"); - } catch (Exception e) { + } catch (UnsupportedEncodingException e) { return null; } } @@ -428,13 +430,13 @@ public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// imp String strOut = ""; int intLength = str.length; - System.out.println("长度==> " + intLength); + logger.debug("长度==> " + intLength); for (int j = 0; j < intLength; j++) { strOut += str[j]; } strCom += vb.getVariable(); if (str.length != 1) { - System.out.println("==第行=vb.getVariable()=" + SNMPTrapServer.toStringHex(strOut));//显示中文 + logger.debug("==第行=vb.getVariable()=" + SNMPTrapServer.toStringHex(strOut));//显示中文 } } return strCom; diff --git a/src/main/java/com/nis/service/impl/ConfEventServiceImpl.java b/src/main/java/com/nis/service/impl/ConfEventServiceImpl.java index d195aff..c0d485c 100644 --- a/src/main/java/com/nis/service/impl/ConfEventServiceImpl.java +++ b/src/main/java/com/nis/service/impl/ConfEventServiceImpl.java @@ -1,55 +1,55 @@ -package com.nis.service.impl;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import com.alibaba.fastjson.JSON;
-import com.nis.dao.ConfEventDao;
-import com.nis.entity.ConfEvent;
-import com.nis.service.ConfEventService;
-
-@Service
-public class ConfEventServiceImpl implements ConfEventService {
-
- @Autowired
- private ConfEventDao confEventDao;
-
- @Override
- public ConfEvent queryConfEvent(String table) {
- return confEventDao.selectConfEvent(table);
- }
-
- @Override
- public Map<String, Integer> queryConfEventMap() {
- Map<String,Integer> result = new HashMap<String,Integer>();
- List<ConfEvent> datas = confEventDao.selectList();
- if(datas.size()>0) {
- for(ConfEvent data:datas) {
- result.put(data.getTable(), data.getValue());
- }
- return result;
- }else {
- return null;
- }
- }
-
- @Override
- public boolean compareData(Map<String, Integer> map) {
- boolean flag = false;
- if(map==null) {
- flag = true;
- return flag;
- }
- List<ConfEvent> datas = confEventDao.selectList();
- for(ConfEvent data:datas) {
- if(!(data.getValue().equals(map.get(data.getTable())))) {
- flag = true;
- }
- }
- return flag;
- }
-}
+package com.nis.service.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.alibaba.fastjson.JSON; +import com.nis.dao.ConfEventDao; +import com.nis.entity.ConfEvent; +import com.nis.service.ConfEventService; + +@Service +public class ConfEventServiceImpl implements ConfEventService { + + @Autowired + private ConfEventDao confEventDao; + + @Override + public ConfEvent queryConfEvent(String table) { + return confEventDao.selectConfEvent(table); + } + + @Override + public Map<String, Integer> queryConfEventMap() { + Map<String,Integer> result = new HashMap<String,Integer>(); + List<ConfEvent> datas = confEventDao.selectList(); + if(datas.size()>0) { + for(ConfEvent data:datas) { + result.put(data.getTable(), data.getValue()); + } + return result; + }else { + return null; + } + } + + @Override + public boolean compareData(Map<String, Integer> map) { + boolean flag = false; + if(map==null) { + flag = true; + return flag; + } + List<ConfEvent> datas = confEventDao.selectList(); + for(ConfEvent data:datas) { + if(!data.getValue().equals(map.get(data.getTable()))) { + flag = true; + } + } + return flag; + } +} diff --git a/src/main/java/com/nis/service/impl/PromserverServiceImpl.java b/src/main/java/com/nis/service/impl/PromserverServiceImpl.java index a20b2ef..e16d028 100644 --- a/src/main/java/com/nis/service/impl/PromserverServiceImpl.java +++ b/src/main/java/com/nis/service/impl/PromserverServiceImpl.java @@ -1,55 +1,56 @@ -package com.nis.service.impl;
-
-import com.nis.dao.PromserverDao;
-import com.nis.entity.Promserver;
-import com.nis.service.PromserverService;
-import org.apache.commons.collections.CollectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-@Service
-public class PromserverServiceImpl implements PromserverService {
-
- @Autowired
- private PromserverDao promserverDao;
-
- public List<Promserver> queryList(){
- return promserverDao.selectList();
- }
-
- @Override
- public Promserver queryRoleByIpAndPort(String ip, String port) {
- return promserverDao.selectRoleByIpAndPort(ip, port);
- }
-
- @Override
- public List<Promserver> querySubInfos(Promserver promserver) {
- return promserverDao.selectSubInfo(promserver);
- }
-
- @Override
- public List<Promserver> querySubInfosByType(Integer type) {
- return promserverDao.selectSubInfosByType(type);
- }
-
- @Override
- public List<Promserver> queryPromServerInfosAndIdcName() {
- return promserverDao.queryPromServerInfosAndIdcName();
- }
-
- @Override
- public boolean checkEnableRule(String ipaddr, String promServerPort) {
- List<Promserver> promservers = promserverDao.queryHealthyGlobalPrometheus();
- if (CollectionUtils.isEmpty(promservers)) {
- return false;
- }
-
- Promserver promserver = promservers.get(0);
- if (promserver.getHost().equals(ipaddr) && promserver.getPort().toString().equals(promServerPort)) {
- return true;
- }
- return false;
- }
-}
+package com.nis.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.nis.dao.PromserverDao; +import com.nis.entity.Promserver; +import com.nis.service.PromserverService; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class PromserverServiceImpl implements PromserverService { + + @Autowired + private PromserverDao promserverDao; + + public List<Promserver> queryList(){ + return promserverDao.selectList(); + } + + @Override + public Promserver queryRoleByIpAndPort(String ip, String port) { + return promserverDao.selectRoleByIpAndPort(ip, port); + } + + @Override + public List<Promserver> querySubInfos(Promserver promserver) { + return promserverDao.selectSubInfo(promserver); + } + + @Override + public List<Promserver> querySubInfosByType(Integer type) { + return promserverDao.selectSubInfosByType(type); + } + + @Override + public List<Promserver> queryPromServerInfosAndIdcName() { + return promserverDao.queryPromServerInfosAndIdcName(); + } + + @Override + public boolean checkEnableRule(String ipaddr, String promServerPort) { + List<Promserver> promservers = promserverDao.queryHealthyGlobalPrometheus(); + if (CollectionUtils.isEmpty(promservers)) { + return false; + } + + Promserver promserver = promservers.get(0); + if(StrUtil.equals(promserver.getHost(),ipaddr) && StrUtil.equals(promserver.getPort().toString(),promServerPort)) { + return true; + } + return false; + } +} diff --git a/src/main/java/com/nis/service/impl/TrafficServiceImpl.java b/src/main/java/com/nis/service/impl/TrafficServiceImpl.java index 323967b..27bdcee 100644 --- a/src/main/java/com/nis/service/impl/TrafficServiceImpl.java +++ b/src/main/java/com/nis/service/impl/TrafficServiceImpl.java @@ -1,5 +1,6 @@ package com.nis.service.impl; +import cn.hutool.core.util.StrUtil; import cn.hutool.log.Log; import com.alibaba.fastjson.JSONObject; import com.nis.dao.TrafficDao; @@ -95,7 +96,7 @@ public class TrafficServiceImpl implements TrafficService { continue; } - if (index.equals(traffic.getIfIndex().toString())) { + if(StrUtil.equals(index,traffic.getIfIndex().toString())) { // ifSpecific已过时 if (name.contains("ifSpecific")) continue; if (trafficDirection.contains(Constant.TRAFFIC_RX)) { @@ -111,7 +112,8 @@ public class TrafficServiceImpl implements TrafficService { if (StringUtils.isNotEmpty(trafficTags)) { tagMap = JSONObject.parseObject(trafficTags, Map.class); for (Map.Entry<String, String> tagEntry : tagMap.entrySet()) { - if (tagEntry.getKey().toLowerCase().equals("ifIndex".toLowerCase())) continue; +// if (tagEntry.getKey().toLowerCase().equals("ifIndex".toLowerCase())) continue; + if (StrUtil.equals(tagEntry.getKey().toLowerCase(),"ifIndex".toLowerCase())) continue; tagStr += tagEntry.getKey() + "=" + "\"" + tagEntry.getValue() + "\"" + ","; } } diff --git a/src/main/java/com/nis/util/CommonUtils.java b/src/main/java/com/nis/util/CommonUtils.java index f95e596..be52c28 100644 --- a/src/main/java/com/nis/util/CommonUtils.java +++ b/src/main/java/com/nis/util/CommonUtils.java @@ -1,5 +1,7 @@ package com.nis.util; +import cn.hutool.core.util.StrUtil; + import java.io.File; import java.util.*; import java.util.regex.Pattern; @@ -36,7 +38,7 @@ public class CommonUtils { } // 字符序列集 - if ((obj instanceof CharSequence) && "".equals(obj.toString().trim())) { + if((obj instanceof CharSequence) && StrUtil.equals( "",obj.toString().trim())) { return true; } // 单列集合 diff --git a/src/main/java/com/nis/util/Constant.java b/src/main/java/com/nis/util/Constant.java index 3a1ee4d..5beb762 100644 --- a/src/main/java/com/nis/util/Constant.java +++ b/src/main/java/com/nis/util/Constant.java @@ -98,7 +98,7 @@ public class Constant { try { databaseId = databaseIdProvider.getDatabaseId(dataSource); } catch (SQLException e) { - System.out.println(LogPrintUtil.print(e)); + logger.debug(LogPrintUtil.print(e)); } DB_TYPE = databaseId; } diff --git a/src/main/java/com/nis/util/DateUtil.java b/src/main/java/com/nis/util/DateUtil.java index 0fd0424..f901f59 100644 --- a/src/main/java/com/nis/util/DateUtil.java +++ b/src/main/java/com/nis/util/DateUtil.java @@ -15,16 +15,13 @@ */ package com.nis.util; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.time.DateFormatUtils; - -import java.sql.Timestamp; -import java.text.DateFormat; +import cn.hutool.log.Log; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class DateUtil { + private final static Log logger = Log.get(); private static final Object lock = new Object(); @@ -61,7 +58,7 @@ public class DateUtil { sdf.setTimeZone(TimeZone.getDefault()); parse = sdf.parse(format); } catch (ParseException e) { - e.printStackTrace(); + logger.error(e); } return parse; } diff --git a/src/main/java/com/nis/util/MybatisPlusConfig.java b/src/main/java/com/nis/util/MybatisPlusConfig.java index 0a0ce3f..b3e1a56 100644 --- a/src/main/java/com/nis/util/MybatisPlusConfig.java +++ b/src/main/java/com/nis/util/MybatisPlusConfig.java @@ -58,7 +58,7 @@ public class MybatisPlusConfig { try { databaseId = databaseIdProvider.getDatabaseId(dataSource); } catch (SQLException e) { - System.out.println(LogPrintUtil.print(e)); + logger.debug(LogPrintUtil.print(e)); } switch (databaseId){ diff --git a/src/main/java/com/nis/util/RuntimeUtil.java b/src/main/java/com/nis/util/RuntimeUtil.java index 26e164f..ce52238 100644 --- a/src/main/java/com/nis/util/RuntimeUtil.java +++ b/src/main/java/com/nis/util/RuntimeUtil.java @@ -12,6 +12,7 @@ import java.io.StringReader; import java.util.*; import java.util.concurrent.TimeUnit; +import cn.hutool.core.util.StrUtil; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -207,7 +208,7 @@ public class RuntimeUtil { BufferReaderWrapper reader = new BufferReaderWrapper(stringReader); for (String temp = readLine(reader); temp != null; temp = readLine(reader)) { - if (skipWhiteLine == false || !temp.trim().equals("")) { + if(skipWhiteLine == false || !StrUtil.equals(temp.trim(),"")) { result.append(temp + "\n"); } } diff --git a/src/main/java/com/nis/util/SnmpUtil.java b/src/main/java/com/nis/util/SnmpUtil.java index cc1cc72..4cee03e 100644 --- a/src/main/java/com/nis/util/SnmpUtil.java +++ b/src/main/java/com/nis/util/SnmpUtil.java @@ -1,5 +1,6 @@ package com.nis.util; +import cn.hutool.core.util.StrUtil; import cn.hutool.log.Log; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; @@ -39,17 +40,17 @@ public class SnmpUtil { // 添加用户 OID authProtocolOid = null; String authProtocol = auth.get("authProtocol"); - if ("MD5".equals(authProtocol)) { + if(StrUtil.equals("MD5",authProtocol)) { authProtocolOid = AuthMD5.ID; - } else if ("SHA".equals(authProtocol)) { + } else if(StrUtil.equals("SHA",authProtocol)) { authProtocolOid = AuthSHA.ID; } OID privProtocolOid = null; String privProtocol = auth.get("privProtocol"); - if ("DES".equals(privProtocol)) { + if(StrUtil.equals("DES",privProtocol)) { privProtocolOid = PrivDES.ID; - } else if ("AES".equals(privProtocol)) { + } else if(StrUtil.equals("AES",privProtocol)) { privProtocolOid = PrivAES128.ID; } @@ -189,7 +190,7 @@ public class SnmpUtil { map.put("type", vb.getVariable().getSyntaxString()); // 时间类型值转为long类型 - if("TimeTicks".equals(vb.getVariable().getSyntaxString())){ + if(StrUtil.equals("TimeTicks",vb.getVariable().getSyntaxString())){ TimeTicks variable = (TimeTicks) vb.getVariable(); map.put("value", variable.getValue()); } diff --git a/src/main/java/com/nis/util/YamlUtil.java b/src/main/java/com/nis/util/YamlUtil.java index ea51072..6f5d3f1 100644 --- a/src/main/java/com/nis/util/YamlUtil.java +++ b/src/main/java/com/nis/util/YamlUtil.java @@ -7,6 +7,8 @@ import cn.hutool.log.Log; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.jcraft.jsch.IO; +import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.DumperOptions; @@ -45,25 +47,16 @@ public class YamlUtil { y.dump(load,osw); } flag = true; - } catch (Exception e) { + } catch (FileNotFoundException e) { + logger.error("snmpYmlHandle error : "+e.getMessage(),e); + } catch (UnsupportedEncodingException e) { logger.error("snmpYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); } finally { if(out!=null) { - try { - out.close(); - } catch (IOException e) { - logger.error("snmpYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(out); } if(osw!=null) { - try { - osw.close(); - } catch (IOException e) { - logger.error("snmpYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(osw); } } } @@ -107,33 +100,19 @@ public class YamlUtil { y.dump(param,osw); flag = true; - } catch (Exception e) { + } catch (FileNotFoundException e) { + logger.error("subYmlHandle error : "+e.getMessage(),e); + } catch (UnsupportedEncodingException e) { logger.error("subYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); } finally { if(fileInputStream!=null) { - try { - fileInputStream.close(); - } catch (IOException e) { - logger.error("subYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(fileInputStream); } if(out!=null) { - try { - out.close(); - } catch (IOException e) { - logger.error("subYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(out); } if(osw!=null) { - try { - osw.close(); - } catch (IOException e) { - logger.error("subYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(osw); } } } @@ -195,57 +174,30 @@ public class YamlUtil { flag = true; - } catch (Exception e) { + } catch (UnsupportedEncodingException e) { + logger.error("centerYmlHandle error : "+e.getMessage(),e); + } catch (FileNotFoundException e) { + logger.error("centerYmlHandle error : "+e.getMessage(),e); + } catch (IOException e) { logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); } finally { if(fileInputStream!=null) { - try { - fileInputStream.close(); - } catch (IOException e) { - logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(fileInputStream); } if(out!=null) { - try { - out.close(); - } catch (IOException e) { - logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(out); } if(osw!=null) { - try { - osw.close(); - } catch (IOException e) { - logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(osw); } if(fileInputStream2!=null) { - try { - fileInputStream2.close(); - } catch (IOException e) { - logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(fileInputStream2); } if(out2!=null) { - try { - out.close(); - } catch (IOException e) { - logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(out2); } if(osw2!=null) { - try { - osw.close(); - } catch (IOException e) { - logger.error("centerYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(osw2); } } } @@ -285,25 +237,18 @@ public class YamlUtil { OutputStreamWriter osw2 = new OutputStreamWriter(out2, "UTF-8"); y.dump(map2, osw2); flag = true; - } catch (Exception e) { + } catch (UnsupportedEncodingException e) { + logger.error("thanosRuleYmlHandle error : "+e.getMessage(),e); + } catch (FileNotFoundException e) { + logger.error("thanosRuleYmlHandle error : "+e.getMessage(),e); + } catch (IOException e) { logger.error("thanosRuleYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); } finally { if (fileInputStream != null) { - try { - fileInputStream.close(); - } catch (IOException e) { - logger.error("thanosRuleYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(fileInputStream); } if (out != null) { - try { - out.close(); - } catch (IOException e) { - logger.error("thanosRuleYmlHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(out); } } } @@ -345,18 +290,13 @@ public class YamlUtil { flag=true; } catch (FileNotFoundException e) { logger.error("prometheusStartHandle error : FileNotFoundException "+e.getMessage(),e); - e.printStackTrace(); + } catch (IOException e) { logger.error("prometheusStartHandle error : IOException "+e.getMessage(),e); - e.printStackTrace(); + } finally { if(raf!=null) { - try { - raf.close(); - } catch (IOException e) { - logger.error("prometheusStartHandle error : FileNotFoundException "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(raf); } } return flag; @@ -401,33 +341,19 @@ public class YamlUtil { y.dump(map,osw); flag = true; - } catch (Exception e) { + } catch (FileNotFoundException e) { + logger.error("prometheusSettingHandle error : "+e.getMessage(),e); + } catch (UnsupportedEncodingException e) { logger.error("prometheusSettingHandle error : "+e.getMessage(),e); - e.printStackTrace(); } finally { if(fileInputStream!=null) { - try { - fileInputStream.close(); - } catch (IOException e) { - logger.error("prometheusSettingHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(fileInputStream); } if(out!=null) { - try { - out.close(); - } catch (IOException e) { - logger.error("prometheusSettingHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(out); } if(osw!=null) { - try { - osw.close(); - } catch (IOException e) { - logger.error("prometheusSettingHandle error : "+e.getMessage(),e); - e.printStackTrace(); - } + IOUtils.closeQuietly(osw); } } } |
