Metadata-Version: 2.4
Name: template-log-parser
Version: 0.9.1
Summary: Parsing Log Files With User Defined Templates
Author-email: Caleb Yourison <caleb.yourison@gmail.com>
License: MIT License
        
        Copyright (c) 2024-2026 Caleb Yourison
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
        
Project-URL: homepage, https://github.com/calebyourison/simple_template_log_parser
Keywords: log,parse,template
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=2.0.0
Requires-Dist: parse==1.22.0
Dynamic: license-file

# template-log-parser : Log Files into Tabular Data
---
`template-log-parser` is designed to pull relevant information into DataFrame columns by way of user designed templates.  [parse](https://pypi.org/project/parse/) and [pandas](https://pypi.org/project/pandas/) perform the heavy lifting.

You can utilize the included [workflows](https://github.com/calebyourison/simple_template_log_parser/tree/master/template_workflows) (Kodi, Omada Controller, Open Media Vault, PFSense, PiHole, Synology DSM, and Ubuntu) or build your own. 

## Getting Started
---

```
pip install template-log-parser
```

---

The foundational principle in this project is designing templates that fit repetitive log file formats.


```
my_log_line = "2024-06-13T15:09:35 server_15 login_authentication[12345] rejected login from user[user_1]."

my_template = "{time} {server_name} {service_process}[{service_id}] {result} login from user[{username}]."
```

The words within the braces will eventually become column names in a DataFrame.  
Note that templates will be looking for an exact match.

---
After creating a list of templates, they should be compiled:

- 'search_string' is text expected to be found in the log file line.  The parsing function will only check the template against the line if the text is present.
- 'template' is the user defined template.
- 'event_type' is an arbitrary string name assigned to this type of occurrence.

```
from template_log_parser import compile_templates

uncompiled_templates = [
# [template, event_type, search_string ]
  [my_template, "login_attempt", "login from"],
  [my_template2, "reboot", "Host Restarting"],
  ...
]

my_templates = compile_templates(uncompiled_templates)

```
---

Parse an entire log file and return a Pandas DataFrame:
```
from template_log_parser import process_log

df = process_log('log_file.log', my_templates)

print(df.columns)
Index(['time', 'server_name', 'service_process', 'service_id', 'result', 'username', 'event_type', 'event_data'])
```
This is just a tabular data form of many single parsed events.
 - event_type column value is determined based on the matching template
 - event_data column holds the raw string data for each log line
 
Note: 
Events that do not match a template will be evaluated as event_type ('Other') with column: ('Unparsed_text').

---
## DISCLAIMER

**This project is in no way affiliated with the products mentioned (Debian, Kodi, Omada, Open Media Vault, PFSense, PiHole, Synology, or Ubuntu).
Any usage of their services is subject to their respective terms of use.**
