Open roney492 opened 1 year ago
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()
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