基于配置文件生成虚拟日志

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个必需属性:namefileformatfrequencyamount,和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
时间戳。

format:The format that the timestamp should have
整数(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地址。

示例

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
junit有没有办法在Java中重新初始化静态类?   在浏览器中点击应用程序时java Play框架挂起   文件Java错误中的NullPointerException   使用Java中的SNMP查找网络中计算机的登录名   java包装服务器引导程序已弃用,有什么替代方案?   当客户在等待理发时,java信号量值是否存在问题?   java如何使用JavaMail仅下载特定类型的附件   如何在java中将十进制转换为十六进制   java Slick2D粒子系统不会生成粒子   java检测更改事件来自何处   将Java集合类型参数类设置为数组   java如何从eclipse导出为可运行JAR文件?   java EntityManager对象未注入Glassfish和Spring   swing从actionPerformed和actionListener Java返回字符串   java在给定另一个等价键对象的情况下获取映射项的当前键   无论输入如何,java网络都会产生相同的输出