-
Notifications
You must be signed in to change notification settings - Fork 1
fix: sync setup.py version/python-requires with pyproject.toml, add logging to notifications #29
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||||||
| - Webhooks (generic) | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| import logging | ||||||||||
| import os | ||||||||||
| import smtplib | ||||||||||
| from email.mime.text import MIMEText | ||||||||||
|
|
@@ -16,6 +17,8 @@ | |||||||||
| from dataclasses import dataclass | ||||||||||
| from datetime import datetime, timezone | ||||||||||
|
|
||||||||||
| logger = logging.getLogger(__name__) | ||||||||||
|
|
||||||||||
| try: | ||||||||||
| import requests | ||||||||||
|
|
||||||||||
|
|
@@ -262,7 +265,8 @@ def _send_slack(self, message: dict[str, Any], critical: int, high: int) -> bool | |||||||||
| timeout=10, | ||||||||||
| ) | ||||||||||
| return response.status_code == 200 | ||||||||||
| except Exception: | ||||||||||
| except Exception as e: | ||||||||||
| logger.warning("Failed to send Slack notification: %s", e) | ||||||||||
| return False | ||||||||||
|
|
||||||||||
| def _send_slack_alert(self, title: str, message: str, color: str) -> bool: | ||||||||||
|
|
@@ -289,7 +293,8 @@ def _send_slack_alert(self, title: str, message: str, color: str) -> bool: | |||||||||
| timeout=10, | ||||||||||
| ) | ||||||||||
| return response.status_code == 200 | ||||||||||
| except Exception: | ||||||||||
| except Exception as e: | ||||||||||
| logger.warning("Failed to send Slack alert: %s", e) | ||||||||||
|
Comment on lines
+296
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully leverage the If the standard
Suggested change
|
||||||||||
| return False | ||||||||||
|
|
||||||||||
| def _send_discord(self, message: dict[str, Any], critical: int, high: int) -> bool: | ||||||||||
|
|
@@ -333,7 +338,8 @@ def _send_discord(self, message: dict[str, Any], critical: int, high: int) -> bo | |||||||||
| timeout=10, | ||||||||||
| ) | ||||||||||
| return response.status_code in (200, 204) | ||||||||||
| except Exception: | ||||||||||
| except Exception as e: | ||||||||||
| logger.warning("Failed to send Discord notification: %s", e) | ||||||||||
|
Comment on lines
+341
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully leverage the If the standard
Suggested change
|
||||||||||
| return False | ||||||||||
|
|
||||||||||
| def _send_discord_alert(self, title: str, message: str, color: str) -> bool: | ||||||||||
|
|
@@ -363,7 +369,8 @@ def _send_discord_alert(self, title: str, message: str, color: str) -> bool: | |||||||||
| timeout=10, | ||||||||||
| ) | ||||||||||
| return response.status_code in (200, 204) | ||||||||||
| except Exception: | ||||||||||
| except Exception as e: | ||||||||||
| logger.warning("Failed to send Discord alert: %s", e) | ||||||||||
|
Comment on lines
+372
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully leverage the If the standard
Suggested change
|
||||||||||
| return False | ||||||||||
|
|
||||||||||
| def _send_email(self, subject: str, body: str) -> bool: | ||||||||||
|
|
@@ -386,7 +393,8 @@ def _send_email(self, subject: str, body: str) -> bool: | |||||||||
| server.send_message(msg) | ||||||||||
|
|
||||||||||
| return True | ||||||||||
| except Exception: | ||||||||||
| except Exception as e: | ||||||||||
| logger.warning("Failed to send email notification: %s", e) | ||||||||||
|
Comment on lines
+396
to
+397
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully leverage the If the standard
Suggested change
|
||||||||||
| return False | ||||||||||
|
|
||||||||||
| def _send_webhook(self, url: str, data: dict[str, Any]) -> bool: | ||||||||||
|
|
@@ -397,7 +405,8 @@ def _send_webhook(self, url: str, data: dict[str, Any]) -> bool: | |||||||||
| try: | ||||||||||
| response = requests.post(url, json=data, timeout=10) | ||||||||||
| return response.status_code in (200, 201, 202, 204) | ||||||||||
| except Exception: | ||||||||||
| except Exception as e: | ||||||||||
| logger.warning("Failed to send webhook to %s: %s", url, e) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The newly added logging statement in the Remediation:
Suggested change
|
||||||||||
| return False | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fully leverage the
StructuredLogger(if adopted as suggested in the previous comment), the exception details should be passed as a keyword argument to the logging method. This allows the structured logger to include the error details in a more parseable format.If the standard
logging.getLoggeris retained, the current format string approach is acceptable, but using keyword arguments is preferred for structured logging.