基于配置文件生成虚拟日志
log-generator的Python项目详细描述
log_generator根据配置文件生成虚拟日志。
usage: log-generator [-h] [--level LEVEL] [--truncate] /path/to/config Generate log events positional arguments: /path/to/config Path to configuration directory optional arguments: -h, --help show this help message and exit --level LEVEL, -l LEVEL Logging level --truncate, -t Truncate the log files on start
配置文件
日志生成器使用一组配置文件来定义如何生成日志。 您可以在log_generator/schema.yaml中看到配置文件的架构。 有6个必需属性:name,file,format,frequency,amount,和fields:
name: | Name of the logs being generated (for logging purposes only) |
---|---|
file: | The path to the file where to write the logs to |
frequency: | Time frame of how frequently to output logs |
amount: | Number of logs to create per tick |
enabled: | (optional) Boolean as to whether the configuration file should be used (default True) |
offset: | (optional) Time frame of the offset, from now, the timestamps should be |
jitter: | (optional) Time frame of the jitter the timestamps should be. |
format: | The format of the log |
fields: | A dictionary of fields to be substituted into the log format |
fields的每个属性都应该是以下类型之一:
type: | One of ^{tt10}$, ^{tt11}$, ^{tt12}$, ^{tt13}$, ^{tt14}$, ^{tt15}$ |
---|---|
repeat: | (optional) Number of times to repeat the current value before generating (default 1) |
change: | (optional) Float probability [0..1] that the current value will change (default 1) |
value: | (optional) The initial value for the field |
- 枚举(enum)
具有被选择的均匀分布的值的列表。
values: List of possible options - 时间戳(timestamp) 时间戳。
- 整数(integer)
随机整数值。
min: Minimum value of the integer max: Maximum value of the integer - 浮动(float)
随机浮点值。
min: Minimum value of the float max: Maximum value of the float - 机会(chance)
定义被选中概率的一组选项和相关权重
choices: A list of objects with two properties: ^{tt21}$ and ^{tt22}$ choices.*.option: The value of the option choices.*.weight: The probability of being selected - IP地址(ip)
- 随机生成的IP地址。
format: | The format that the timestamp should have |
---|
示例
apache 2.4访问:
name: Apache General Access file: /var/log/httpd/apache_access format: "{log_ip} - - [{log_time} +0000] \"{log_method} {log_path} HTTP/1.1\" {log_status} {log_bytes}" frequency: seconds: 5 offset: seconds: 0 jitter: seconds: 5 amount: 50 fields: log_ip: type: ip log_time: type: timestamp format: "%d/%b/%Y:%H:%M:%S" log_method: type: enum values: [POST, GET, PUT, PATCH, DELETE] log_path: type: enum values: - /auth - /alerts - /events - /playbooks - /lists - /fieldsets - /customers - /collectors - /parsers - /users log_status: type: enum values: [200, 201, 204, 300, 301, 400, 401, 403, 404, 500, 503] log_bytes: type: integer min: 2000 max: 5000
自定义日志:
name: Simulated Field Change file: /var/log/server/status format: "{log_time} server status: {log_colour}" frequency: seconds: 11 offset: seconds: 0 amount: 1 fields: log_time: type: timestamp format: "%Y-%m-%dT%H:%M:%SZ" log_colour: type: chance repeat: 11 change: 0.25 value: green choices: - option: red weight: 0.2 - option: yellow weight: 0.2 - option: green weight: 0.6