//---------------------------------------------------------------------- // // File: WAPRClient.java // // Author: Stephen D. Wise // // Class: CS522 // // Semester: Fall '02 // // Usage: java WAPRClient // // Description: This is the source code to access a CIM Object // (the processor) and packetize the information // that is sent to the server for display // import java.rmi.MarshalledObject; import java.rmi.Naming; import java.rmi.RMISecurityManager; import java.rmi.AccessException; import java.rmi.AlreadyBoundException; import java.rmi.ConnectException; import java.rmi.ConnectIOException; import java.rmi.MarshalException; import java.rmi.NoSuchObjectException; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.rmi.ServerError; import java.rmi.ServerException; import java.rmi.StubNotFoundException; import java.rmi.UnexpectedException; import java.rmi.UnmarshalException; import java.util.Vector; import java.net.*; import java.io.*; import java.lang.Object; import java.lang.Thread; import javax.wbem.client.CIMClient; import javax.wbem.cim.*; import javax.wbem.client.UserPrincipal; import javax.wbem.client.PasswordCredential; public class WAPRClient { public static void main(String[] args) { int port = 1500; String server = "localhost"; Socket socket = null; String report = ""; BufferedReader input; PrintWriter output; int ERROR = 1; // read arguments if(args.length < 4) { System.out.println("Usage: WAPRClient " + " "); System.exit(1); } else{ server = args[0]; try { port = Integer.parseInt(args[1]); } catch (Exception e) { System.out.println("server port = 1500 (default)"); port = 1500; } } //---------------------------------------------------------------------------- // New Client code CIMClient cc = null; CIMObjectPath cop = null; String protocol = CIMClient.CIM_RMI; String hostName = "zeppo"; CIMNameSpace cns = new CIMNameSpace(hostName); UserPrincipal up = new UserPrincipal(args[2]); PasswordCredential pc = new PasswordCredential(args[3]); try{ cc = new CIMClient(cns, up, pc, protocol); } catch (CIMException e) { System.out.println(e); System.exit(ERROR); } // // set up keys for solaris computer system // Vector computerSystemKeys = new Vector(); CIMProperty computerSystemKey = new CIMProperty("CreationClassName"); computerSystemKey.setValue(new CIMValue("Solaris_ComputerSystem")); computerSystemKeys.addElement(computerSystemKey); computerSystemKey = new CIMProperty("Name"); computerSystemKey.setValue(new CIMValue(hostName)); computerSystemKeys.addElement(computerSystemKey); // // set up keys for solaris processor // Vector processorKeys = new Vector(); CIMProperty processorKey = new CIMProperty("CreationClassName"); processorKey.setValue(new CIMValue("Solaris_Processor")); processorKeys.addElement(processorKey); processorKey = new CIMProperty("SystemCreationClassName"); processorKey.setValue(new CIMValue("Solaris_ComputerSystem")); processorKeys.addElement(processorKey); processorKey = new CIMProperty("SystemName"); processorKey.setValue(new CIMValue(hostName)); processorKeys.addElement(processorKey); processorKey = new CIMProperty("DeviceID"); processorKey.setValue(new CIMValue("0")); processorKeys.addElement(processorKey); CIMValue cVal; // // get handle to computer system // CIMObjectPath computerSystemCOP = new CIMObjectPath("Solaris_ComputerSystem", computerSystemKeys); try{ CIMInstance computerSystemIE = cc.getInstance(computerSystemCOP, false, false, false, null); // // get handle to processor // CIMObjectPath processorCOP = new CIMObjectPath("Solaris_Processor", processorKeys); CIMInstance processorIE = cc.getInstance(processorCOP, false, false, false, null); // // Solaris_ComputerSystem Info // String name = (String)computerSystemIE.getProperty("Name").getValue().getValue(); String CCname = (String)computerSystemIE.getProperty ("CreationClassName").getValue().getValue(); // // Solaris_Processor Info // String deviceid = (String) processorIE.getProperty("DeviceID").getValue().getValue(); UnsignedInt32 CPUSpeed = (UnsignedInt32)processorIE.getProperty ("CurrentClockSpeed").getValue().getValue(); UnsignedInt16 loadAve = (UnsignedInt16)processorIE.getProperty ("LoadPercentage").getValue().getValue(); String Status = (String) processorIE.getProperty("Status").getValue().getValue(); String generalInfo = "\n\nHost Name : " + name + "\nCreation Class : " + CCname + "\nDevice ID : " + deviceid + "\nClock Speed : "+ CPUSpeed + " MHz" + "\nProcessor Status : " + Status + "\nCPU load : " + loadAve + "%\n\n" ; report = generalInfo; } catch (CIMException e) { System.out.println(e); System.exit(ERROR); } System.out.println(report); // // connect to server and send report // try { socket = new Socket(server, port); System.out.println("Connected with server " + socket.getInetAddress() + ":" + socket.getPort()); } catch (UnknownHostException e) { System.out.println(e); System.exit(ERROR); } catch (IOException e) { System.out.println(e); System.exit(ERROR); } try{ output = new PrintWriter(socket.getOutputStream(),true); // // Send Report to Server // output.println(report); } catch (IOException e) { System.out.println(e); } try { socket.close(); } catch (IOException e) { System.out.println(e); } } }