Rapid7 Insight Python Logger

1.0.1 · maintenance · verified Thu Apr 16

r7insight-python is a plugin library designed to integrate Python's standard logging module with Rapid7 Insight (formerly InsightOps). It enables sending log messages, and optionally method execution times, CPU, and memory statistics to your Rapid7 Insight account. The library leverages asynchronous operations for log dispatch and is currently at version 1.0.1. Releases appear to be infrequent, suggesting a mature or maintenance phase.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic logging to Rapid7 Insight. You need to obtain a Token UUID from a 'Token TCP' log source in your Rapid7 Insight account and specify your region. The example retrieves these values from environment variables or uses placeholders.

import logging
import os
from r7insight import R7InsightHandler

# Get Rapid7 Insight Token and Region from environment variables
# Ensure you configure a 'Token TCP' log source in your Rapid7 Insight account.
TOKEN = os.environ.get('R7INSIGHT_TOKEN', 'YOUR_RAPID7_TOKEN')
REGION = os.environ.get('R7INSIGHT_REGION', 'us') # e.g., 'us', 'eu', 'ca', 'au', 'jp', 'in', 'uk'

# Basic logging setup
log = logging.getLogger('r7insight')
log.setLevel(logging.INFO)

try:
    handler = R7InsightHandler(TOKEN, REGION)
    log.addHandler(handler)
    log.info("Hello from r7insight-python!")
    log.warning("This is a warning message.")
    log.error("An error occurred!")
    print("Logs sent to Rapid7 Insight (asynchronously).")
    print("Check your Rapid7 Insight account for these messages.")
except Exception as e:
    print(f"Failed to configure R7InsightHandler: {e}")
    print("Please ensure R7INSIGHT_TOKEN and R7INSIGHT_REGION are correctly set.")

view raw JSON →