Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#################
.idea/
target/
*.iml
*.ipr
*.iws

#################
## Eclipse
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/com/tapstream/rollbar/NotifyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/tapstream/rollbar/RollbarAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class RollbarAppender extends UnsynchronizedAppenderBase<ILoggingEvent>{
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/");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down