feat: Refactor log-alert application into modular structure

- Introduced alerters package with base Alerter class and implementations for LogAlerter and GotifyAlerter.
- Created fetchers package with abstract LogFetcher class and implementations for FileLogFetcher, LokiLogFetcher, and ParseableLogFetcher.
- Added filters package with base Filter class and implementations for RegexpFilter and GeolocationFilter.
- Implemented rules package with base AlertRule class and SimpleAlertRule for alerting logic.
- Enhanced configuration handling with utilities for loading and validating JSON configuration.
- Updated logging setup for better logging management.
- Modified main application logic to utilize the new modular structure, improving maintainability and readability.
- Updated config.json and config.schema.json to reflect changes in alerting and fetching configurations.
- Added python-dateutil to requirements for date parsing functionality.
This commit is contained in:
2026-08-30 23:22:38 +02:00
parent b7f1b97434
commit a5337c3d29
23 changed files with 627 additions and 261 deletions
+19 -15
View File
@@ -1,14 +1,17 @@
{
"log-fetchers": {
"loki-fileserver": {
"type": "loki",
"parseable": {
"type": "parseable",
"config": {
"url-from-env": "{LOKI_URL}"
"url-from-env": "{PARSEABLE_URL}",
"dataset-from-env": "{PARSEABLE_DATASET}",
"user-from-env": "{PARSEABLE_USER}",
"password-from-env": "{PARSEABLE_PASSWORD}"
}
}
},
"alert-managers": {
"gotify-paris": {
"alerters": {
"gotify": {
"type": "gotify",
"config": {
"url-from-env": "{GOTIFY_URL}",
@@ -20,10 +23,10 @@
"ssh-outside": {
"check-interval": 30,
"log-fetcher": {
"name": "loki-fileserver",
"name": "parseable",
"filters": {
"labels": {
"container": "openssh-server"
"container_name": "/openssh-server"
},
"text": "Accepted"
}
@@ -42,19 +45,20 @@
}
}
],
"alert-manager": {
"name": "gotify-paris",
"alerter": {
"name": "gotify",
"title": "Outside SSH login",
"message": "New SSH login for {username} on {instance} from ip {ip} (country: {country}, provider: {isp}, method: {method})"
"message": "New SSH login for {username} on {hostname} from ip {ip} (country: {country}, provider: {isp}, method: {method})"
}
},
"ssh-local": {
"check-interval": 30,
"log-fetcher": {
"name": "loki-fileserver",
"name": "parseable",
"filters": {
"labels": {
"filename": "/var/log/host/auth.log"
"filename": "/var/log/host/auth.log",
"process": "sshd"
},
"text": "Accepted"
}
@@ -67,10 +71,10 @@
}
}
],
"alert-manager": {
"name": "gotify-paris",
"alerter": {
"name": "gotify",
"title": "Local SSH login",
"message": "New SSH login for {username} on {instance} from ip {ip} (method: {method})"
"message": "New SSH login for {username} on {hostname} from ip {ip} (method: {method})"
}
}
}