Skip to main content

A package to consume events from an Azure storage queue, process log files, and forward them to a HTTP endpoint or file.

Project description

Azure Log Forwarder

Azure Log Forwarder is a Python package that consumes events from an Azure storage queue, processes log files stored in Azure Blob Storage, and forwards the logs either to an HTTP endpoint or writes them to files.

Image for sap-ecs-azure-log-forwarder

Features

  • Consume blob creation events from an Azure storage queue.
  • Download and decompress gzipped JSON log files from Azure Blob Storage.
  • Forward logs to an HTTP endpoint or write them to files.
  • Support for TLS protocol.
  • Support for different HTTP authentication methods (Token, API Key).
  • Configurable through environment variables.
  • Configurable timeout to exit the program if no messages are found for a specified duration.

Prerequisites

  • Python 3.8 or higher.
  • An Azure Storage account with a configured event grid and storage queue.
  • Azure CLI or Azure portal access to set up the necessary infrastructure.

Installation

With internet access:

pip install sap-ecs-azure-log-forwarder
pip install sap-ecs-azure-log-forwarder==<version>

Without internet access:

  • Navigate to the Download files section on pypi.org for sap-ecs-azure-log-forwarder and download the latest .whl (wheel) file. The file will typically have a name that includes details about compatibility (e.g., example_package-1.0-py3-none-any.whl).
  • Navigate to the directory where your .whl file is located using the cd command, or provide the full path to the .whl file when running the pip command.

Run the following command:

pip install /path/to/your_file.whl

Example:

pip install /User/Downloads/sap_ecs_azure_log_forwarder-1.0.2-py3-none-any.whl

Configuration

Set up the following environment variables to configure the Azure Log Forwarder:

  • SAS_TOKEN: The SAS token for Azure Blob Storage.
  • STORAGE_ACCOUNT_NAME: The name of your Azure Storage account (required if using SAS token).
  • QUEUE_NAME: The name of the Azure storage queue to consume events from.
  • TIMEOUT_DURATION: The time duration in seconds to wait for messages before exiting.
  • OUTPUT_METHOD: The method to forward logs (http or files).
  • HTTP_ENDPOINT: The HTTP endpoint to forward logs to (required if OUTPUT_METHOD is http).
  • TLS_CERT_PATH: Path to the TLS certificate for mutual TLS connections.
  • TLS_KEY_PATH: Path to the TLS key for mutual TLS connections.
  • AUTH_METHOD: Authentication method (token, api_key). Default is token.
    • Auth Token: Set AUTH_METHOD to token and configure AUTH_TOKEN.
      • AUTH_TOKEN: Bearer/OAuth token for HTTP endpoint authentication.
    • API Key: Set AUTH_METHOD to api_key and configure API_KEY.
      • API_KEY: API key for HTTP endpoint API key authentication.
  • OUTPUT_DIR: The output directory to write log files to (required if OUTPUT_METHOD is files).

You can set these environment variables in your shell or in a .env file.

Example of setting environment variables in a shell:

export SAS_TOKEN="your_SAS_token"
export STORAGE_ACCOUNT_NAME="your_storage_account_name"

export QUEUE_NAME="your_queue_name"
export TIMEOUT_DURATION=120  # Timeout after 120 seconds of inactivity. DO NOT set for indefinite runs.

# For http
export OUTPUT_METHOD="http"
export HTTP_ENDPOINT="https://your-http-endpoint.com"
# For TLS certs
export TLS_CERT_PATH="/path/to/your/tls_cert.pem"
export TLS_KEY_PATH="/path/to/your/tls_key.pem"
# For Bearer/OAuth Token authentication
export AUTH_METHOD="token"
export AUTH_TOKEN="your_token"
# For API Key authentication
export AUTH_METHOD="api_key"
export API_KEY="your_api_key"

# For file output
export OUTPUT_METHOD="files"
export OUTPUT_DIR="/path/to/your/output/directory/"

Usage

To run the Azure Log Forwarder, use the following command:

sap-ecs-azure-log-forwarder

This will start the process of consuming events from the storage queue, downloading and processing log files, and forwarding them according to the specified method. The program will exit if no messages are found within the specified timeout duration. If not timeout duration is specified, the program will run indefinitely.

Things to remember

If you do not set a TIMEOUT_DURATION, the program will run indefinitely.

References

  1. Create SAS tokens for your storage containers
  2. Creating a Storage Queue

License

This application and its source code are licensed under the terms of the SAP Developer License Agreement. See the LICENSE file for more information.

Release Notes

1.0.1

  • First proper release!

1.0.2

  • Updated README with diagrams and instructions on installing the package without access to the internet.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file sap_ecs_azure_log_forwarder-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sap_ecs_azure_log_forwarder-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c572222c9c7d7dfb038b34f02af4499c1070f3427bce97d5a3ddca9736678d3
MD5 d3db1d3b299e643bd599811c60e29661
BLAKE2b-256 7ad9028d40650a444d155a715c24ee849f1d720c75d9f726c95f091d542c96f4

See more details on using hashes here.

Supported by

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