|
|
@ -63,13 +63,19 @@ public class DeviceStatus { |
|
|
|
AjaxResult deviceByIotDeviceId = deviceService.getDeviceByIotDeviceId(device.getIotDeviceId()); |
|
|
|
String deviceState = ((JSONObject) JSON.toJSON(deviceByIotDeviceId.get("data"))).getString("deviceState"); |
|
|
|
if (Objects.equals(deviceState, UniversalEnum.ON_LINE.getValue())) { |
|
|
|
extracted(statusService, device, UniversalEnum.ONE_HUNDRED_PERCENT.getValue()); |
|
|
|
extracted(statusService, device, true, UniversalEnum.ZERO_PERCENT.getValue()); |
|
|
|
} else { |
|
|
|
extracted(statusService, device, UniversalEnum.ZERO_PERCENT.getValue()); |
|
|
|
extracted(statusService, device, false, UniversalEnum.ONE_HUNDRED_PERCENT.getValue()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
extracted(statusService, device, getPingPacketLossRate(device.getDeviceIp())); |
|
|
|
if (StringUtil.isNotEmpty(device.getDeviceIp())) { |
|
|
|
InetAddress address = InetAddress.getByName(device.getDeviceIp()); |
|
|
|
boolean reachable = address.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber()); // Timeout: 5 seconds
|
|
|
|
|
|
|
|
extracted(statusService, device, reachable, getPingPacketLossRate(device.getDeviceIp())); |
|
|
|
} else { |
|
|
|
extracted(statusService, device, false, UniversalEnum.ONE_HUNDRED_PERCENT.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
}; |
|
|
@ -88,8 +94,7 @@ public class DeviceStatus { |
|
|
|
executor.shutdown(); |
|
|
|
} |
|
|
|
|
|
|
|
private void extracted(StatusService statusService, DcDevice device, String lostRate) { |
|
|
|
try { |
|
|
|
private void extracted(StatusService statusService, DcDevice device, boolean reachable, String packetLossRate) { |
|
|
|
Status status = new Status(); |
|
|
|
status.setDeviceNo(device.getStakeMark()); |
|
|
|
status.setDeviceName(device.getDeviceName()); |
|
|
@ -97,10 +102,7 @@ public class DeviceStatus { |
|
|
|
status.setDeviceId(device.getId()); |
|
|
|
LocalDateTime localDateTime = LocalDateTime.now(); |
|
|
|
status.setTime(localDateTime); |
|
|
|
if (StringUtil.isNotEmpty(device.getDeviceIp())) { |
|
|
|
InetAddress address = InetAddress.getByName(device.getDeviceIp()); |
|
|
|
boolean reachable = address.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber()); // Timeout: 5 seconds
|
|
|
|
status.setLostRate(lostRate); |
|
|
|
status.setLostRate(packetLossRate); |
|
|
|
if (reachable) { |
|
|
|
status.setDeviceStatus(UniversalEnum.ONE.getValue()); |
|
|
|
status.setSuccessRate(UniversalEnum.ONE_HUNDRED_PERCENT.getValue()); |
|
|
@ -108,15 +110,7 @@ public class DeviceStatus { |
|
|
|
status.setDeviceStatus(UniversalEnum.ZERO.getValue()); |
|
|
|
status.setSuccessRate(UniversalEnum.ZERO_PERCENT.getValue()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
status.setDeviceStatus(UniversalEnum.ZERO.getValue()); |
|
|
|
status.setSuccessRate(UniversalEnum.ZERO_PERCENT.getValue()); |
|
|
|
status.setLostRate(UniversalEnum.ONE_HUNDRED_PERCENT.getValue()); |
|
|
|
} |
|
|
|
statusService.Add(status); |
|
|
|
} catch (IOException e) { |
|
|
|
System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -139,8 +133,8 @@ public class DeviceStatus { |
|
|
|
if (line.contains("packets transmitted")) { |
|
|
|
// Extract the number of packets sent and lost
|
|
|
|
String[] stats = line.split(", "); |
|
|
|
packetsSent = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(" ")[UniversalEnum.ZERO.getNumber()]); |
|
|
|
packetsLost = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(" ")[UniversalEnum.ZERO.getNumber()]) - Integer.parseInt(stats[UniversalEnum.ONE.getNumber()].split(" ")[UniversalEnum.ZERO.getNumber()]); |
|
|
|
packetsSent = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(UniversalEnum.BLANK_SPACE.getValue())[UniversalEnum.ZERO.getNumber()]); |
|
|
|
packetsLost = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(UniversalEnum.BLANK_SPACE.getValue())[UniversalEnum.ZERO.getNumber()]) - Integer.parseInt(stats[UniversalEnum.ONE.getNumber()].split(UniversalEnum.BLANK_SPACE.getValue())[UniversalEnum.ZERO.getNumber()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|