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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Use a [Flow API token](https://www.flowdock.com/account/tokens) as Target when a
##### [HipChat](https://www.hipchat.com)
* `HIPCHAT_AUTHTOKEN` - The hipchat api auth token. Default: ``
* `HIPCHAT_USERNAME` - The username that messages will be sent from. Default: `Seyren Alert`
* `HIPCHAT_USE_V1_API` - Allow the use of HipChat's API for compatibility reasons. Default: `false`

##### [Hubot](http://hubot.github.com)
* `HUBOT_URL` - The location where Hubot is running. Default ``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,25 @@ private String getHipChatMessage(Check check) {
}

private void sendMessage(String message, MessageColor color, String[] roomIds, String from, String authToken, boolean notify) {
boolean useV1Api = seyrenConfig.getHipChatUseV1Api();
for (String roomId : roomIds) {
LOGGER.info("Posting: {} to {}: {} {}", from, roomId, message, color);
HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
HttpPost post = new HttpPost();

try {
String url = baseUrl + "/v2/room/" + URLEncoder.encode(roomId, "UTF-8").replaceAll("\\+", "%20") + "/notification?auth_token=" + authToken;
String url;
if (useV1Api) {
url = baseUrl + "/v1/rooms/message?auth_token=" + authToken;
} else {
url = baseUrl + "/v2/room/" + URLEncoder.encode(roomId, "UTF-8").replaceAll("\\+", "%20") + "/notification?auth_token=" + authToken;
}
post = new HttpPost(url);
List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
if (useV1Api) {
parameters.add(new BasicNameValuePair("room_id", roomId));
parameters.add(new BasicNameValuePair("from", from));
}
parameters.add(new BasicNameValuePair("message", message));
parameters.add(new BasicNameValuePair("color", color.name().toLowerCase()));
parameters.add(new BasicNameValuePair("message_format", "html"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SeyrenConfig {
private final String hipChatBaseUrl;
private final String hipChatAuthToken;
private final String hipChatUsername;
private final String hipChatUseV1Api;
private final String hubotUrl;
private final String smtpFrom;
private final String smtpUsername;
Expand Down Expand Up @@ -122,6 +123,7 @@ public SeyrenConfig() {
this.hipChatBaseUrl = configOrDefault(list("HIPCHAT_BASEURL", "HIPCHAT_BASE_URL"), "https://api.hipchat.com");
this.hipChatAuthToken = configOrDefault(list("HIPCHAT_AUTHTOKEN", "HIPCHAT_AUTH_TOKEN"), "");
this.hipChatUsername = configOrDefault(list("HIPCHAT_USERNAME", "HIPCHAT_USER_NAME"), "Seyren Alert");
this.hipChatUseV1Api = configOrDefault(list("HIPCHAT_USE_V1_API", "HIPCHAT_USE_OLD_API", "HIPCHAT_USE_V1"), "false");

// PagerDuty

Expand Down Expand Up @@ -236,6 +238,11 @@ public String getHipChatAuthToken() {
public String getHipChatUsername() {
return hipChatUsername;
}

@JsonIgnore
public boolean getHipChatUseV1Api() {
return Boolean.valueOf(hipChatUseV1Api);
}

@JsonIgnore
public String getHubotUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void defaultHipChatAuthTokenIsCorrect() {
public void defaultHipChatUsernameIsCorrect() {
assertThat(config.getHipChatUsername(), is("Seyren Alert"));
}

@Test
public void defaultHubotUrlIsCorrect() {
assertThat(config.getHubotUrl(), is(""));
Expand Down