diff --git a/README.md b/README.md index 9dd8a6ec..83bf1159 100644 --- a/README.md +++ b/README.md @@ -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 `` diff --git a/seyren-core/src/main/java/com/seyren/core/service/notification/HipChatNotificationService.java b/seyren-core/src/main/java/com/seyren/core/service/notification/HipChatNotificationService.java index 9c1bec28..50dc20b5 100644 --- a/seyren-core/src/main/java/com/seyren/core/service/notification/HipChatNotificationService.java +++ b/seyren-core/src/main/java/com/seyren/core/service/notification/HipChatNotificationService.java @@ -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 parameters = new ArrayList(); + 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")); diff --git a/seyren-core/src/main/java/com/seyren/core/util/config/SeyrenConfig.java b/seyren-core/src/main/java/com/seyren/core/util/config/SeyrenConfig.java index d4ef4e14..4f53891f 100644 --- a/seyren-core/src/main/java/com/seyren/core/util/config/SeyrenConfig.java +++ b/seyren-core/src/main/java/com/seyren/core/util/config/SeyrenConfig.java @@ -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; @@ -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 @@ -236,6 +238,11 @@ public String getHipChatAuthToken() { public String getHipChatUsername() { return hipChatUsername; } + + @JsonIgnore + public boolean getHipChatUseV1Api() { + return Boolean.valueOf(hipChatUseV1Api); + } @JsonIgnore public String getHubotUrl() { diff --git a/seyren-core/src/test/java/com/seyren/core/util/config/SeyrenConfigTest.java b/seyren-core/src/test/java/com/seyren/core/util/config/SeyrenConfigTest.java index 90434526..60045b11 100644 --- a/seyren-core/src/test/java/com/seyren/core/util/config/SeyrenConfigTest.java +++ b/seyren-core/src/test/java/com/seyren/core/util/config/SeyrenConfigTest.java @@ -132,7 +132,7 @@ public void defaultHipChatAuthTokenIsCorrect() { public void defaultHipChatUsernameIsCorrect() { assertThat(config.getHipChatUsername(), is("Seyren Alert")); } - + @Test public void defaultHubotUrlIsCorrect() { assertThat(config.getHubotUrl(), is(""));