Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alerting): custom alert support endpoint errors #844

Merged
merged 8 commits into from
Sep 18, 2024

Conversation

raojinlin
Copy link
Contributor

@raojinlin raojinlin commented Aug 24, 2024

Summary

Fixes #840

  • Updated buildHTTPRequest method in AlertProvider to accept a result parameter.
  • Added support for including [ENDPOINT_ERRORS] in both the request body and URL, which will be replaced by the errors from Result.Errors[].
  • Modified the Send method to pass the result object to buildHTTPRequest.
  • Adjusted CreateExternalEndpointResult to capture and store errors from query parameters.
  • This allows custom alerts to include detailed error information, enhancing the flexibility of alert notifications.

Usage

push the status of an external endpoint

curl -X POST -H "Authorization: Bearer 123456" "http://127.0.0.1:8080/api/v1/endpoints/core_ext-ep-test/external?success=false&error=xxxx"

custom alerts config

alerting:
  custom:
    url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx  
    method: POST
    headers:
      Content-Type: application/json
    body: |
      {
        "msgtype": "markdown",
        "markdown": {
          "content": "Gatus:\n <font color='warning'>[ALERT_TRIGGERED_OR_RESOLVED]</font>: [ENDPOINT_GROUP] - [ENDPOINT_NAME] - <font color='commen'>[ALERT_DESCRIPTION]</font>\n<font color='warning'>[ENDPOINT_ERRORS]</font>"
        }
      }

image

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

raojinlin added 2 commits August 24, 2024 14:56
…lerts

- Updated `buildHTTPRequest` method in `AlertProvider` to accept a `result` parameter.
- Added support for including `[ENDPOINT_ERRORS]` in both the request body and URL, which will be replaced by the errors from `Result.Errors[]`.
- Adjusted `CreateExternalEndpointResult` to capture and store errors from query parameters.
- This allows custom alerts to include detailed error information, enhancing the flexibility of alert notifications.
@raojinlin raojinlin marked this pull request as draft August 24, 2024 07:48
@raojinlin raojinlin marked this pull request as ready for review August 24, 2024 09:03
README.md Outdated Show resolved Hide resolved
alerting/provider/custom/custom_test.go Outdated Show resolved Hide resolved
alerting/provider/custom/custom.go Outdated Show resolved Hide resolved
alerting/provider/custom/custom.go Outdated Show resolved Hide resolved
alerting/provider/custom/custom_test.go Outdated Show resolved Hide resolved
api/external_endpoint_test.go Outdated Show resolved Hide resolved
@raojinlin
Copy link
Contributor Author

Hi @TwiN I've made the updates as per your suggestions. Could you please take another look? Thanks!

@gh0st3e
Copy link

gh0st3e commented Sep 17, 2024

hey, appreciate you work, i also really need this feature, how about to merge it

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.98%. Comparing base (b0c2f1e) to head (2d5aeb8).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #844      +/-   ##
==========================================
+ Coverage   78.96%   78.98%   +0.01%     
==========================================
  Files          71       71              
  Lines        4768     4772       +4     
==========================================
+ Hits         3765     3769       +4     
  Misses        794      794              
  Partials      209      209              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

README.md Outdated Show resolved Hide resolved
api/external_endpoint.go Outdated Show resolved Hide resolved
api/external_endpoint.go Outdated Show resolved Hide resolved
api/external_endpoint.go Outdated Show resolved Hide resolved
Copy link
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@TwiN TwiN added feature New feature or request area/alerting Related to alerting labels Sep 18, 2024
@TwiN TwiN merged commit 59842d5 into TwiN:master Sep 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/alerting Related to alerting feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add paramter to send extra message when posting to custom alert to an External Endpoint
4 participants