Skip to content

m3hr4nn/logpatrol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ LogPatrol β€” Lightweight Log Audit Tool

LogPatrol is a fast, dependency-free Python script that scans system log files for suspicious or critical command usage like reboot, shutdown, systemctl, or any custom-defined commands β€” even in compressed logs!

πŸ’‘ Ideal for DevOps, sysadmins, and incident responders who need quick visibility into system-level actions across logs.


πŸ” Features

  • βœ… Find dangerous or suspicious commands like reboot, rm, or systemctl
  • 🧠 Scans plain & compressed logs (.log, .gz, .bz2) β€” even extensionless logs like /var/log/syslog
  • πŸ“¦ No external dependencies β€” only Python standard library
  • πŸ“ Includes the source filename and timestamp for every match
  • πŸ“Š Exports to clean CSV you can open in Excel for filtering/sorting
  • πŸš€ Fast and optimized β€” skips files without matches
  • 🧩 Customizable β€” define your own command list in commands.txt

βš™οΈ How It Works

  1. Place a list of commands (one per line) in a commands.txt file (optional)

  2. Run the script:

    python3 logpatrol.py
  3. Choose a log directory (default: /var/log)

  4. Review the results in a neatly structured CSV file like:

    hostname_20250702-1420_ParsedLines.csv

πŸ“ Output Example

date command file logs
2025-07-01 04:12:30 reboot /var/log/syslog system reboot initiated by root
Jul 1 02:01:05 systemctl /var/log/messages systemctl restart nginx.service

Note: Matched time patterns include YYYY-MM-DD HH:MM:SS or common syslog formats.


🧩 Custom Commands

Define your own suspicious or tracked commands by creating a commands.txt file next to the script:

  • reboot
  • shutdown
  • systemctl
  • iptables
  • rm -rf
  • ...

If no file is found, LogPatrol will use a default list of critical commands.


πŸ’Ό Use Cases

  • πŸ” Security Audits: Find unauthorized reboots or shutdowns
  • πŸ”§ Debugging: Trace command-triggered issues
  • πŸ“Š Compliance: Record actions for reporting and accountability
  • πŸ›‘οΈ Forensics: Triage after incidents

🧰 Requirements

  • Python 3.x
  • No third-party modules required

πŸš€ Why Use LogPatrol?

βœ… Faster than grepping multiple files manually
βœ… Works with compressed logs
βœ… Clean Excel-ready output
βœ… Fully portable β€” works anywhere Python does


πŸ“ƒ License

MIT License Β© 2025

About

To check /var/log about high risk commands execution.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages