gatus icon indicating copy to clipboard operation
gatus copied to clipboard

feat(alerting): custom alert support endpoint errors

Open raojinlin opened this issue 6 months ago • 0 comments

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

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

raojinlin avatar Aug 24 '24 07:08 raojinlin