<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [3570] need an easy way to determine what the agent "thinks" is its canonical hostname and IP address - version --host gives u that now</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>3570</dd> <dt>Author</dt> <dd>mazz</dd> <dt>Date</dt> <dd>2009-03-31 14:36:24 -0500 (Tue, 31 Mar 2009)</dd> </dl> <h3>Log Message</h3> <pre>need an easy way to determine what the agent "thinks" is its canonical hostname and IP address - version --host gives u that now</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagenti18nAgentI18NResourceKeysjava">rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagentpromptcmdVersionPromptCommandjava">rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/VersionPromptCommand.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagenti18nAgentI18NResourceKeysjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java (3569 => 3570)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java 2009-03-31 18:13:30 UTC (rev 3569) +++ rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java 2009-03-31 19:36:24 UTC (rev 3570) </span><span class="lines">@@ -867,10 +867,10 @@ </span><span class="cx"> @I18NMessage("version") String VERSION = "PromptCommand.version"; </span><span class="rem">- @I18NMessage("version [--sysprops[=name]] [--env[=name]]") </span><span class="add">+ @I18NMessage("version [--sysprops[=name]] [--env[=name]] [--host]") </span><span class="cx"> String VERSION_SYNTAX = "PromptCommand.version.syntax"; </span><span class="rem">- @I18NMessage("Shows agent version information") </span><span class="add">+ @I18NMessage("Shows information on agent version and agent environment") </span><span class="cx"> String VERSION_HELP = "PromptCommand.version.help"; @I18NMessage("System Properties:") </span><span class="lines">@@ -879,6 +879,9 @@ </span><span class="cx"> @I18NMessage("Environment Variables:") String VERSION_ENV_LABEL = "PromptCommand.version.env-label"; </span><span class="add">+ @I18NMessage("Host Information:") + String VERSION_HOST_LABEL = "PromptCommand.version.host-label"; + </span><span class="cx"> @I18NMessage("identify") String IDENTIFY = "PromptCommand.identify"; </span></pre></div> <a id="rhqtrunkmodulesenterpriseagentsrcmainjavaorgrhqenterpriseagentpromptcmdVersionPromptCommandjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/VersionPromptCommand.java (3569 => 3570)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/VersionPromptCommand.java 2009-03-31 18:13:30 UTC (rev 3569) +++ rhq/trunk/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/VersionPromptCommand.java 2009-03-31 19:36:24 UTC (rev 3570) </span><span class="lines">@@ -18,15 +18,18 @@ </span><span class="cx"> */ package org.rhq.enterprise.agent.promptcmd; </span><span class="add">+import gnu.getopt.Getopt; +import gnu.getopt.LongOpt; + </span><span class="cx"> import java.io.PrintWriter; </span><span class="add">+import java.net.InetAddress; </span><span class="cx"> import java.util.HashMap; import java.util.Map; import java.util.Properties; </span><span class="rem">-import gnu.getopt.Getopt; -import gnu.getopt.LongOpt; </span><span class="cx"> import mazz.i18n.Msg; </span><span class="add">+import org.rhq.core.util.exception.ThrowableUtil; </span><span class="cx"> import org.rhq.enterprise.agent.AgentMain; import org.rhq.enterprise.agent.Version; import org.rhq.enterprise.agent.i18n.AgentI18NFactory; </span><span class="lines">@@ -59,10 +62,13 @@ </span><span class="cx"> return true; } </span><span class="rem">- String sopts = "s::e::"; </span><span class="add">+ String sopts = "hs::e::"; </span><span class="cx"> LongOpt[] lopts = { new LongOpt("sysprops", LongOpt.OPTIONAL_ARGUMENT, null, 's'), </span><span class="rem">- new LongOpt("env", LongOpt.OPTIONAL_ARGUMENT, null, 'e') }; </span><span class="add">+ new LongOpt("env", LongOpt.OPTIONAL_ARGUMENT, null, 'e'), + new LongOpt("host", LongOpt.NO_ARGUMENT, null, 'h') }; </span><span class="cx"> </span><span class="add">+ out.println(versionString); + </span><span class="cx"> Getopt getopt = new Getopt(getPromptCommandString(), args, sopts, lopts); int code; </span><span class="lines">@@ -75,10 +81,24 @@ </span><span class="cx"> break; } </span><span class="add">+ case 'h': { + out.println(); + out.println(MSG.getMsg(AgentI18NResourceKeys.VERSION_HOST_LABEL)); + + try { + InetAddress localhost = InetAddress.getLocalHost(); + String name = localhost.getCanonicalHostName(); + String ip = localhost.getHostAddress(); + out.println(name + '(' + ip + ')'); + } catch (Exception e) { + out.println(ThrowableUtil.getAllMessages(e)); + } + break; + } + </span><span class="cx"> case 's': { </span><span class="rem">- out.println(versionString); </span><span class="add">+ out.println(); </span><span class="cx"> out.println(MSG.getMsg(AgentI18NResourceKeys.VERSION_SYSPROPS_LABEL)); </span><span class="rem">- out.println(); </span><span class="cx"> String opt = getopt.getOptarg(); </span><span class="lines">@@ -92,9 +112,8 @@ </span><span class="cx"> } case 'e': { </span><span class="rem">- out.println(versionString); </span><span class="add">+ out.println(); </span><span class="cx"> out.println(MSG.getMsg(AgentI18NResourceKeys.VERSION_ENV_LABEL)); </span><span class="rem">- out.println(); </span><span class="cx"> String opt = getopt.getOptarg(); </span> </pre> </div> </div> </body> </html> |