Skip to content

Feature Request - Google Chat Alerts #286

@roney492

Description

@roney492

It would be nice to have google chats alerts Integrated as well.
I have already written a code for same, please have a look and get it added in

import json
import requests

def google_chat_post(url, json_message):
    """Post to Google Chat webhook."""
    headers = { 'Content-Type': 'application/json' }
    requests.post(url, headers = headers, json = json_message)

def google_chat_alert(filename, sha2, base_url, message):
    """Send Google Chat alert."""
    url = os.environ.get('GOOGLE_CHAT_WEBHOOK_URL', settings.GOOGLE_CHAT_WEBHOOK_URL)
    if not url:
        return
    severity, total_issues = filters.get_metrics(message)
    total_files = len(message['files'])
    scan_file = filename
    error = severity['error']
    warning = severity['warning']
    info = severity['info']
    json_message = {
        'cards': [{
            'header': {
                'title': f'nodejsscan v{settings.VERSION}',
                'subtitle': f'Scan Completed on: {utils.get_timestamp()}',
            },
            'sections': [{
                'widgets': [{
                    'textParagraph': {
                        'text': (f'Found {total_issues} issues in {total_files} files\n'
    f'nodejsscan finished analyzing: {scan_file}'),
                }},{
                    'buttons': [{
                        'textButton': {
                            'text': 'See Scan Results',
                            'onClick': {
                                'openLink': {
                                    'url': f'{base_url}scan/{sha2}',
                                },
                            },
                        },
                    }],
    }],
        }, {
            'widgets': [{
                'keyValue': {
                    'topLabel': 'Severity Distribution',
                    'content': f':octagonal_sign: ERROR: {error}\n:warning: WARNING: {warning}\n:information_source: INFO: {info}',
                },
            }],
        }],
    }],
    }
    process = Thread(target = google_chat_post, args = (url, json_message))
    process.start()
    process.join()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions