This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nms-nmsweb/src/com/nms/thread/NmsPortThread.java
chenjinsong 3a8a20de7b 1.增加上报开关,从配置文件里配置
2.port、rule上报任务
2018-10-09 18:11:38 +08:00

74 lines
2.4 KiB
Java

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;
import com.nms.thread.service.NmsReportService;
public class NmsPortThread implements Runnable {
private Logger logger = Logger.getLogger(NmsPortThread.class);
@Override
public void run() {
Date now = new Date();
Long nowLong = now.getTime();
Integer interval = null;
try {
interval = Integer.parseInt(BaseAction.rb.getString("nms.report.interval"));
} catch (Exception e) {
interval = 300;
}
ConnectionOracle connection = null;
try {
connection = ConnectionOracle.getConnection();
NmsReportService service = new NmsReportService(connection);
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 {
if (connection != null) {
connection.close();
}
}
}
}