mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
vuln alerts from arch-audit
This commit is contained in:
parent
56ebed516e
commit
de0ce7d3b0
6 changed files with 153 additions and 11 deletions
|
|
@ -11,9 +11,11 @@ from alerting.common import CREDS_FILE, ROOM_ID
|
|||
|
||||
class AlertType(StrEnum):
|
||||
TEST = "TEST"
|
||||
ERROR = "ERROR"
|
||||
RAM = "RAM"
|
||||
CPU = "CPU"
|
||||
TEMP = "TEMP"
|
||||
VULN = "VULN"
|
||||
LOGIN = "LOGIN" # TODO
|
||||
SMART = "SMART" # TODO
|
||||
RAID = "RAID" # TODO
|
||||
|
|
@ -30,6 +32,7 @@ class Alert:
|
|||
alert_type: AlertType
|
||||
message: str
|
||||
severity: Severity
|
||||
html_message: Optional[str] = None
|
||||
|
||||
|
||||
async def get_client() -> nio.AsyncClient:
|
||||
|
|
@ -56,7 +59,11 @@ def format_message(alert: Alert) -> str:
|
|||
case Severity.CRITICAL:
|
||||
severity_emoji = "🆘"
|
||||
message = f"{severity_emoji} {alert.alert_type} Alert\n{alert.message}"
|
||||
return message
|
||||
if alert.html_message:
|
||||
html_message = f"{severity_emoji} {alert.alert_type} Alert<br>{alert.html_message}"
|
||||
return message, html_message
|
||||
else:
|
||||
return message, None
|
||||
|
||||
|
||||
async def send_alert(alert: Alert, client: Optional[nio.AsyncClient] = None) -> None:
|
||||
|
|
@ -65,14 +72,18 @@ async def send_alert(alert: Alert, client: Optional[nio.AsyncClient] = None) ->
|
|||
client = await get_client()
|
||||
else:
|
||||
temp_client = False
|
||||
message = format_message(alert)
|
||||
message, html_message = format_message(alert)
|
||||
content = {
|
||||
"msgtype": "m.text",
|
||||
"body": message,
|
||||
}
|
||||
if html_message:
|
||||
content["format"] = "org.matrix.custom.html"
|
||||
content["formatted_body"] = html_message
|
||||
await client.room_send(
|
||||
room_id=ROOM_ID,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": message,
|
||||
},
|
||||
content=content,
|
||||
)
|
||||
if temp_client:
|
||||
await client.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue