Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 1 whitespace to match many whitespaces #70

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions napalm_logs/config/eos.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# You should not use special characture in the value keys
#
# A single whitespace in `line` will match any number of whitespaces. You should be explicit when
# Matching white space in `values`
#
prefix:
time_format: "%b %d %H:%M:%S"
values:
Expand Down
4 changes: 4 additions & 0 deletions napalm_logs/config/iosxr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# You should not use special characture in the value keys
#
# A single whitespace in `line` will match any number of whitespaces. You should be explicit when
# Matching white space in `values`
#
prefix:
values:
messageId: (\d+)
Expand Down
6 changes: 5 additions & 1 deletion napalm_logs/config/junos.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# You should not use special characture in the value keys
#
# A single whitespace in `line` will match any number of whitespaces. You should be explicit when
# Matching white space in `values`
#
prefix:
time_format: "%b %d %H:%M:%S"
values:
date: (\w+ \d\d)
date: (\w+\s+\d+)
time: (\d\d:\d\d:\d\d)
host: ([^ ]+)
processName: /?(\w+)
Expand Down
2 changes: 2 additions & 0 deletions napalm_logs/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def _compile_messages(self):
sorted_position[elem[1]] = i + 1
# Escape the line, then remove the escape for the curly bracets so they can be used when formatting
escaped = re.escape(line).replace('\{', '{').replace('\}', '}')
# Replace a whitespace with \s+
escaped = escaped.replace('\ ', '\s+')
self.compiled_messages.append(
{
'error': error,
Expand Down
2 changes: 2 additions & 0 deletions napalm_logs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def _compile_prefixes(self):
sorted_position[elem[1]] = i + 1
# Escape the line, then remove the escape for the curly bracets so they can be used when formatting
escaped = re.escape(line).replace('\{', '{').replace('\}', '}')
# Replace a whitespace with \s+
escaped = escaped.replace('\ ', '\s+')
self.compiled_prefixes[dev_os] = {
'prefix': re.compile(escaped.format(**values)),
'prefix_positions': sorted_position,
Expand Down