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

Got 500 error when saving Outgoing Webhook #890

Closed
lstama opened this issue Nov 23, 2022 · 2 comments
Closed

Got 500 error when saving Outgoing Webhook #890

lstama opened this issue Nov 23, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@lstama
Copy link

lstama commented Nov 23, 2022

I got 500 error when saving outgoing webhooks with this data

{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "type": "AdaptiveCard",
                "body": [
                    {
                        "type": "TextBlock",
                        "size": "Large",
                        "weight": "Bolder",
                        "wrap": "true",
                        "text": "{{ alert_payload.title }}"
                    },
                    {
                        "type": "TextBlock",
                        "text": "There is new issue reported by **{{ alert_payload.message.creator.display_name }}**"
                    },
                    {
                        "type": "TextBlock",
                        "text": "Please follow this Jira link: [{{ alert_payload.message.issue_key }}]({{ alert_payload.link_to_upstream_details}})"
                    },
                    {
                        "type": "FactSet",
                        "facts": [
                            {
                                "title": "Priority",
                                "value": "{{ alert_payload.message.issue_priority }}"
                            },
                            {
                                "title": "Assignee",
                                "value": "<at>{{ alert_payload.message.assignee.display_name }}</at>"
                            }
                        ]
                    }
                ],
                "actions": [
                    {
                        "type": "Action.OpenUrl",
                        "title": "Silence/Acknowledge/Resolve",
                        "url": "https://my.url/grafana-oncall-app/?page=incident&id={{ alert_group_id}}"
                    },
                    {
                        "type": "Action.OpenUrl",
                        "title": "Source",
                        "url": "{{ alert_payload.generatorURL }}"
                    },
                    {
                        "type": "Action.OpenUrl",
                        "title": "Silence Source",
                        "url": "{{ alert_payload.silenceURL }}"
                    }
                ],
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "version": "1.0",
                "msteams": {
                    "entities": [
                        {
                            "type": "mention",
                            "text": "<at>{{ alert_payload.message.assignee.display_name }}</at>",
                            "mentioned": {
                                "id": "{{ alert_payload.message.assignee.email }}",
                                "name": "{{ alert_payload.message.assignee.display_name }}"
                            }
                        }
                    ]
                }
            }
        }
    ]
}

And this is the error log from Grafana OnCall:

2022-11-23 11:43:41 source=engine:app google_trace_id=none logger=django.request Internal Server Error: /api/internal/v1/custom_buttons/KBL9C1T8P8EHK
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/rest_framework/mixins.py", line 67, in update
serializer.is_valid(raise_exception=True)
File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 220, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 419, in run_validation
value = self.to_internal_value(data)
File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 478, in to_internal_value
validated_value = validate_method(validated_value)
File "/etc/app/apps/api/serializers/custom_button.py", line 61, in validate_data
rendered = template.render(
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 18, in top-level template code
File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 326, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'str object' has no attribute 'creator'

Previously, it works on Grafana OnCall before v1.1.0, I only got the error after updating to v1.1.0.

Here is the result from previous working outgoing webhook:
image

The webhook that already saved before the v1.1.0 update still works, so it most likely an error when trying to validate the pre-rendered json.

@vadimkerr vadimkerr added the bug Something isn't working label Nov 23, 2022
@vadimkerr
Copy link
Member

Hey @lstama, thank you for reporting the issue!
Seems like a bug, most probably introduced by #639.

@mderynck
Copy link
Contributor

Ideally the UI should have a place to provide content for the alert payload and then we could preview and do more useful validation.

In the short term validation can be relaxed and if an error occurs during rendering the error will be passed along as the result. This is being worked on here:
#884

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants