Skip to main content

Lightweight Cloud Forwarder Agent for Windows Event Logs

Project description

logwatch-ai

AI-powered Windows Event Log anomaly detection library using Isolation Forest.

This library provides a pre-trained machine learning model that analyzes Windows system logs and detects anomalous behavior in real time. It uses a 25-feature Isolation Forest model trained on real Windows Event Log data.


Installation

pip install logwatch-ai

Or install from source:

git clone https://github.com/mouayed-kordi/logwatch-ai.git
cd logwatch-ai
pip install .

Quick Start

from logwatch_ai import AnomalyDetector

# Initialize the detector (loads the pre-trained model)
detector = AnomalyDetector()

# Score a single log entry
result = detector.score_log(
    level="ERROR",
    message="FATAL: Database connection lost due to timeout",
    log_type="Database",
    cpu=85.2,
    ram=72.1,
)

print(result)
# Output:
# {
#     "is_anomaly": True,
#     "score": -0.1234,
#     "threshold": -0.09
# }

API Reference

AnomalyDetector(artifacts_path=None)

Creates a new detector instance and loads the pre-trained model.

| Parameter | Type | Description | |---|---|---|pX0VVVVVV | artifacts_path | str or None | Path to custom .pkl model files. If None, uses the bundled pre-trained model. |

detector.score_log(...)

Scores a single log entry for anomaly detection.

Parameter Type Default Description
level str (required) Log severity: "INFO", "WARNING", "ERROR", "CRITICAL"
message str (required) Raw log message text
log_type str "Other" Category: "Database", "Authentication", "Network", "Security", "System", "Other"
cpu float 0.0 CPU usage % at the time of the log
ram float 0.0 RAM usage % at the time of the log
timestamp datetime now() When the log occurred
source_key str "default" Identifier to group logs from the same source

Returns a dict:

{
    "is_anomaly": True,    # True if anomaly detected
    "score": -0.1234,      # Raw Isolation Forest score
    "threshold": -0.09     # Calibrated threshold
}

detector.score_batch(logs)

Scores multiple log entries at once.

logs = [
    {"level": "ERROR", "message": "Connection refused", "log_type": "Network"},
    {"level": "INFO", "message": "Service started", "log_type": "System"},
    {"level": "CRITICAL", "message": "Disk full", "log_type": "System", "cpu": 95.0},
]

results = detector.score_batch(logs)
for r in results:
    print(r["is_anomaly"], r["score"])

How It Works

The detector builds a 25-feature vector for each log entry:

  • Temporal features: Rolling error counts (30s, 1m, 5m, 10m, 15m, 60m)
  • Statistical features: CUSUM drift tracking, error density, short/long ratios
  • Hardware features: CPU and RAM velocity (rate of change)
  • Cyclical time features: Hour and day encoded as sin/cos
  • NLP features: TF-IDF + SVD text encoding of the log message

The Isolation Forest model scores each log. If the score falls below the calibrated threshold (-0.09), the log is flagged as anomalous.


License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logwatch_agent-1.0.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logwatch_agent-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file logwatch_agent-1.0.0.tar.gz.

File metadata

  • Download URL: logwatch_agent-1.0.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for logwatch_agent-1.0.0.tar.gz
Algorithm Hash digest
SHA256 83fb32261cd85c7cfcb7096940612a3d34596823019143fa8b728fa14992e19b
MD5 a2e3ef8c01ab55134e6dd3b858c54f7f
BLAKE2b-256 e33bf812babd092d21b9d433a8e9bb3b370c665ef51a8fb833a1eabfd4be5863

See more details on using hashes here.

File details

Details for the file logwatch_agent-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: logwatch_agent-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for logwatch_agent-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4765f48ef39c7cddce19dd6c52e41ca59683f335744b6e60d4d6fa42878d4d4
MD5 8ec6235723693b033fca84779bddc89e
BLAKE2b-256 ac6d3d0f5ec9d522dcbfc0ba934baa214d6edf88ba8133e3521273c252cbd283

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page