Skip to main content

A pluggable log shipper and alerting agent.

Project description

Markdown

Log Shipper & Alerting Agent

A highly pluggable, pattern-driven logging agent built in Python that dynamically routes log events to multiple third-party providers (like Slack, Email, and more) based on log severity thresholds.

This project serves as a practical blueprint for implementing clean, decoupled software architectures using classic Gang of Four (GoF) design patterns inside a modern, production-ready Python layout.


Architecture & Design Patterns

The core philosophy of this tool is Open-Closed Principle: the engine shouldn't know how notifications are sent, and individual alerting channels shouldn't know when or why a log event occurs.

[ Application Core ] │ ▼ (Triggers log events) [ LogShipEngine ] ──(Broadcasts)──► [ FilteringAlertObserver ] │ │ │ (Dynamic registration) ▼ (Matches Level?) ├─► SlackAlertObserver ─────────────► Calls SlackStrategy └─► EmailAlertObserver ─────────────► Calls EmailStrategy

Applied Patterns

  • Strategy Pattern: Encapsulates the network payload execution details for each provider (SlackNotificationStrategy, EmailNotificationStrategy) behind a uniform NotificationStrategy abstract base interface.
  • Observer Pattern: Implements pub-sub routing logic. The LogShipperEngine acts as the Subject, passing all logs down to registered LogObserver instances, which filter entries before executing notification routines.
  • Factory Method Pattern: Isolates creation logic inside NotificationFactory. It parses raw dictionary runtime profiles into functional code blocks, abstracting implementation dependencies away from client endpoints.
  • Singleton Pattern: Employs a custom SingletonMeta metaclass configured with a thread-safe execution lock (threading.Lock) to manage global configuration states safely across concurrent processing environments.

Getting Started

This repository leverages uv, an incredibly fast Python package installer and workspace manager.

Prerequisites

Make sure you have uv installed on your local environment:

pip install uv

Installation

  1. Clone this repository to your computer:
git clone https://github.com/khansohil530/ship-logs.git
cd ship-logs
  1. Sync the environment lockfile and compile requirements:
uv sync

Running the Test Suite

The codebase is built strictly around Test-Driven Development (TDD) principles. Run the unit test suite to verify your configuration structure matches:

uv run pytest

Usage Example

  1. Define a Configuration File: Create a profile containing an alerts declaration block. You can mix and match log filters across target endpoints. Save this file as config.json:
{
  "alerts": [
    {
      "type": "slack",
      "level": "CRITICAL",
      "webhook_url": "[https://hooks.slack.com/services/mock-endpoint-string](https://hooks.slack.com/services/mock-endpoint-string)"
    },
    {
      "type": "email",
      "level": "ERROR",
      "smtp": {
        "host": "smtp.internal.net",
        "port": 587,
        "sender": "secops@company.internal"
      }
    }
  ]
}
  1. "Execute via the CLI Engine":Trigger the shipper instantly from your terminal environment using the registered executable command:
uv run ship-logs --config config.json --level CRITICAL --message "Production database partition out of memory space!"

How to Extend (Add a New Provider)

Adding a brand new delivery provider (like Discord or PagerDuty) requires zero modifications to the core logging pipeline engine.

1: Write a New Strategy Subclass

Open src/ship_logs/strategies.py and extend NotificationStrategy:

class DiscordNotificationStrategy(NotificationStrategy):
    def __init__(self, webhook_url: str):
        self.webhook_url = webhook_url

    def send(self, message: str, context: dict) -> bool:
        # Custom HTTP execution logic for Discord payloads goes here...
        print(f"Dispatched to Discord: {message}")
        return True

2: Register in the Factory

Update NotificationFactory.create_strategy inside src/ship_logs/factory.py to recognize the entry mapping string:

elif normalized_type == "discord":
    return DiscordNotificationStrategy(webhook_url=config["webhook_url"])

Now, anyone can use your updated strategy simply by specifying "type": "discord" inside their config.json profile!

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

ship_logs-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

ship_logs-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ship_logs-0.1.0.tar.gz.

File metadata

  • Download URL: ship_logs-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ship_logs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2046015232de3603c55b120c54835596d937448b6a8bdca029faeff9da489151
MD5 4224cfe0c6f71ca1e96f1368df76ff23
BLAKE2b-256 3d71f34ee9d3ec7979356e9d41e2a523c4c531a84aab5c75e30a27fa5bd9e881

See more details on using hashes here.

Provenance

The following attestation bundles were made for ship_logs-0.1.0.tar.gz:

Publisher: python-publish.yml on khansohil530/logship

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ship_logs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ship_logs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ship_logs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff6212304a30999f55105763f2700f29d98893129840e140ca57902c822559e2
MD5 27fb6ee4c0009c35709787ea42bf5fb2
BLAKE2b-256 c26d776ba39bb45fd52522ec00077daa42e33d8f92aa90338ca28c120a97b3fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ship_logs-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on khansohil530/logship

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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