Skip to main content

PrintAudit - Modern CUPS page_log analyzer for print accounting and cost allocation

Project description

PrintAudit

PrintAudit is a modern Python rewrite of the historical PrintAnalyzer Perl utility. It ingests CUPS page_log files, produces comprehensive usage, cost, and behavior reports, and supports modular outputs (CLI, CSV, HTML, email).

Features

  • Comprehensive Analysis: Queue usage, user activity, temporal patterns, cost allocation, and more
  • Cost Tracking: Currency-agnostic cost calculation with configurable rates per printer, department, or label
  • Flexible Outputs: Multiple output formats (CLI, CSV, HTML, email) with plugin architecture
  • Date Filtering: Analyze specific time ranges with --start-date and --end-date
  • Work Hours Detection: Identify printing activity within configured business hours
  • Modular Design: Easy to extend with custom output modules

Installation

From PyPI

pip install printaudit

From Source

git clone https://github.com/vhsantos/PrintAudit.git
cd printaudit
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Quick Test

PYTHONPATH=src python3 -m printaudit --config printaudit.conf.sample --dry-run

Configuration

Configuration File Search Order

PrintAudit searches for configuration files in this order:

  1. --config /path/to/printaudit.conf (command-line override)
  2. $PRINTAUDIT_CONFIG (environment variable)
  3. /etc/printaudit/printaudit.conf
  4. /etc/printaudit.conf
  5. ./printaudit.conf (current directory)

Basic Setup

  1. Copy the sample configuration:

    sudo cp printaudit.conf.sample /etc/printaudit.conf
    
  2. Edit /etc/printaudit.conf and adjust:

    • page_log_path: Path to your CUPS page_log file
    • work_start / work_end: Business hours (7-22 = 7 AM to 10 PM)
    • outputs: Comma-separated list of output modules
    • enabled_sections: Which analysis sections to include

Configuration Sections

[core] - Main Settings

[core]
page_log_path=/var/log/cups/page_log
work_start=7
work_end=22
enabled_sections=queue,queue_user,user,temporal,job,cost
outputs=cli,csv,html,email
cli_mode=rich              # or "plain"
cli_max_rows=15
csv_dir=/var/spool/printaudit/reports
html_path=/var/spool/printaudit/reports/printaudit.html
html_use_chartjs=false     # Use Chart.js for graphs (optional)

[email] - Email Delivery

[email]
enabled=true
smtp_host=mail.example.com
smtp_port=587
smtp_user=printaudit@example.com
smtp_password=secret
use_tls=true
recipients=ops@example.com,finance@example.com
subject=PrintAudit Report
from=printaudit@example.com
attach_csv=true
attach_html=true
report_in_body=true       # Include full report text in email body

[costs] - Cost Calculation

[costs]
# Default cost per page (unitless, use your local currency)
default=0.02

# Currency display settings (optional)
currency_symbol=CLP$
currency_code=CLP

# Printer-specific rates (optional)
printer.Printer01=0.01
printer.Printer02=0.05

# Department/label-specific rates (optional)
label.accounting=0.03
label.marketing=0.05
label.IT=0.04

[cost_rules] - Cost Label Mapping

[cost_rules]
# Map users/queues to cost labels for department allocation
accounting=accounting1,accounting2,accounting3
sales=bob
platform=charlie,diana,eve
it=alice

Usage

Basic Command

printaudit

With Date Range

printaudit --start-date 2025-04-01 --end-date 2025-04-30

Override Outputs

printaudit --outputs cli,html

List Available Output Modules

printaudit --list-outputs

Dry Run (Test Configuration)

printaudit --dry-run

Output Modules

PrintAudit supports multiple output formats:

  • cli: Terminal report with plain or rich formatting
  • csv: One CSV file per analysis section in csv_dir
  • html: Interactive HTML dashboard with charts
  • email: SMTP delivery of summary and attachments

See Creating Output Modules for extending with custom formats.

Analysis Modules

PrintAudit provides comprehensive analysis across multiple dimensions:

  • Queue Analysis: Usage by printer/queue with percentages
  • User Analysis: Per-user statistics with pages per request
  • Temporal Analysis: Hourly and daily usage patterns
  • Job Analysis: Distribution of job sizes and copy counts
  • Cost Analysis: Department/label-based cost allocation
  • Media Analysis: Paper/media type usage
  • Client Analysis: Source hostname tracking
  • Document Types: File extension analysis
  • Duplex Analysis: Two-sided vs. one-sided printing

See Analysis Modules Documentation for detailed explanations and expected outputs.

Command-Line Options

  -c, --config PATH       Path to configuration file
  -o, --outputs LIST     Comma-separated output modules override
  --cli-mode MODE        CLI renderer style (plain/rich)
  --start-date DATE      Filter start date (YYYY-MM-DD)
  --end-date DATE        Filter end date (YYYY-MM-DD)
  --dry-run              Test configuration without running
  --list-outputs         List available output modules
  -h, --help             Show help message

Examples

Generate All Reports

printaudit

This creates:

  • CLI output to terminal
  • CSV files in csv_dir
  • HTML report at html_path
  • Email delivery (if enabled)

Monthly Report

printaudit --start-date 2025-04-01 --end-date 2025-04-30

HTML Only

printaudit --outputs html

Sample Report Output

See example reports to understand the output format:

Requirements

  • Python 3.10+
  • CUPS page_log file access
  • Optional: SMTP server for email delivery

Dependencies

  • rich>=13.0.0 - Enhanced terminal output
  • click>=8.0.0 - Command-line interface

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please see the documentation for:

Automation

Logrotate Integration

PrintAudit can be integrated with logrotate to automatically generate reports when CUPS logs are rotated. See Logrotate Setup Guide for detailed examples including:

  • Weekly and monthly rotation configurations
  • Automated email reporting

Support

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

printaudit-0.9.0.tar.gz (56.1 kB view details)

Uploaded Source

Built Distribution

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

printaudit-0.9.0-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

Details for the file printaudit-0.9.0.tar.gz.

File metadata

  • Download URL: printaudit-0.9.0.tar.gz
  • Upload date:
  • Size: 56.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for printaudit-0.9.0.tar.gz
Algorithm Hash digest
SHA256 15cee917a422ea0533780d97ae31d4ad94bb8b630134c448b70a3a04069dcd4f
MD5 27f5525417b119c5ae1cb49cc1bb394b
BLAKE2b-256 a2583ab0d4c5591a652c886ac9629ad68a0a93231d5c133f2eef17fadae5b318

See more details on using hashes here.

Provenance

The following attestation bundles were made for printaudit-0.9.0.tar.gz:

Publisher: publish.yml on vhsantos/PrintAudit

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

File details

Details for the file printaudit-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: printaudit-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for printaudit-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 284b4fb4f1b7bfb3963c69fb2ca182a5fe98790bb1ddfa64345354ff380e7403
MD5 8d16746a5f8e6ce9ee398f0fe76b2c76
BLAKE2b-256 3547ae14bccf3e006b15dc964dd1bf97e3bef8095cc852f33b5e02eaa7de9f49

See more details on using hashes here.

Provenance

The following attestation bundles were made for printaudit-0.9.0-py3-none-any.whl:

Publisher: publish.yml on vhsantos/PrintAudit

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