Skip to content

feat(grafana-oncall): add custom_json parameter for custom payloads#6269

Open
ningyang1988 wants to merge 2 commits intokeephq:mainfrom
ningyang1988:feat/grafana-oncall-custom-json-5316
Open

feat(grafana-oncall): add custom_json parameter for custom payloads#6269
ningyang1988 wants to merge 2 commits intokeephq:mainfrom
ningyang1988:feat/grafana-oncall-custom-json-5316

Conversation

@ningyang1988
Copy link
Copy Markdown

@ningyang1988 ningyang1988 commented Apr 21, 2026

Summary

Adds support for a custom_json parameter in the Grafana OnCall provider's _notify method, as requested in #5316.

Problem

Currently, the Grafana OnCall provider only sends a fixed set of fields (title, message, alert_uid, image_url, state, link_to_upstream_details). Grafana OnCall supports custom templating and arbitrary key/value pairs in webhook payloads, but there was no way to pass custom fields through Keep.

Solution

  • Added a custom_json parameter (type: dict | str | None) to _notify
  • When custom_json is provided:
    • If it's a string, it's parsed as JSON
    • If it's a dict, it's used directly
    • The custom payload is sent as-is, bypassing default field mapping
  • When custom_json is None (default), the existing behavior is unchanged

Changes

  • keep/providers/grafana_oncall_provider/grafana_oncall_provider.py: Add custom_json parameter and payload routing logic
  • docs/providers/documentation/grafana_oncall-provider.mdx: Add "Custom JSON Payload" section with examples
  • docs/snippets/providers/grafana_oncall-snippet-autogenerated.mdx: Add custom_json to parameter list
  • tests/providers/grafana_oncall_provider/test_grafana_oncall_custom_json.py: Unit tests covering all code paths

Testing

All 5 unit tests pass:

  • Default payload (no custom_json)
  • custom_json as dict
  • custom_json as JSON string
  • custom_json=None fallback
  • Invalid JSON string error handling

Usage

actions:
    - name: Custom alert
      provider: grafana_oncall
      config: "{{ provider.my_provider_name }}"
      with:
        custom_json:
          alert_uid: "custom-123"
          title: "Custom Alert"
          state: "alerting"
          my_custom_field: "custom value"

Closes #5316

Allow users to pass a custom JSON payload (dict or string) to the
Grafana OnCall provider, bypassing the default field mapping.

- Add custom_json parameter to _notify (dict | str | None)
- When provided, send custom payload directly to OnCall webhook
- Supports both dict objects and JSON string inputs
- Update provider documentation with usage examples
- Add unit tests for all custom_json code paths

Closes keephq#5316
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 21, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 21, 2026

CLA assistant check
All committers have signed the CLA.

@dosubot dosubot Bot added Enhancement New feature or request Provider Providers related issues labels Apr 21, 2026
@ningyang1988
Copy link
Copy Markdown
Author

I have signed the CLA

@ningyang1988 ningyang1988 force-pushed the feat/grafana-oncall-custom-json-5316 branch from 8a0b5d4 to dd3d1d5 Compare April 21, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Provider Providers related issues size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[➕ Feature]: Allow custom JSON input for Grafana OnCall Provider

2 participants