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

Build custom alert message #3137

Merged
merged 25 commits into from
Jul 11, 2019
Merged

Conversation

k-tomoyasu
Copy link
Contributor

@k-tomoyasu k-tomoyasu commented Nov 28, 2018

Build custom alert messages with query results.

Alert feature is useful but we cannot see detail about query result.
This feature enable us write custom alert messages with query results (using template engine Jinja2).

WIP yet. I would appreciate if give me feedback.

alert destination

  • email
  • slack
  • webhook
  • chatworks
  • pagerduty
  • mattermost
  • hangoutschat
  • hipchat

setting
setting

slack alert
slack

@kocsmy
Copy link
Collaborator

kocsmy commented Nov 28, 2018

Nice feature @k-tomoyasu — regarding the color of the preview button: we don't use that color so using btn-default would make sense. I'll think about having a better layout for this in the meantime.

@k-tomoyasu
Copy link
Contributor Author

Nice feature @k-tomoyasu — regarding the color of the preview button: we don't use that color so using btn-default would make sense. I'll think about having a better layout for this in the meantime.

@kocsmy Thanks for your advice!
Firstly, I changed button color (and some fixes) and update screenshots.

@jupe
Copy link

jupe commented Jan 18, 2019

When we get this in ? Could rest of integrations be done in follow-up PR? I would like to get this first for emails and for slack..

@ghost ghost added the in progress label Jan 19, 2019
@k-tomoyasu k-tomoyasu changed the title WIP Build custom alert message Build custom alert message Jan 19, 2019
@k-tomoyasu
Copy link
Contributor Author

@jupe Thanks for your comment!

Could rest of integrations be done in follow-up PR?

That's a big help if it is OK.
I was not good progress of integration because rest destinations are not easy to debug in my environment.

@jupe
Copy link

jupe commented Jan 19, 2019

For our case email&slack would be enough. Most probably we doesn’t need anything else, at least in near future. Currently slack alert is almost useless because it gives just title, not even link.. so this would be really welcome feature :)

@arikfr arikfr self-assigned this Jan 23, 2019
@ghost ghost added the in progress label Jan 31, 2019
client/app/pages/alert/index.js Outdated Show resolved Hide resolved
redash/handlers/api.py Outdated Show resolved Hide resolved
@rauchy rauchy requested a review from kravets-levko February 6, 2019 07:14
Copy link
Member

@arikfr arikfr 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 this pull request, @k-tomoyasu ! This is a great feature and apologies that I couldn't review it sooner.

I made a few comments inline in code, but I have two other things to discuss in general --

How about we use Mustache as the template language? It has two important benefits: ability to render preview in client side without having to call the server and more importantly: it's far more secure. While Jinja2 supposed to be secure, it still has quite a big attack surface.

For Email type notification it will be beneficial to be able to edit the subject too. How about we provide the user the option to customize "Alert short description" (will be used as subject for email, text for Slack and just first line for others) and "Alert description" (what you already have)?

There will be needed some UI work as well, but we can do this in a follow up once we work out the other details. And this is something we can help you with.

Thanks!


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('alerts', sa.Column('template', sa.Text(), nullable=True))
Copy link
Member

Choose a reason for hiding this comment

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

Let's put template in the options JSON object we already have in alerts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, fix logic and remove migration file.

@@ -772,6 +773,10 @@ def evaluate(self):
def subscribers(self):
return User.query.join(AlertSubscription).filter(AlertSubscription.alert == self)

def render_template(self, showError=None):
Copy link
Member

Choose a reason for hiding this comment

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

showError seems to be unused? Also should be show_error.

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've removed.

@k-tomoyasu
Copy link
Contributor Author

@arikfr
I implemented on other destinations(except hipchat).
(except hipchat).

Thank you for updating this! Please see follow up comments.

Thank you for comments!
I've updated. it's ready to review.

@arikfr
Copy link
Member

arikfr commented May 13, 2019

Apologies for letting this linger. I will try to get to it this week 🤞

@karamov-git
Copy link

Hello, I am also looking forward to this functionality. How soon does this appear in redash?
Thank.

@arikfr
Copy link
Member

arikfr commented Jul 11, 2019

Apologies for letting this linger. I will try to get to it this week 🤞

"this week"... 2 months later here I am 😅

To avoid further review cycles, I did some changes myself:

  1. Updated with latest master (there were some merge conflicts to fix).
  2. Updated how the Webhook destination handles these new options (b078866).
  3. Add log message when checking alert (60cb858, not really related to this PR, just happened to include it).
  4. Added a feature flag (REDASH_FEATURE_EXTENDED_ALERT_OPTIONS, disabled by default) to control whether to show the new options.

The reason for the feature flag is that the UI still needs more work. I will work on the product and UX definition with @ranbena and we will do these changes ourselves (along with converting this page to React).

But you can already use this in your setup 👍

Thank you for your effort here, this great feature and patience during the process.

Once the build passes I will merge this.

@arikfr
Copy link
Member

arikfr commented Jul 11, 2019

@k-tomoyasu it's not a big thing, but the email address you signed this commits with (k.tomoyasu@geniee.co.jp) is not associated with your GitHub account. This means that you won't show up in the contributors page on GitHub :-( You can fix this by verifying this email address in your account: https://help.github.com/en/articles/setting-your-commit-email-address.

@arikfr arikfr merged commit a8ff250 into getredash:master Jul 11, 2019
@arikfr
Copy link
Member

arikfr commented Jul 11, 2019

Merged 👍

@k-tomoyasu
Copy link
Contributor Author

k-tomoyasu commented Jul 11, 2019

@arikfr
Thanks for fix and future plan:+1:
I'm looking forward to next release:smile:

You can fix this by verifying this email address in your account

Thank you for your kindness. But this email is invalid now...
I'm glad to be listed on the page at the next opportunity!

The-Alchemist pushed a commit to The-Alchemist/redash that referenced this pull request Jul 15, 2019
* build custom alert message

* fit button color tone

* pass existing test

* fix typos

* follow code style

* add webhook alert description and avoid key error

* refactor: create alert template module

* follow code style

* use es6 class, fix template display

* use alerts.options, use mustache

* fix email description

* alert custom subject

* add alert state to template context, sanitized preview

* remove console.log 🙇

* chatwork custom_subject

* add alert custom message. pagerduty, mattermost, hangoutschat

* Pass custom subject in webhook destination

* Add log message when checking alert.

* Add feature flag for extra alert options.
@Vaidas737
Copy link

Hi, how to enable this feature in version 8.0.0

@ranbena
Copy link
Contributor

ranbena commented Oct 29, 2019

@Vaidas737
Copy link

Thanks

@arikfr
Copy link
Member

arikfr commented Oct 29, 2019

@ranbena the link you referenced is for v9...

@Vaidas737 in v8, you can enable it with an env var, but note that it won't be 100% compatible with the final implementation in v9.

@Vaidas737
Copy link

@arikfr thanks a lot

harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
* build custom alert message

* fit button color tone

* pass existing test

* fix typos

* follow code style

* add webhook alert description and avoid key error

* refactor: create alert template module

* follow code style

* use es6 class, fix template display

* use alerts.options, use mustache

* fix email description

* alert custom subject

* add alert state to template context, sanitized preview

* remove console.log 🙇

* chatwork custom_subject

* add alert custom message. pagerduty, mattermost, hangoutschat

* Pass custom subject in webhook destination

* Add log message when checking alert.

* Add feature flag for extra alert options.
@auziel
Copy link

auziel commented Jan 2, 2021

@Vaidas737 in v8, you can enable it with an env var, but note that it won't be 100% compatible with the final implementation in v9.

Hi @arikfr I know it is a year old feature and v9 is already there, but I'm still on v8.0.0. I didn't find a clear explanation how to enable it in v8.
I try to set FEATURE_EXTENDED_ALERT_OPTIONS=true which didn't enable the feature.
Is there a clear doc how to enable this feature for v8.0.0?
How can I customize the message body (I'm using Slack as the alert target)?

@isdzulqor
Copy link

@Vaidas737 in v8, you can enable it with an env var, but note that it won't be 100% compatible with the final implementation in v9.

Hi @arikfr I know it is a year old feature and v9 is already there, but I'm still on v8.0.0. I didn't find a clear explanation how to enable it in v8.
I try to set FEATURE_EXTENDED_ALERT_OPTIONS=true which didn't enable the feature.
Is there a clear doc how to enable this feature for v8.0.0?
How can I customize the message body (I'm using Slack as the alert target)?

try REDASH_FEATURE_EXTENDED_ALERT_OPTIONS not FEATURE_EXTENDED_ALERT_OPTIONS @auziel

@moonsub-kim
Copy link

moonsub-kim commented Mar 6, 2022

Can I use this feature with the docker version redash/redash:10.1.0.b50633?
I enabled REDASH_FEATURE_EXTENDED_ALERT_OPTIONS=true but the alert preview gets no results.

query result
image

alert template
image

alert body
image

@susodapop
Copy link
Contributor

Can I use this feature with the docker version redash/redash:10.1.0.b50633?

This feature was replaced in V9 and is now always enabled (the environment variable has no effect). You can read about how to use it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.