summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenjinsong <[email protected]>2018-10-09 18:11:38 +0800
committerchenjinsong <[email protected]>2018-10-09 18:11:38 +0800
commit3a8a20de7b24a91206b716e8afa49abe6598f2e0 (patch)
treec8b964d5aabb4e8fcdf71094ad6a068d810dd546 /src
parente0b516d3dd6f0f7f8b6424dff59af76a2a578335 (diff)
1.增加上报开关,从配置文件里配置
2.port、rule上报任务
Diffstat (limited to 'src')
-rw-r--r--src/com/nms/servlet/auto/run/AutoRunForSocketServerServlet.java31
-rw-r--r--src/com/nms/thread/NmsPortThread.java33
-rw-r--r--src/com/nms/thread/NmsRuleThread.java39
-rw-r--r--src/com/nms/thread/service/NmsReportService.java27
-rw-r--r--src/conf/myconfig.properties6
-rw-r--r--src/nis/nms/util/HttpClientUtil.java6
6 files changed, 119 insertions, 23 deletions
diff --git a/src/com/nms/servlet/auto/run/AutoRunForSocketServerServlet.java b/src/com/nms/servlet/auto/run/AutoRunForSocketServerServlet.java
index 77e08c7..b728267 100644
--- a/src/com/nms/servlet/auto/run/AutoRunForSocketServerServlet.java
+++ b/src/com/nms/servlet/auto/run/AutoRunForSocketServerServlet.java
@@ -110,21 +110,24 @@ public class AutoRunForSocketServerServlet extends HttpServlet implements Servle
}});
System.out.println(port+">>SSL通讯监听 已启动");
-
- //nms上报
- String intervalStr = BaseAction.rb.getString("nms.report.interval");
- //nms上报间隔
- long interval = StringUtil.isBlank(intervalStr) ? 300000 : Long.parseLong(intervalStr)*1000;
- //nms初次上报延时
- long now = new Date().getTime();
- long initInterval = 0l;
- if(now%interval > 0) {
- initInterval = interval-(now%interval);
+ String openStr = BaseAction.rb.getString("nms.report.open");
+ boolean open = StringUtil.isBlank(openStr) ? false : ("1".equals(openStr) ? true : false);
+ if (open) {
+ //nms上报
+ String intervalStr = BaseAction.rb.getString("nms.report.interval");
+ //nms上报间隔
+ long interval = StringUtil.isBlank(intervalStr) ? 300000 : Long.parseLong(intervalStr)*1000;
+ //nms初次上报延时
+ long now = new Date().getTime();
+ long initInterval = 0l;
+ if(now%interval > 0) {
+ initInterval = interval-(now%interval);
+ }
+
+ ThreadPoolCommon.scheduled.scheduleAtFixedRate(new NmsStatusThread(), initInterval, interval, TimeUnit.MILLISECONDS);
+ ThreadPoolCommon.scheduled.scheduleAtFixedRate(new NmsRuleThread(), initInterval, interval, TimeUnit.MILLISECONDS);
+ ThreadPoolCommon.scheduled.scheduleAtFixedRate(new NmsPortThread(), initInterval, interval, TimeUnit.MILLISECONDS);
}
-
- ThreadPoolCommon.scheduled.scheduleAtFixedRate(new NmsStatusThread(), initInterval, interval, TimeUnit.MILLISECONDS);
- ThreadPoolCommon.scheduled.scheduleAtFixedRate(new NmsRuleThread(), initInterval, interval, TimeUnit.MILLISECONDS);
- ThreadPoolCommon.scheduled.scheduleAtFixedRate(new NmsPortThread(), initInterval, interval, TimeUnit.MILLISECONDS);
}
}
diff --git a/src/com/nms/thread/NmsPortThread.java b/src/com/nms/thread/NmsPortThread.java
index d858e94..6147090 100644
--- a/src/com/nms/thread/NmsPortThread.java
+++ b/src/com/nms/thread/NmsPortThread.java
@@ -2,10 +2,14 @@ package com.nms.thread;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import net.sf.json.JSONObject;
import nis.nms.util.BaseAction;
import nis.nms.util.ConnectionOracle;
+import nis.nms.util.HttpClientUtil;
import org.apache.log4j.Logger;
@@ -30,7 +34,34 @@ public class NmsPortThread implements Runnable {
try {
connection = ConnectionOracle.getConnection();
NmsReportService service = new NmsReportService(connection);
- //ArrayList<Map<String, String>> nmsRuleInfo = service.getNmsPortInfo(nowLong, nowLong-interval);
+ ArrayList<Map<String, String>> nmsPortInfo = service.getNmsPortInfo(nowLong, nowLong-interval);
+ if (nmsPortInfo != null && nmsPortInfo.size() > 0) {
+
+ Map<String, List<Map<String, String>>> data = new HashMap<String, List<Map<String, String>>>();
+ List<Map<String, String>> results = new ArrayList<Map<String, String>>();
+
+ for (Map<String, String> info : nmsPortInfo) {
+ Map<String, String> result = new HashMap<String, String>();
+ result.put("port", info.get("ifindex"));
+ result.put("nodeName", info.get("node_name"));
+ result.put("nodeIp", info.get("node_ip"));
+ result.put("portDesc", info.get("IFDESCR"));
+ result.put("bandwidth", info.get("IFSPEED"));
+ result.put("inoctets", info.get("IFINOCTETS"));
+ result.put("outoctets", info.get("IFOUTOCTETS"));
+ result.put("inoctetsSpeed", info.get("INOCTETSSPEED"));
+ result.put("outoctetsSpeed", info.get("OUTOCTETSSPEED"));
+ result.put("inpktsSpeed", info.get("INPKTSSPEED"));
+ result.put("outpktsSpeed", info.get("OUTPKTSSPEED"));
+ result.put("recvTime", info.get("DATA_CHECK_TIME"));
+ results.add(result);
+ }
+ data.put("trafficNetflowPortInfoList", results);
+ HttpClientUtil httpUtil = new HttpClientUtil();
+ JSONObject fromObject = JSONObject.fromObject(data);
+
+ httpUtil.post(BaseAction.rb.getString("nms.port.url"), fromObject.toString());
+ }
} catch (Exception e) {
logger.error(e);
} finally {
diff --git a/src/com/nms/thread/NmsRuleThread.java b/src/com/nms/thread/NmsRuleThread.java
index 4cede0b..6dd5fa6 100644
--- a/src/com/nms/thread/NmsRuleThread.java
+++ b/src/com/nms/thread/NmsRuleThread.java
@@ -2,11 +2,15 @@ package com.nms.thread;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import net.sf.json.JSONObject;
import nis.nms.util.BaseAction;
import nis.nms.util.ConnectionOracle;
import nis.nms.util.DateUtil;
+import nis.nms.util.HttpClientUtil;
import org.apache.log4j.Logger;
@@ -31,7 +35,40 @@ public class NmsRuleThread implements Runnable {
try {
connection = ConnectionOracle.getConnection();
NmsReportService service = new NmsReportService(connection);
- //ArrayList<Map<String, String>> nmsRuleInfo = service.getNmsRuleInfo(nowLong, nowLong-interval);
+ ArrayList<Map<String, String>> nmsRuleInfo = service.getNmsRuleInfo(nowLong, nowLong-interval);
+ if (nmsRuleInfo != null && nmsRuleInfo.size() > 0) {
+
+ Map<String, List<Map<String, String>>> data = new HashMap<String, List<Map<String, String>>>();
+ List<Map<String, String>> results = new ArrayList<Map<String, String>>();
+
+ for (Map<String, String> info : nmsRuleInfo) {
+ Map<String, String> result = new HashMap<String, String>();
+ result.put("detectionInfoId", info.get("detection_info_id"));
+ result.put("serviceIndex", info.get("ServiceIndex"));
+ result.put("serviceCode", info.get("ServiceCode"));
+ result.put("serviceDesc", info.get("ServiceDesc"));
+ result.put("agedTime", info.get("agedTime"));
+ result.put("clientNum", info.get("ClientNum"));
+ result.put("refluxPort", info.get("RefluxPort"));
+ result.put("ruleNumber", info.get("RuleNumber"));
+ result.put("usedRuleNum", info.get("usedRuleNum"));
+ result.put("leftRuleNum", info.get("leftRuleNum"));
+ result.put("hitTotalNum", info.get("HitTotalNum"));
+ result.put("detectionedState", info.get("DETECTIONED_STATE"));
+ result.put("seqId", info.get("SEQ_ID"));
+ result.put("detectionSetInfoId", info.get("DETECTION_SET_INFO_ID"));
+ result.put("dataCheckTime", info.get("data_check_time"));
+ result.put("dataArriveTime", info.get("data_arrive_time"));
+ result.put("dataCheckTimeDigital", info.get("data_check_time_digital"));
+ result.put("dataArriveTimeDigital", info.get("data_arrive_time_digital"));
+ results.add(result);
+ }
+ data.put("nmsDiRuleList", results);
+ HttpClientUtil httpUtil = new HttpClientUtil();
+ JSONObject fromObject = JSONObject.fromObject(data);
+
+ httpUtil.post(BaseAction.rb.getString("nms.rule.url"), fromObject.toString());
+ }
} catch (Exception e) {
logger.error(e);
} finally {
diff --git a/src/com/nms/thread/service/NmsReportService.java b/src/com/nms/thread/service/NmsReportService.java
index 2a7ac49..abb1742 100644
--- a/src/com/nms/thread/service/NmsReportService.java
+++ b/src/com/nms/thread/service/NmsReportService.java
@@ -41,12 +41,13 @@ public class NmsReportService {
}
public ArrayList<Map<String, String>> getNmsRuleInfo(Long end, Long start) {
- String sql = "SELECT nt.node_ip, dr.ServiceIndex, dr.ServiceCode, dr.ServiceDesc, dr.agedTime, dr.ClientNum, dr.RefluxPort, dr.RuleNumber, dr.usedRuleNum, dr.leftRuleNum, dr.HitTotalNum, dr.DETECTIONED_STATE "
+ //end=1539073880004l, start=1539073579984l
+ String sql = "SELECT dr.detection_info_id, dr.ServiceIndex, dr.ServiceCode, dr.ServiceDesc, dr.agedTime, dr.ClientNum, dr.RefluxPort, dr.RuleNumber, dr.usedRuleNum, dr.leftRuleNum, dr.HitTotalNum, dr.DETECTIONED_STATE, dr.SEQ_ID, dr.DETECTION_SET_INFO_ID, dr.data_check_time, dr.data_arrive_time, dr.data_check_time_digital, dr.data_arrive_time_digital "
+ "FROM di_rule dr "
+ "LEFT JOIN node_table nt ON nt.seq_id=dr.seq_id "
+ "WHERE nt.node_state=0 AND dr.data_check_time_digital<" + end + " AND dr.data_check_time_digital>=" + start;
ArrayList<String> fields = new ArrayList<String>();
- fields.add("node_ip");
+ fields.add("detection_info_id");
fields.add("ServiceIndex");
fields.add("ServiceCode");
fields.add("ServiceDesc");
@@ -58,6 +59,12 @@ public class NmsReportService {
fields.add("leftRuleNum");
fields.add("HitTotalNum");
fields.add("DETECTIONED_STATE");
+ fields.add("SEQ_ID");
+ fields.add("DETECTION_SET_INFO_ID");
+ fields.add("data_check_time");
+ fields.add("data_arrive_time");
+ fields.add("data_check_time_digital");
+ fields.add("data_arrive_time_digital");
try {
ArrayList<Map<String, String>> dbSelect = dao.dbSelect(sql, fields);
@@ -69,12 +76,24 @@ public class NmsReportService {
}
public ArrayList<Map<String, String>> getNmsPortInfo(Long end, Long start) {
- String sql = "SELECT nt.node_ip, ds.* "
+ //end=1539073220004l,start=1539064699984l
+ String sql = "SELECT nt.node_ip, nt.node_name, ds.ifindex, ds.IFDESCR, ds.IFSPEED, ds.IFINOCTETS, ds.IFOUTOCTETS,ds.INOCTETSSPEED,ds.INPKTSSPEED,ds.OUTOCTETSSPEED, ds.OUTPKTSSPEED, ds.DATA_CHECK_TIME "
+ "FROM di_switchport ds "
- + "LEFT JOIN node_table nt ON nt.seq_id=ds.seq_id"
+ + "LEFT JOIN node_table nt ON nt.seq_id=ds.seq_id "
+ "WHERE nt.node_state=0 AND ds.data_check_time_digital<" + end + " AND ds.data_check_time_digital>=" + start;
ArrayList<String> fields = new ArrayList<String>();
fields.add("node_ip");
+ fields.add("node_name");
+ fields.add("ifindex");
+ fields.add("IFDESCR");
+ fields.add("IFSPEED");
+ fields.add("IFINOCTETS");
+ fields.add("IFOUTOCTETS");
+ fields.add("INOCTETSSPEED");
+ fields.add("INPKTSSPEED");
+ fields.add("OUTOCTETSSPEED");
+ fields.add("OUTPKTSSPEED");
+ fields.add("DATA_CHECK_TIME");
try {
ArrayList<Map<String, String>> dbSelect = dao.dbSelect(sql, fields);
diff --git a/src/conf/myconfig.properties b/src/conf/myconfig.properties
index c054ce7..189b604 100644
--- a/src/conf/myconfig.properties
+++ b/src/conf/myconfig.properties
@@ -87,7 +87,11 @@ nation.role.jsbh=224
dept.mk.id=280
+#1:open 0:close
+nms.report.open=1
#unit:s
nms.report.interval=20
nms.status.setId=7
-nms.status.url=http\://10.0.6.242\:8080/galaxy/service/nms/v1/saveServerStatus \ No newline at end of file
+nms.status.url=http\://192.168.11.64\:8080/galaxy-service/service/nms/v1/saveServerStatus
+nms.port.url=http\://192.168.11.64\:8080/galaxy-service/service/nms/v1/rafficNetflowPortInfo
+nms.rule.url=http\://192.168.11.64\:8080/galaxy-service/service/nms/v1/saveNmsDiRule \ No newline at end of file
diff --git a/src/nis/nms/util/HttpClientUtil.java b/src/nis/nms/util/HttpClientUtil.java
index d03906e..ec09361 100644
--- a/src/nis/nms/util/HttpClientUtil.java
+++ b/src/nis/nms/util/HttpClientUtil.java
@@ -66,7 +66,8 @@ public class HttpClientUtil {
*/
public String post(String url, String json) throws ClientProtocolException, IOException{
//实例化httpClient
- logger.info("发送post请求:" + url + ":::" + json);
+ logger.info("发送post请求:" + url);
+ logger.debug("发送post请求:" + url + ":::" + json);
CloseableHttpClient httpclient = HttpClients.createDefault();
//实例化post方法
HttpPost httpPost = new HttpPost(url);
@@ -80,7 +81,8 @@ public class HttpClientUtil {
//执行post方法
response = httpclient.execute(httpPost);
content = EntityUtils.toString(response.getEntity(), "utf-8");
- logger.info("post请求结束:" + response.getStatusLine().getStatusCode() + ":::" + content);
+ logger.info("post请求结束:" + response.getStatusLine().getStatusCode());
+ logger.debug("post请求结束:" + response.getStatusLine().getStatusCode() + ":::" + content);
return content;
}
}