Skip to content

Consistos/VigInt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

75 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Vigint API Services

A comprehensive platform providing RTSP video streaming and automated billing services with API management.

πŸš€ Features

RTSP Streaming

  • Real-time Video Streaming using MediaMTX
  • Multiple Input Sources (cameras, files, live streams)
  • API-controlled Stream Management
  • Authentication & Access Control
  • Recording Capabilities
  • Built-in Metrics & Monitoring

Video Security Alerts

  • AI-Powered Incident Detection using Gemini AI
  • Private Video Links instead of email attachments
  • Secure Video Hosting on sparse-ai.com
  • Automatic Link Expiration for enhanced security
  • Frame Buffer Management for incident context
  • Multi-language Support (French alerts)
  • Automatic Cleanup of old incident files (30-day retention)
  • Offline Mode with local fallback storage
  • Incident Deduplication to prevent spam (60s cooldown)

Billing System

  • Automated Invoice Generation (weekly/monthly/quarterly)
  • Multiple Payment Methods (credit cards, bank transfers, direct debit)
  • Real-time Usage Tracking
  • Cost Monitoring & Alerts
  • Email Invoice Delivery
  • Stripe & Qonto Integration

API Management

  • API Key Authentication
  • Usage-based Billing
  • Rate Limiting & Monitoring
  • Comprehensive Logging

πŸ“‹ Quick Start

Prerequisites

  • Python 3.8+
  • MediaMTX binary (for RTSP functionality)
  • Database (SQLite/PostgreSQL/MySQL)

Installation

  1. Clone and Setup:

    git clone <repository-url>
    cd vigint
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
  2. Configure:

    # Copy configuration templates
    cp config.ini.example config.ini
    cp server_config.ini.example server_config.ini
    
    # Edit configuration files with your settings
    nano config.ini
  3. Initialize Database:

    python3 start_vigint.py --init-db
  4. Download MediaMTX (for RTSP functionality):

    # Download from https://github.com/bluenviron/mediamtx/releases
    wget https://github.com/bluenviron/mediamtx/releases/latest/download/mediamtx_linux_amd64.tar.gz
    tar -xzf mediamtx_linux_amd64.tar.gz
    chmod +x mediamtx

Running the Application

# Start full application (API + RTSP)
./start.sh

# Start only API server
./start.sh api

# Start only RTSP server
./start.sh rtsp

# Or use Python directly
python3 start_vigint.py --mode full

πŸ“– Documentation

πŸ”§ Configuration

Basic Configuration (config.ini)

[Database]
database_url = sqlite:///vigint.db

[API]
secret_key = your-secret-key
host = 0.0.0.0
port = 5000

[Email]
smtp_server = smtp.gmail.com
smtp_port = 587
sender_email = [email protected]
sender_password = your-app-password

[SparseAI]
# Video hosting for security alerts
api_key = your-sparse-ai-api-key
base_url = https://sparse-ai.com
default_expiration_hours = 48

[Stripe]
api_key = sk_test_your_stripe_key

Environment Variables

export VIGINT_CONFIG_PATH=/path/to/config.ini
export VIGINT_SERVER_CONFIG_PATH=/path/to/server_config.ini

πŸ” API Usage

Authentication

# Get API key (create client first)
curl -X POST http://localhost:5000/api/clients \
  -H "Content-Type: application/json" \
  -d '{"name": "Test Client", "email": "[email protected]"}'

RTSP Streaming

# List streams
curl -H "X-API-Key: your-api-key" \
  http://localhost:5000/api/rtsp/paths/list

# Stream URL format
rtsp://localhost:8554/stream_name

Video Security Alerts

# Send security alert with video frames
curl -X POST http://localhost:5000/api/video/alert \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "analysis": "Security incident detected",
    "risk_level": "HIGH",
    "incident_type": "shoplifting",
    "frame_count": 150
  }'

New Feature: Videos are now uploaded to sparse-ai.com and private links are sent via email instead of large attachments.

# Python usage
from alerts import send_security_alert_with_video

result = send_security_alert_with_video(
    message="Security incident detected",
    frames=frame_buffer,  # Your video frames
    incident_data={
        'incident_type': 'shoplifting',
        'risk_level': 'HIGH',
        'analysis': 'Customer concealing merchandise'
    }
)

# Email will contain private link like:
# https://sparse-ai.com/video/abc123?token=xyz789

Usage Monitoring

# Get usage statistics
curl -H "X-API-Key: your-api-key" \
  http://localhost:5000/api/usage

πŸ”„ Automated Billing

Setup Cron Jobs

# Weekly billing (Mondays at 9 AM)
0 9 * * 1 /path/to/vigint/run_weekly_billing.py

# Daily cost monitoring
0 8 * * * /path/to/vigint/cost_monitor.py

Manual Billing

# Generate invoices manually
python3 generate_weekly_invoices.py

# Run cost monitoring
python3 cost_monitor.py

πŸ—οΈ Project Structure

vigint/
β”œβ”€β”€ vigint/                     # Core package
β”‚   β”œβ”€β”€ models.py              # Database models
β”‚   β”œβ”€β”€ billing_manager.py     # Billing system
β”‚   └── invoice_generator.py   # Invoice generation
β”œβ”€β”€ config.py                  # Configuration management
β”œβ”€β”€ auth.py                    # Authentication system
β”œβ”€β”€ api_proxy.py               # API proxy and routing
β”œβ”€β”€ rtsp_server.py             # RTSP server management
β”œβ”€β”€ start_vigint.py            # Main application entry
β”œβ”€β”€ start.sh                   # Startup script
β”œβ”€β”€ mediamtx_simple.yml        # MediaMTX configuration
β”œβ”€β”€ generate_weekly_invoices.py # Invoice generation
β”œβ”€β”€ cost_monitor.py            # Cost monitoring
└── requirements.txt           # Dependencies

πŸ” Monitoring & Logging

Health Checks

# API health
curl http://localhost:5000/api/health

# RTSP server status
./start_rtsp_server status

# MediaMTX API
curl http://localhost:9997/v1/config/global/get

Logs

  • Application: vigint.log
  • MediaMTX: mediamtx.log
  • Billing: /var/log/vigint/billing.log

πŸ§ͺ Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=vigint

Code Quality

# Format code
black .

# Lint code
flake8 .

# Type checking
mypy vigint/

🐳 Docker Support

# Build image
docker build -t vigint .

# Run container
docker run -p 5000:5000 -p 8554:8554 vigint

πŸ“Š Metrics & Monitoring

Prometheus Metrics

# MediaMTX metrics
curl http://localhost:9998/metrics

# Application metrics
curl http://localhost:5000/metrics

Cost Alerts

The system automatically monitors:

  • Daily cost thresholds
  • Per-client usage limits
  • Unusual usage patterns

πŸ”’ Security

  • API Key Authentication with secure hashing
  • Payment Tokenization via Stripe
  • Configuration Security with example templates
  • Audit Logging for all operations
  • Rate Limiting and usage monitoring

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages