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

My attempt at an Mattermost notification #902

Closed
cwerner opened this issue Nov 28, 2019 · 2 comments
Closed

My attempt at an Mattermost notification #902

cwerner opened this issue Nov 28, 2019 · 2 comments
Labels
stale Stale issues and PRs

Comments

@cwerner
Copy link
Contributor

cwerner commented Nov 28, 2019

Mattermost follows (mostly) the slack notification scheme, but it does not work with the blocks api.

I thus hacked a simple custom class. Not sure if this is useful for someone else?

In addition, I had to mod the util.py file in the validation_operators folder to make it work with our server (set verify=False):

util.py (partial):

def send_slack_notification(query, slack_webhook):
    session = requests.Session()
    
    try:
        response = session.post(url=slack_webhook, json=query, verify=False)
    except requests.ConnectionError:

the poor-mans mattermost class:

mattermost_renderer.py

import datetime

from .renderer import Renderer


class MattermostRenderer(Renderer):
    
    def __init__(self):
        pass
    
    def render(self, validation_json=None):
        timestamp = datetime.datetime.strftime(datetime.datetime.now(), "%x %X")
        default_text = "No validation occurred. Please ensure you passed a validation_json."
        status = "Failed :x:"        

        query = {
            "text": default_text
        }

        # TODO improve this nested logic
        expectation_suite_name = None
        data_asset_name = None
        if validation_json:
            if "meta" in validation_json:
                data_asset_name = validation_json["meta"].get(
                    "data_asset_name",
                    "no_name_provided_" + datetime.datetime.utcnow().isoformat().replace(":", "") + "Z"
                )
                expectation_suite_name = validation_json["meta"].get("expectation_suite_name", "default")
        
            n_checks_succeeded = validation_json["statistics"]["successful_expectations"]
            n_checks = validation_json["statistics"]["evaluated_expectations"]
            run_id = validation_json["meta"].get("run_id", None)
            check_details_text = "*{}* of *{}* expectations were met".format(
                n_checks_succeeded, n_checks)
        
            if validation_json["success"]:
                status = "Success :tada:"

            summary_text = """*Batch Validation Status*: {}
*Data Asset:* `{}`
*Expectation suite name*: `{}`
*Run ID*: `{}`
*Timestamp*: `{}`
*Summary*: {}""".format(
                status,
                data_asset_name,
                expectation_suite_name,
                run_id,
                timestamp,
                check_details_text
            )

            if "result_reference" in validation_json["meta"]:
                query["text"] += "---\n" + "- *Validation Report*: {}".format(validation_json["meta"]["result_reference"]) 
        
            if "dataset_reference" in validation_json["meta"]:
                query["text"] += "- *Validation data asset*: {}".format(validation_json["meta"]["dataset_reference"])

        return query
@stale
Copy link

stale bot commented Mar 11, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Mar 11, 2020
@Aylr Aylr removed the wontfix label Mar 13, 2020
@github-actions
Copy link
Contributor

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?\n\nThis issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale issues and PRs label Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues and PRs
Projects
None yet
Development

No branches or pull requests

2 participants