-
Notifications
You must be signed in to change notification settings - Fork 80
Allow for http method selection in custom webhook #101
Allow for http method selection in custom webhook #101
Conversation
* Revert "Adding new type of input for Monitors - HttpInput (opendistro-for-elasticsearch#82)" This reverts commit c2004f7.
Please let me know if there's anything I can do to assist with reviewing this. This functionality would be a big improvement for my teams alerting. |
we need this very much too!!! |
@jcleezer Sorry for the delay on this. |
Hi @skkosuri-amzn, admittedly I added this to get support for PUT. It was minimal effort to add |
@jcleezer Can we limit only for |
@skkosuri-amzn works for me. I've updated the PR with |
...com/amazon/opendistroforelasticsearch/alerting/destination/message/CustomWebhookMessage.java
Outdated
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/alerting/destination/CustomWebhookMessageTest.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #101 +/- ##
============================================
+ Coverage 80.17% 80.29% +0.12%
- Complexity 196 202 +6
============================================
Files 151 151
Lines 5165 5192 +27
Branches 673 679 +6
============================================
+ Hits 4141 4169 +28
+ Misses 666 661 -5
- Partials 358 362 +4
Continue to review full report at Codecov.
|
Thanks @jcleezer |
Tagged this for next release. |
DestinationHttpClient httpClient = new DestinationHttpClient(); | ||
httpClient.setHttpClient(mockHttpClient); | ||
CustomWebhookDestinationFactory customDestinationFactory = new CustomWebhookDestinationFactory(); | ||
customDestinationFactory.setClient(httpClient); | ||
|
||
DestinationFactoryProvider.setFactory(DestinationType.CUSTOMWEBHOOK, customDestinationFactory); | ||
DestinationFactoryProvider.setFactory(DestinationType.CUSTOMWEBHOOK, customDestinationFactory); | ||
|
||
Map<String, String> queryParams = new HashMap<String, String>(); | ||
queryParams.put("token", "R2x1UlN4ZHF8MXxxVFJpelJNVDgzdGNwMnVRenJwRFBHUkR0NlhROWhXOVVTZXpiTWx2azVr"); | ||
Map<String, String> queryParams = new HashMap<String, String>(); | ||
queryParams.put("token", "R2x1UlN4ZHF8MXxxVFJpelJNVDgzdGNwMnVRenJwRFBHUkR0NlhROWhXOVVTZXpiTWx2azVr"); | ||
|
||
String message = "{\"Content\":\"Message gughjhjlkh Body emoji test: :) :+1: " + | ||
"link test: http://sample.com email test: [email protected] " + | ||
"All member callout: @All All Present member callout: @Present\"}"; | ||
BaseMessage bm = new CustomWebhookMessage.Builder("abc").withHost("hooks.chime.aws"). | ||
withPath("incomingwebhooks/383c0e2b-d028-44f4-8d38-696754bc4574"). | ||
withMessage(message). | ||
withMessage(message).withMethod(method). | ||
withQueryParams(queryParams).build(); | ||
DestinationResponse actualCustomResponse = (DestinationResponse) Notification.publish(bm); | ||
|
||
assertEquals(expectedCustomWebhookResponse.getResponseContent(), actualCustomResponse.getResponseContent()); | ||
assertEquals(expectedCustomWebhookResponse.getStatusCode(), actualCustomResponse.getStatusCode()); | ||
} | ||
assertEquals(expectedCustomWebhookResponse.getResponseContent(), actualCustomResponse.getResponseContent()); | ||
assertEquals(expectedCustomWebhookResponse.getStatusCode(), actualCustomResponse.getStatusCode()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor Nitpick: Please remove the extra spacing, so the different code lines are on a consistent indent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I believe I caught all the places where that somehow got changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor Nitpick on line indenting. I went through everything in the code and these are the remaining line indents that are incorrect.
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
|
||
@RunWith(Parameterized.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the same indent as line 46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Good eye, I believe these have been fixed.
@Parameterized.Parameters(name = "Param: {0}={1}") | ||
public static Object[][] params() { | ||
return new Object[][]{ | ||
{"POST", HttpPost.class}, | ||
{"PUT", HttpPut.class}, | ||
{"PATCH", HttpPatch.class}, | ||
}; | ||
} | ||
|
||
@Parameterized.Parameter(0) | ||
public String method; | ||
|
||
@Parameterized.Parameter(1) | ||
public Class<HttpUriRequest> expectedHttpClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the same indent as line 62
Thanks @jcleezer |
* Add http method to custom webhook * Remove unused line * Opendistro 1.3 * Revert "Adding new type of input for Monitors - HttpInput (#82)" This reverts commit c2004f7. * fix alerting stats API (#129) * Bump plugin version (#131) * Restrict custom http alert method to POST PUT and PATCH * Fix indenting * Fix indention * Fix additional indention Co-authored-by: Jason Leezer <[email protected]> Co-authored-by: Lucas Winkelmann <[email protected]> Co-authored-by: Jinsoo <[email protected]> Co-authored-by: Mohammad Qureshi <[email protected]>
Issue #, if available: None
Description of changes:
This allows for the method used by the alerting custom web hook to be supplied as part of the configuration.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.