Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -37,6 +37,7 @@
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -314,6 +315,9 @@ public static String fetchLocalIp() {
return AgentConfiguration.getAgentConf().get(AgentConstants.AGENT_LOCAL_IP, getLocalIp());
}

private static final String UUID_REGEX =
"^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$";

/**
* Check agent uuid from manager
*/
Expand All @@ -329,15 +333,36 @@ public static String fetchLocalUuid() {
uuid = localUuid;
return uuid;
}
String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
if (StringUtils.isNotEmpty(result)
&& StringUtils.containsIgnoreCase(result, "UUID")) {
uuid = result.split(":")[1].trim();
return uuid;
String result = ExecuteLinux.exeCmd(new String[]{"dmidecode", "-s", "system-uuid"});
if (StringUtils.isNotEmpty(result)) {
result = result.trim();
if (result.matches(UUID_REGEX)) {
return result;
}
}
} catch (Exception e) {
LOGGER.error("fetch uuid error", e);
}

try {
String result = ExecuteLinux.exePipedCmd(
Arrays.asList(
new String[]{"dmidecode"},
new String[]{"grep", "UUID"}),
null, 0);
if (StringUtils.isNotEmpty(result) && StringUtils.containsIgnoreCase(result, "UUID")) {
String[] parts = result.split(":");
if (parts.length >= 2) {
String fallbackUuid = parts[1].trim();
if (fallbackUuid.matches(UUID_REGEX)) {
return fallbackUuid;
}
}
}
} catch (Exception e) {
LOGGER.warn("dmidecode | grep UUID failed", e);
}

return uuid;
}

Expand Down

This file was deleted.

Loading
Loading