Skip to main content

A CLI tool to measure energy consumption of Bandit and Semgrep scans using Energibridge.

Project description

SAST (Static application security testing) Energy Monitor

PyPI version

A command-line tool to measure the energy consumption of static analysis scans (Bandit, Semgrep) on your codebase using Energibridge, with clear, colored output.

What it Does

This tool wraps bandit or semgrep scans within an energibridge measurement process. It runs the specified scan using predefined configurations bundled with the tool and displays:

  • The findings reported by Bandit or Semgrep.
  • The total energy consumed during the scan execution, as reported by Energibridge.
  • Colored output for better readability (errors in red, findings in yellow, success/summary in green/magenta).

Prerequisites

  1. Python: Version 3.8 or higher.

  2. Energibridge:

    • You must have the energibridge.exe (or your OS equivalent) executable installed and know its path. Energibridge needs to be obtained separately from its source.
    • Windows Setup (RAPL Service): Energibridge often relies on the RAPL (Running Average Power Limit) service to access energy data on Windows. If you haven't configured this before, you may need to install and start the service using Administrator privileges:
      # Open PowerShell or Command Prompt as Administrator
      
      # Create the service (Replace path if LibreHardwareMonitor.sys is elsewhere)
      sc create rapl type=kernel binPath="C:\path\to\your\LibreHardwareMonitor.sys"
      
      # Start the service
      sc start rapl
      
      • Note: You only need to do this once. Verify the path to LibreHardwareMonitor.sys (which often comes with tools like LibreHardwareMonitor or potentially Energibridge's dependencies).
      • You can test if Energibridge is working correctly by running a simple command like energibridge.exe --summary timeout 5 in your terminal (as Admin if needed).
  3. Bandit / Semgrep:

    • The specific scanner (bandit or semgrep) you intend to use must be installed in your Python environment and accessible from your system's PATH.
    • Install them if needed:
      pip install bandit semgrep
      

Installation

From PyPI (Recommended once published):

pip install sast_energy_monitor

From Source (for development or local use):

# Clone the repository (replace with actual URL if available)
# git clone https://github.com/yourusername/scan-energy-monitor.git
# cd scan-energy-monitor
pip install .

Usage

Run the tool from your command line:

sast_energy_monitor --energibridge-path /path/to/energibridge.exe \
            --repo-path /path/to/your/code/repository \
            --tool [bandit|semgrep] \
            --config-level [strict|loose]

Arguments:

  • energibridge-path: (Required) Absolute or relative path to your energibridge executable.

  • repo-path: (Required) Path to the root directory of the code repository you want to scan.

  • tool: (Required) Choose bandit or semgrep.

  • config-level: (Required) Choose strict or loose. This selects a predefined configuration file bundled with the tool.

Example:

# On Windows (using PowerShell escape character `)
sast_energy_monitor --energibridge-path C:\Tools\energibridge.exe
            --repo-path C:\MyProjects\MyApp
            --tool bandit
            --config-level strict

# On Linux/macOS (using \)
sast_energy_monitor --energibridge-path /usr/local/bin/energibridge \
            --repo-path ~/projects/my_app \
            --tool semgrep \
            --config-level loose

The tool will execute the scan, display the scanner's findings, and print the final energy consumption summary from Energibridge. Non-zero exit codes from scanners (indicating findings) are handled gracefully.

Bundled Configurations

This tool uses internal configuration files:

  • Bandit:

    • loose: Uses the bundled configs/.bandit_basic file.

    • strict: Uses the bundled configs/.bandit file.

  • Semgrep:

    • loose: Uses the bundled configs/.semgrep.yml file.

    • strict: Uses the Semgrep Registry ruleset p/bandit.

You currently cannot override these configurations via command-line arguments.

Important Notes

  • Administrator Privileges: Depending on your system configuration and how Energibridge accesses hardware sensors, you might need to run the scan-energy command itself with Administrator/root privileges for Energibridge to function correctly. Test without first, but if you encounter errors accessing energy data, try running as Admin.

  • The accuracy of energy measurements depends heavily on Energibridge's capabilities and the underlying hardware support (like Intel RAPL).

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributors

Sustainable Software Engineering Group 10, TU Delft:

  • Yulin Chen
  • Ayush Kuruvilla
  • Sahar Marossi
  • Andrea Onofrei

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

sast_energy_monitor-0.1.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

sast_energy_monitor-0.1.3-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file sast_energy_monitor-0.1.3.tar.gz.

File metadata

  • Download URL: sast_energy_monitor-0.1.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for sast_energy_monitor-0.1.3.tar.gz
Algorithm Hash digest
SHA256 85a4d08d103ecb3defdca10099c33564b845e570bbc0e8a01729d70cdef25812
MD5 f072593c2ffb8c0a8f8b3a2a549a9734
BLAKE2b-256 756dbbcbe369db461c4686ff1d1edd40e6856ea1ce19dd729c6df49aeea8e4e7

See more details on using hashes here.

File details

Details for the file sast_energy_monitor-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sast_energy_monitor-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5e73b83076f821771b22f6a6b9444a0e13bbe1f013de5282a0737912a8ef4e
MD5 7179e6959739db094da5b5eb0821566f
BLAKE2b-256 82e8131018d8cae45326f175d0b7b8dc3caf6d9edfdabeff28966a4bcb130107

See more details on using hashes here.

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