Éric Lemoine | 48f39bf | 2016-12-13 16:31:28 +0100 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | |
| 6 | def syslog_file_match(output): |
| 7 | """ |
| 8 | Return patterns to be used in logstreamer file_match config params. |
| 9 | |
| 10 | For example the function may return this dict: |
| 11 | |
| 12 | { |
| 13 | "/var/log": "kern\.log|auth\.log|syslog|mail\.log|mail\.err" |
| 14 | } |
| 15 | """ |
| 16 | file_match = {} |
| 17 | for name, config in output.get('file', {}).items(): |
| 18 | if not config.get('enabled', False): |
| 19 | continue |
| 20 | logdir = os.path.dirname(name) |
| 21 | pattern = os.path.basename(name).replace('.', '\.') |
| 22 | if logdir in file_match: |
| 23 | file_match[logdir] = file_match[logdir] + '|' + pattern |
| 24 | else: |
| 25 | file_match[logdir] = pattern |
| 26 | return file_match |