1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.logging.LogDomains; 26 import com.sun.enterprise.diagnostics.Data; 27 import com.sun.enterprise.diagnostics.Defaults; 28 29 30 import java.util.logging.Logger ; 31 import java.util.logging.Level ; 32 import java.io.File ; 33 34 37 public class WindowsSystemInfoCollector implements Collector{ 38 39 private static Logger logger = 40 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 41 42 43 private static final String MEMORY_INFO_CMD = "mem"; 44 private static final String IP_ADDRESS_INFO_CMD = "ipconfig"; 45 private static final String HOST_NAME_CMD = "hostname"; 46 private static final String OS_INFO_CMD = "ver"; 47 48 private String destFolder = null; 49 50 51 public WindowsSystemInfoCollector(String destFolder){ 52 this.destFolder = destFolder; 53 } 54 55 59 public Data capture(){ 60 61 FileData data = null; 62 63 String outputFileName = destFolder + File.separator + Defaults.SYSTEM_INFO_FILE; 64 65 final String ALL_CMDS = 66 67 "(echo HOSTNAME & "+HOST_NAME_CMD+" & " + 68 "echo OS INFO & "+ OS_INFO_CMD +" & " + 69 "echo MEMORY INFO & " + MEMORY_INFO_CMD + " & " + 70 "echo IP ADDRESS & " + IP_ADDRESS_INFO_CMD + ") >> " + outputFileName ; 71 72 73 String [] cmd = {"cmd.exe", "/C", ALL_CMDS}; 74 75 ProcessExecutor executor = new ProcessExecutor(cmd, 0); 76 try{ 77 executor.execute(); 78 79 File outputFile = new File (outputFileName); 80 81 data = new FileData(outputFile.getName(),DataType.SYSTEM_INFO); 82 83 } 84 catch(ProcessExecutorException pee){ 85 logger.log(Level.WARNING, "Exception while capturing system info" + 86 " : " + pee.getMessage()); 87 } 88 89 return data; 90 } 91 } 92 | Popular Tags |