{"id":47685322,"url":"https://github.com/adrianvillanueva997/fail2ban-log-parser","last_synced_at":"2026-04-02T14:47:40.996Z","repository":{"id":347028806,"uuid":"1187744260","full_name":"adrianvillanueva997/fail2ban-log-parser","owner":"adrianvillanueva997","description":"Simple to use Fail2ban log parser in rust with python bindings","archived":false,"fork":false,"pushed_at":"2026-03-27T03:21:33.000Z","size":1241,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-27T04:32:42.638Z","etag":null,"topics":["fail2ban","nodejs","parser","python","rust","typescript","winnow"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/fail2ban-log-parser-core","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrianvillanueva997.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-21T05:14:38.000Z","updated_at":"2026-03-27T03:21:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/adrianvillanueva997/fail2ban-log-parser","commit_stats":null,"previous_names":["adrianvillanueva997/fail2ban-log-parser"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/adrianvillanueva997/fail2ban-log-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianvillanueva997%2Ffail2ban-log-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianvillanueva997%2Ffail2ban-log-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianvillanueva997%2Ffail2ban-log-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianvillanueva997%2Ffail2ban-log-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrianvillanueva997","download_url":"https://codeload.github.com/adrianvillanueva997/fail2ban-log-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianvillanueva997%2Ffail2ban-log-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31308431,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fail2ban","nodejs","parser","python","rust","typescript","winnow"],"created_at":"2026-04-02T14:47:37.043Z","updated_at":"2026-04-02T14:47:40.988Z","avatar_url":"https://github.com/adrianvillanueva997.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fail2ban-log-parser\n\nFast, zero-copy fail2ban log parser with bindings for **Rust**, **Python**, and **JavaScript**.\n\n[![crates.io](https://img.shields.io/crates/v/fail2ban-log-parser-core)](https://crates.io/crates/fail2ban-log-parser-core)\n[![docs.rs](https://img.shields.io/docsrs/fail2ban-log-parser-core)](https://docs.rs/fail2ban-log-parser-core)\n[![PyPI](https://img.shields.io/pypi/v/fail2ban-log-parser)](https://pypi.org/project/fail2ban-log-parser/)\n[![License](https://img.shields.io/crates/l/fail2ban-log-parser-core)](LICENSE)\n[![Benchmark History](https://img.shields.io/badge/benchmarks-history-blue)](https://adrianvillanueva997.github.io/fail2ban-log-parser/)\n\nParse fail2ban logs at **~142 ns/line** with **19 heap allocations per million lines**, `Fail2BanStructuredLog` borrows directly from the input, so only the output `Vec` and its backing buffer are heap-allocated. Enable the `parallel` feature for up to **5.4× speedup** on large inputs via Rayon.\n\n---\n\n## Installation\n\n### Rust\n\n```sh\ncargo add fail2ban-log-parser-core\n```\n\nWith serde support:\n\n```sh\ncargo add fail2ban-log-parser-core --features serde\n```\n\nWith parallel parsing (multi-threaded via Rayon):\n\n```sh\ncargo add fail2ban-log-parser-core --features parallel\n```\n\n### Python\n\n```sh\npip install fail2ban-log-parser\n```\n\nRequires Python 3.10+. Prebuilt wheels are available for Linux (x86_64, aarch64), macOS (aarch64), and Windows (x86_64).\n\n---\n\n## Usage\n\n### Rust\n\n#### Parse a single line\n\n```rust\nuse fail2ban_log_parser_core::parse;\n\nlet line = \"2024-01-15 14:32:01,847 fail2ban.filter [12345] INFO [sshd] Found 192.168.1.1\";\nlet log = parse(line).next().unwrap().unwrap();\n\nassert_eq!(log.jail(), Some(\"sshd\"));\nassert_eq!(log.pid(), Some(12345));\nprintln!(\"{:?} {:?} {:?}\", log.event(), log.ip(), log.timestamp());\n```\n\n\u003e **Note:** Parsed results borrow from the input `\u0026str`, the input buffer must outlive the iterator and any collected results.\n\n#### Parse a batch and handle errors\n\n```rust\nuse fail2ban_log_parser_core::parse;\n\nlet input = \"\\\n2024-01-15 14:32:01,847 fail2ban.filter [12345] INFO [sshd] Found 192.168.1.100\nthis line is not a valid log entry\n2024-01-15 14:32:03,456 fail2ban.actions [12345] NOTICE [sshd] Ban 192.168.1.100\";\n\nfor result in parse(input) {\n    match result {\n        Ok(log) =\u003e println!(\"{:?} {:?}\", log.event(), log.ip()),\n        Err(e) =\u003e eprintln!(\"parse error: {e}\"),\n    }\n}\n```\n\n#### Filter specific events\n\n```rust\nuse fail2ban_log_parser_core::{Fail2BanEvent, parse};\n\nlet input = \"...\"; // multi-line log\nlet bans: Vec\u003c_\u003e = parse(input)\n    .filter_map(|r| r.ok())\n    .filter(|log| log.event() == Some(\u0026Fail2BanEvent::Ban))\n    .collect();\n```\n\n### Python\n\n#### Parse a single line\n\n```python\nfrom fail2ban_log_parser import parse, Event\n\nline = \"2024-01-15 14:32:01,847 fail2ban.filter [12345] INFO [sshd] Found 192.168.1.1\"\nlogs, errors = parse(line)\n\nlog = logs[0]\nprint(log.timestamp)  # \"2024-01-15T14:32:01.847+00:00\"\nprint(log.jail)       # \"sshd\"\nprint(log.event)      # Event.Found\nprint(log.ip)         # \"192.168.1.1\"\nprint(log.pid)        # 12345\n```\n\n#### Parse a batch and handle errors\n\n```python\nfrom fail2ban_log_parser import parse\n\ninput_text = \"\"\"\\\n2024-01-15 14:32:01,847 fail2ban.filter [12345] INFO [sshd] Found 192.168.1.100\nthis line is not a valid log entry\n2024-01-15 14:32:03,456 fail2ban.actions [12345] NOTICE [sshd] Ban 192.168.1.100\"\"\"\n\nlogs, errors = parse(input_text)\n\nfor log in logs:\n    print(f\"{log.event} {log.ip} in jail {log.jail}\")\n\nfor err in errors:\n    print(f\"Line {err.line_number}: {err.line}\")\n```\n\n#### Filter bans\n\n```python\nfrom fail2ban_log_parser import parse, Event\n\nlogs, _ = parse(open(\"/var/log/fail2ban.log\").read())\nbans = [log for log in logs if log.event == Event.Ban]\n\nfor ban in bans:\n    print(f\"Banned {ban.ip} from {ban.jail} at {ban.timestamp}\")\n```\n\n#### Group events by jail\n\n```python\nfrom collections import defaultdict\nfrom fail2ban_log_parser import parse\n\nlogs, _ = parse(open(\"/var/log/fail2ban.log\").read())\n\nby_jail = defaultdict(list)\nfor log in logs:\n    if log.jail:\n        by_jail[log.jail].append(log)\n\nfor jail, entries in by_jail.items():\n    print(f\"{jail}: {len(entries)} events\")\n```\n\n---\n\n## Log structure\n\n```\n2024-01-15 14:32:01,847  fail2ban.filter  [12345]  INFO  [sshd] Found 1.2.3.4\n|___________________|    |______________|  |____|   |__|  |____| |__| |______|\n    timestamp              header            pid    level  jail  event  IP\n```\n\n### Supported formats\n\n| Field | Formats |\n|---|---|\n| Timestamp | `2024-01-15 14:32:01,847`, `Jan 15 2024 14:32:01,847`, `2024-01-15T14:32:01,847Z`, `±HH:MM` offset |\n| Header | `fail2ban.filter`, `fail2ban.actions`, `fail2ban.server` |\n| Level | `INFO`, `NOTICE`, `WARNING`, `ERROR`, `DEBUG` (case-insensitive) |\n| Event | `Found`, `Ban`, `Unban`, `Restore`, `Ignore`, `AlreadyBanned`, `Failed`, `Unknown` |\n| IP | IPv4 (`192.168.1.1`) and IPv6 (`2001:db8::1`) |\n\n---\n\n## API\n\n### Rust\n\n| Type | Description |\n|---|---|\n| `parse(\u0026str)` | Returns `Iterator\u003cItem = Result\u003cFail2BanStructuredLog, ParseError\u003e\u003e`. Sequential by default; with `parallel`, lines are parsed concurrently via Rayon (same API). |\n| `Fail2BanStructuredLog` | Parsed log line. Accessor methods: `timestamp()`, `header()`, `pid()`, `level()`, `jail()`, `event()`, `ip()`. Borrows from input — input must outlive results. |\n| `Fail2BanEvent` | Enum: `Found`, `Ban`, `Unban`, `Restore`, `Ignore`, `AlreadyBanned`, `Failed`, `Unknown` |\n| `Fail2BanHeaderType` | Enum: `Filter`, `Actions`, `Server` |\n| `Fail2BanLevel` | Enum: `Info`, `Notice`, `Warning`, `Error`, `Debug` |\n| `ParseError` | Contains `line_number: usize` and `line: String` |\n\n### Python\n\n| Type | Description |\n|---|---|\n| `parse(input: str)` | Returns `(list[Fail2BanLog], list[ParseError])`. |\n| `Fail2BanLog` | Parsed log line. Properties: `timestamp` (RFC 3339), `header`, `pid`, `level`, `jail`, `event`, `ip` — all `Optional`. |\n| `Event` | Enum: `Found`, `Ban`, `Unban`, `Restore`, `Ignore`, `AlreadyBanned`, `Failed`, `Unknown` |\n| `HeaderType` | Enum: `Filter`, `Actions`, `Server` |\n| `Level` | Enum: `Info`, `Notice`, `Warning`, `Error`, `Debug` |\n| `ParseError` | Properties: `line_number` (int), `line` (str) |\n\n### Features\n\n| Feature | Description |\n|---|---|\n| `serde` | Enables `Serialize`/`Deserialize` on all public types |\n| `parallel` | Multi-threaded parsing via Rayon. Same `parse()` API, lines parsed concurrently. Not supported on `wasm32` targets (compile-time error). |\n| `debug_errors` | Extra error context for debugging parse failures |\n\n---\n\n## How it works\n\n```mermaid\nflowchart TD\n    A[\"\u0026str (multi-line log)\"] --\u003e B[\"parse()\"]\n    B --\u003e C{parallel feature?}\n    C --\u003e|No| D[\"Split into lines (lazy)\"]\n    C --\u003e|Yes| E[\"Collect lines + Rayon par_iter\"]\n    D --\u003e F[\"parse_log_line() per line\"]\n    E --\u003e F\n\n    F --\u003e T[\"timestamp\"]\n    F --\u003e H[\"header\"]\n    F --\u003e P[\"pid\"]\n    F --\u003e L[\"level\"]\n    F --\u003e J[\"jail\"]\n    F --\u003e EV[\"event\"]\n    F --\u003e I[\"ip\"]\n\n    T \u0026 H \u0026 P \u0026 L \u0026 J \u0026 EV \u0026 I --\u003e R{Result}\n    R --\u003e|Ok| S[\"Fail2BanStructuredLog\"]\n    R --\u003e|Err| ERR[\"ParseError\"]\n\n    S \u0026 ERR --\u003e O[\"Iterator of Results\"]\n```\n\nThe parser is built with [winnow](https://docs.rs/winnow), a fast parser combinator library. Each log line is parsed in a single pass with no intermediate allocations, `Fail2BanStructuredLog` holds `\u0026str` slices into the original input rather than owned strings.\n\n---\n\n## Benchmarks\n\nMeasured with [Criterion.rs](https://github.com/criterion-rs/criterion.rs) + [dhat](https://docs.rs/dhat) on Apple M4 Pro (12 cores) / 48 GB / rustc 1.94.0.\n\n📈 [View full benchmark history](https://adrianvillanueva997.github.io/fail2ban-log-parser/)\n\n### Single-line parsing\n\n| Variant | Time |\n|---|---|\n| ISO date + IPv4 | ~121 ns |\n| Syslog date | ~127 ns |\n| ISO 8601 (T-separator) | ~121 ns |\n| IPv6 address | ~144 ns |\n\n### Batch parsing — sequential (default)\n\nSingle-threaded, lazy iterator. Each line is parsed on demand.\n\n| Lines | Total time | Per line |\n|---|---|---|\n| 10 | ~1.35 µs | ~135 ns |\n| 100 | ~14.1 µs | ~141 ns |\n| 1,000 | ~142 µs | ~142 ns |\n| 10,000 | ~1.42 ms | ~142 ns |\n| 100,000 | ~14.3 ms | ~143 ns |\n| 1,000,000 | ~143 ms | ~143 ns |\n\n### Batch parsing — parallel (`--features parallel`)\n\nMulti-threaded via Rayon. Lines are parsed concurrently, then yielded in order.\n\n| Lines | Total time | Per line | Speedup |\n|---|---|---|---|\n| 1,000 | ~114 µs | ~114 ns | 1.2× |\n| 10,000 | ~442 µs | ~44 ns | 3.2× |\n| 100,000 | ~2.77 ms | ~28 ns | 5.2× |\n| 1,000,000 | ~26.3 ms | ~26 ns | **5.4×** |\n\n\u003e Parallel overhead makes it slower than sequential for inputs under ~1,000 lines. Speedup scales with core count.\n\n### Collection strategies (1,000 lines, sequential)\n\n| Strategy | Time |\n|---|---|\n| Iterate + count | ~144 µs |\n| Collect to `Vec` | ~150 µs |\n| Partition ok/err | ~147 µs |\n\n### Error handling\n\n| Scenario | Time |\n|---|---|\n| 1,000 lines (50% invalid) | ~81 µs |\n| All 8 event types (8 lines) | ~1.14 µs |\n\n### Memory usage (sequential, collect to `Vec`)\n\nHeap allocations measured with [dhat](https://docs.rs/dhat). The low allocation count reflects the zero-copy design,  only the `Vec` itself and its backing buffer are heap-allocated; all string fields borrow from the input.\n\n| Lines | Total allocated | Peak in-use | Alloc count | Per line |\n|---|---|---|---|---|\n| 1 | 224 B | 224 B | 1 | 224 B |\n| 100 | 13.78 KB | 7.00 KB | 6 | 141 B |\n| 1,000 | 111.78 KB | 56.00 KB | 9 | 114 B |\n| 10,000 | 1.75 MB | 896.00 KB | 13 | 183 B |\n| 100,000 | 14.00 MB | 7.00 MB | 16 | 146 B |\n| 1,000,000 | 112.00 MB | 56.00 MB | **19** | 117 B |\n\n### Reproduce\n\n```sh\n# Sequential benchmarks\ncargo bench -p fail2ban-log-parser-core --bench parsing\n\n# Parallel benchmarks\ncargo bench -p fail2ban-log-parser-core --bench parsing --features parallel\n```\n\n---\n\n## Examples\n\n```sh\ncargo run -p fail2ban-log-parser-core --example parse_single\ncargo run -p fail2ban-log-parser-core --example parse_batch\ncargo run -p fail2ban-log-parser-core --example filter_bans\n```\n\n---\n\n## License\n\nApache-2.0,  see [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianvillanueva997%2Ffail2ban-log-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrianvillanueva997%2Ffail2ban-log-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianvillanueva997%2Ffail2ban-log-parser/lists"}