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

Feature Request - Google Chat Alerts #286

Open
roney492 opened this issue Jan 22, 2023 · 0 comments
Open

Feature Request - Google Chat Alerts #286

roney492 opened this issue Jan 22, 2023 · 0 comments

Comments

@roney492
Copy link

roney492 commented Jan 22, 2023

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()
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

No branches or pull requests

2 participants
@roney492 and others