Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ public double[] getNpuUsage() {
*/
public String getIpAddress() {
String dev = ConfigManager.getInstance().getConfig().getNetworkConfig().networkManagerIface;
logger.debug("Requesting IP addresses for \"" + dev + "\"");
String addr = NetworkUtils.getIPAddresses(dev);
logger.debug("Got value \"" + addr + "\"");
return addr;
}

Expand All @@ -244,8 +242,6 @@ public double getUptime() {
}

public void publishMetrics() {
logger.debug("Publishing Metrics...");

// Check that the hostname hasn't changed
if (!CameraServerJNI.getHostname()
.equals(NetworkTable.basenameKey(metricPublisher.getTopic().getName()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static boolean nmcliIsInstalled() {
}
}

private static List<NMDeviceInfo> allInterfaces = new ArrayList<>();
private static List<NMDeviceInfo> allInterfaces = null;
private static long lastReadTimestamp = 0;

public static List<NMDeviceInfo> getAllInterfaces() {
Expand All @@ -88,35 +88,36 @@ public static List<NMDeviceInfo> getAllInterfaces() {

var ret = new ArrayList<NMDeviceInfo>();

if (!Platform.isLinux()) {
// Can only determine interface name on Linux, give up
return ret;
}

try {
var shell = new ShellExec(true, false);
shell.executeBashCommand(
"nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show");
String out = shell.getOutput();
if (out == null) {
return new ArrayList<>();
if (Platform.isLinux()) {
String out = null;
try {
var shell = new ShellExec(true, false);
shell.executeBashCommand(
"nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show", true, false);
out = shell.getOutput();
} catch (IOException e) {
logger.error("IO Exception occured when calling nmcli to get network interfaces!", e);
}
Pattern pattern =
Pattern.compile("GENERAL.CONNECTION:(.*)\nGENERAL.DEVICE:(.*)\nGENERAL.TYPE:(.*)");
Matcher matcher = pattern.matcher(out);
while (matcher.find()) {
if (!matcher.group(2).equals("lo")) {
// only include non-loopback devices
ret.add(new NMDeviceInfo(matcher.group(1), matcher.group(2), matcher.group(3)));
if (out != null) {
Pattern pattern =
Pattern.compile("GENERAL.CONNECTION:(.*)\nGENERAL.DEVICE:(.*)\nGENERAL.TYPE:(.*)");
Matcher matcher = pattern.matcher(out);
while (matcher.find()) {
if (!matcher.group(2).equals("lo")) {
// only include non-loopback devices
ret.add(new NMDeviceInfo(matcher.group(1), matcher.group(2), matcher.group(3)));
}
}
}
} catch (IOException e) {
logger.error("Could not get active network interfaces!", e);
}

logger.debug("Found network interfaces: " + ret);

allInterfaces = ret;
if (!ret.equals(allInterfaces)) {
if (ret.isEmpty()) {
logger.error("Unable to identify network interfaces!");
} else {
logger.debug("Found network interfaces: " + ret);
}
allInterfaces = ret;
}
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public int executeBashCommand(String command) throws IOException {
* @return process exit code
*/
public int executeBashCommand(String command, boolean wait) throws IOException {
return executeBashCommand(command, true, true);
return executeBashCommand(command, wait, true);
}

/**
Expand Down
Loading