Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Allow for http method selection in custom webhook #101

Conversation

jcleezer
Copy link
Contributor

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.

@jcleezer
Copy link
Contributor Author

@jcleezer
Copy link
Contributor Author

jcleezer commented Jun 5, 2020

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.

@sloev
Copy link

sloev commented Jun 9, 2020

we need this very much too!!!
we have an alerting api that only accepts alerts on http PUT (and the api is not owned by us) so being able to PUT alerts would be a major increase in usability for us!!!

@skkosuri-amzn
Copy link
Contributor

skkosuri-amzn commented Nov 17, 2020

@jcleezer Sorry for the delay on this.
Curious, whats the use case to support GET and DELETE?

@jcleezer
Copy link
Contributor Author

Hi @skkosuri-amzn, admittedly I added this to get support for PUT. It was minimal effort to add GET and DELETE as well and I figured it could possibly aid other use cases.

@skkosuri-amzn
Copy link
Contributor

@jcleezer Can we limit only for POST, PUT and PATCH?

@jcleezer
Copy link
Contributor Author

@skkosuri-amzn works for me. I've updated the PR with GET and DELETE removed.

@codecov
Copy link

codecov bot commented Nov 17, 2020

Codecov Report

Merging #101 (bf8add9) into master (f7a3982) will increase coverage by 0.12%.
The diff coverage is 87.61%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...forelasticsearch/alerting/model/destination/SNS.kt 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...arch/alerting/core/schedule/JobSchedulerMetrics.kt 81.25% <0.00%> (ø) 6.00 <0.00> (ø)
...ting/destination/message/CustomWebhookMessage.java 67.18% <55.55%> (-1.91%) 14.00 <1.00> (+3.00) ⬇️
...roforelasticsearch/alerting/alerts/AlertIndices.kt 65.64% <60.00%> (-0.50%) 0.00 <0.00> (ø)
...ting/destination/client/DestinationHttpClient.java 81.25% <73.33%> (-2.32%) 17.00 <3.00> (+3.00) ⬇️
...icsearch/alerting/model/destination/Destination.kt 76.36% <83.33%> (+1.36%) 0.00 <0.00> (ø)
...endistroforelasticsearch/alerting/MonitorRunner.kt 78.00% <100.00%> (ø) 0.00 <0.00> (ø)
...stroforelasticsearch/alerting/alerts/AlertError.kt 80.95% <100.00%> (ø) 0.00 <0.00> (ø)
...stroforelasticsearch/alerting/alerts/AlertMover.kt 72.72% <100.00%> (ø) 0.00 <0.00> (ø)
...sticsearch/alerting/model/ActionExecutionResult.kt 87.09% <100.00%> (ø) 0.00 <0.00> (ø)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7a3982...5617557. Read the comment docs.

skkosuri-amzn
skkosuri-amzn previously approved these changes Nov 17, 2020
@skkosuri-amzn
Copy link
Contributor

Thanks @jcleezer

@skkosuri-amzn skkosuri-amzn added the next release Targeted for next ODFE release label Nov 18, 2020
@skkosuri-amzn
Copy link
Contributor

Tagged this for next release.

@bowenlan-amzn bowenlan-amzn added the enhancement New feature or request label Nov 25, 2020
Comment on lines 173 to 194
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());
}
Copy link
Contributor

@lezzago lezzago Nov 25, 2020

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@lezzago lezzago left a 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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Comment on lines 47 to 60
@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;
Copy link
Contributor

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

@lezzago
Copy link
Contributor

lezzago commented Nov 30, 2020

Thanks @jcleezer

@skkosuri-amzn skkosuri-amzn merged commit 6fc0cde into opendistro-for-elasticsearch:master Nov 30, 2020
tlfeng pushed a commit that referenced this pull request Feb 6, 2021
* 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request next release Targeted for next ODFE release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants