luchunliang commented on code in PR #12151:
URL: https://github.com/apache/inlong/pull/12151#discussion_r3533266748


##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java:
##########
@@ -329,12 +329,11 @@ 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();
+            String result = ExcuteLinux.exeCmd(new String[]{"dmidecode", "-s", 
"system-uuid"});

Review Comment:
   Support "dmidecode -s " from Linux 2.10. Suggest to add a fallback.
   String uuid = null;
   try {
       String result = ExcuteLinux.exeCmd(new String[]{"dmidecode", "-s", 
"system-uuid"});
       if (StringUtils.isNotEmpty(result)) {
           result = result.trim();
           // check format
           if 
(result.matches("^[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}$"))
 {
               return result;
           }
       }
   } catch (Exception e) {
       LOG.warn("dmidecode -s system-uuid failed, fallback to grep", e);
   }
   
   // Fallback
   try {
       String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
       if (StringUtils.isNotEmpty(result) && 
StringUtils.containsIgnoreCase(result, "UUID")) {
           String[] parts = result.split(":");
           if (parts.length >= 2) {
               return parts[1].trim();
           }
       }
   } catch (Exception e) {
       LOG.warn("dmidecode | grep UUID failed", e);
   }
   
   return uuid;
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to