diff --git a/.gitignore b/.gitignore index a8e751e..1009448 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ ################# .idea/ target/ +*.iml +*.ipr +*.iws ################# ## Eclipse diff --git a/src/main/java/com/tapstream/rollbar/NotifyBuilder.java b/src/main/java/com/tapstream/rollbar/NotifyBuilder.java index 96fc5b8..b67c718 100644 --- a/src/main/java/com/tapstream/rollbar/NotifyBuilder.java +++ b/src/main/java/com/tapstream/rollbar/NotifyBuilder.java @@ -27,12 +27,12 @@ public class NotifyBuilder { private final JSONObject notifierData; private final JSONObject serverData; - public NotifyBuilder(String accessToken, String environment, String rollbarContext) throws JSONException { + public NotifyBuilder(String accessToken, String environment, String serverName, String serverIp, String rollbarContext) throws JSONException { this.accessToken = accessToken; this.environment = environment; this.rollbarContext = rollbarContext; this.notifierData = getNotifierData(); - this.serverData = getServerData(); + this.serverData = getServerData(serverName, serverIp); } @@ -204,12 +204,10 @@ private JSONObject getNotifierData() throws JSONException { return notifier; } - private JSONObject getServerData() throws JSONException { + private JSONObject getServerData(String serverName, String serverIp) throws JSONException { try { - InetAddress localhost = InetAddress.getLocalHost(); - - String host = localhost.getHostName(); - String ip = localhost.getHostAddress(); + String host = getHostName(serverName); + String ip = getHostAddress(serverIp); JSONObject notifier = new JSONObject(); notifier.put("host", host); @@ -220,6 +218,22 @@ private JSONObject getServerData() throws JSONException { } } + private String getHostName(String serverName) throws UnknownHostException { + if (null != serverName && !serverName.endsWith("_IS_UNDEFINED")) { + return serverName; + } + InetAddress localhost = InetAddress.getLocalHost(); + return localhost.getHostName(); + } + + private String getHostAddress(String serverIp) throws UnknownHostException { + if (null != serverIp && !serverIp.endsWith("_IS_UNDEFINED")) { + return serverIp; + } + InetAddress localhost = InetAddress.getLocalHost(); + return localhost.getHostAddress(); + } + private JSONObject createTrace(Throwable throwable) throws JSONException { JSONObject trace = new JSONObject(); diff --git a/src/main/java/com/tapstream/rollbar/RollbarAppender.java b/src/main/java/com/tapstream/rollbar/RollbarAppender.java index be836ef..3315e70 100644 --- a/src/main/java/com/tapstream/rollbar/RollbarAppender.java +++ b/src/main/java/com/tapstream/rollbar/RollbarAppender.java @@ -24,7 +24,9 @@ public class RollbarAppender extends UnsynchronizedAppenderBase{ private String rollbarContext; private boolean async = true; private IHttpRequester httpRequester = new HttpRequester(); - + private String serverName; + private String serverIp; + public RollbarAppender(){ try { this.url = new URL("https://api.rollbar.com/api/1/item/"); @@ -61,6 +63,14 @@ public void setRollbarContext(String context){ this.rollbarContext = context; } + public void setServerName(String serverName) { + this.serverName = serverName; + } + + public void setServerIp(String serverIp) { + this.serverIp = serverIp; + } + @Override public void start() { boolean error = false; @@ -82,13 +92,13 @@ public void start() { addError("No apiKey set for the appender named [" + getName() + "]."); error = true; } - if (this.environment == null || this.environment.isEmpty()) { + if (this.environment == null || this.environment.isEmpty() || this.environment.endsWith("_IS_UNDEFINED")) { addError("No environment set for the appender named [" + getName() + "]."); error = true; } try { - payloadBuilder = new NotifyBuilder(apiKey, environment, rollbarContext); + payloadBuilder = new NotifyBuilder(apiKey, environment, serverName, serverIp, rollbarContext); } catch (JSONException e) { addError("Error building NotifyBuilder", e); error = true;