-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add templates to generate file to format lines based on regex
- Loading branch information
Alexis von Glasow
committed
Mar 20, 2017
1 parent
f156b98
commit 6957aaf
Showing
6 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
logentries_logs: [] | ||
logentries_account_key: "" | ||
logentries_stage: "" | ||
|
||
# formatters | ||
logentries_formatters: "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
- name: create folder containing formatters | ||
file: | ||
path: /etc/le/le_formatters/ | ||
state: directory | ||
mode: "u=rwx,g=rx,o=rx" | ||
owner: root | ||
become: yes | ||
tags: | ||
- logentries | ||
- formatters | ||
|
||
- name: initiate module | ||
file: | ||
path: /etc/le/le_formatters/__init__.py | ||
state: touch | ||
mode: "u=rwx,g=rx,o=rx" | ||
owner: root | ||
become: yes | ||
tags: | ||
- logentries | ||
- formatters | ||
|
||
- name: deploy formatting class | ||
template: | ||
src: le_formatters/formatters.py.j2 | ||
dest: /etc/le/le_formatters/formatters.py | ||
validate: python %s | ||
notify: | ||
- Restart logentries | ||
tags: | ||
- logentries | ||
- formatters | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import re | ||
|
||
class Form(object): | ||
"""Formats lines based of pattern given.""" | ||
|
||
def __init__(self, identity, hostname, log_name, token): | ||
self.identity = identity | ||
self.hostname = hostname | ||
self.log_name = log_name | ||
self.token = token | ||
|
||
{% for format in logentries_formatters.format %} | ||
def {{ format.method_name }}(self, line): | ||
line = line.rstrip() | ||
m = re.match(r"{{ format.regexp }}", line) | ||
if m: | ||
pl = m.groupdict() | ||
return {{ format.output_line }} | ||
else: | ||
return line | ||
|
||
{% endfor %} | ||
|
||
formatters = { | ||
{% for format in logentries_formatters.formatters %} | ||
'{{ logentries_stage }}-{{ format.logentries_project }}': lambda hostname, log_name, token: Form('{{ logentries_stage }}-{{ format.logentries_project }}', hostname, log_name, token).{{ format.method_name }}, | ||
{% endfor %} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
- hosts: localhost | ||
remote_user: root | ||
roles: | ||
- logentries | ||
- ansible-logentries |