1.增加上报开关,从配置文件里配置
2.port、rule上报任务
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user