5 个不稳定版本
| 0.3.1 | 2024年4月15日 | 
|---|---|
| 0.3.0 | 2024年4月14日 | 
| 0.2.1 | 2024年4月8日 | 
| 0.1.1 | 2024年3月31日 | 
| 0.1.0 | 2024年3月31日 | 
#463 在 数据库接口 中
在 fiddler-cli 中使用
92KB
 2K  SLoC
Fiddler  
  
 
Fiddler 是一个基于 Rust 构建的流处理器,使用基于 YAML 的配置文件语法来映射输入、处理器和输出。
例如
input:
    stdin: {}
pipeline:
  max_in_flight: 10
  processors:
    - python: 
        string: true
        code: |
            import json
            msg = json.loads(root)
            msg['Python'] = 'rocks'
            root = json.dumps(msg)
output:
  switch:
    - check:
        condition: '\"Hello World\" > `5`'
        output:
          validate: 
            expected: []
    - stdout: {}
主内联消息操作由 Python 提供,需要 Python 共享库。
在 Ubuntu 上安装 Python 共享库: sudo apt install python3-dev 在基于 RPM 的发行版(例如 Fedora、Red Hat、SuSE)上安装 Python 共享库,请安装 python3-devel 软件包。
在 fiddler 运行的操作系统上安装任何 Python 第三方包。
消息的输入和输出格式简单,事件源存储在名为 root 的本地变量中;执行代码后期望的输出应命名为 root。默认情况下,root 是消息的字节,除非提供了 string: true 参数,在这种情况下,root 转换为字符串。
可以通过使用 check 和 switch 插件来执行处理步骤的条件执行或选择输出。对于处理,它看起来像
- switch:
    - check: 
        condition: '\"Hello World\" <= `5`'
        processors:
            - python: 
                string: true
                code: |
                    import json
                    new_string = f\"python: {root}\"
                    root = new_string
            - echo: {}
    - label: my_cool_mapping
        echo: {}
用于评估的条件格式使用 [jmespath](https://jmespath.org/specification.html) 语法。因此,这只能用于 JSON 文档。
安装
- 在此处获取您操作系统的发布版本 这里
- 使用 Cargo 安装 cargo install fiddler
运行
- fiddler run-c<配置文件路径> [ -c... ]
检查
- fiddler lint-c<配置文件路径> [ -c... ]
测试
测试应以以下格式进行:<filename>_test.yaml。例如,如果您有一个配置文件 input.yaml,则期望的文件名是 input_test.yaml。测试文件的语法如下
- name: name_of_test
  inputs:
   - list of expected input strings
  expected_outputs:
   - list of expected output strings
测试可以按以下方式运行:fiddler-cli test -c <path_to_configuration>.yaml
构建
使用 Cargo 构建 cargo build --release --features all
插件
输入
文件
input:
  file: 
    filename: tests/data/input.txt
    codec: ToEnd
- filename:- string: 要读取的文件路径
- codec:- string: 可能的值:- ToEnd: 一次性读取整个文件。- Lines: 逐行读取文件
标准输入
input:
  stdin: {}
处理器
行
processors:
  - lines: {}
无操作
processors:
  - noop: {}
Python
processors:
  - python: 
      string: true
      code: |
          import json
          msg = json.loads(root)
          msg['Python'] = 'rocks'
          root = json.dumps(msg)
- string:- bool: 消息内容是否作为字符串或字节传递(默认值)
- code:- string: 要执行的Python代码
检查
processors:
  - check: 
      condition: '\"Hello World\" <= `5`'
      processors:
        - python: 
            string: true
            code: |
              import json
              new_string = f\"python: {root}\"
              root = new_string
- condition:- string: 如果处理器正在运行,则评估jmespath表达式
- processors:- list: 如果条件满足,则运行的处理器列表
切换
processors:
  - switch:
      - check: 
          condition: '\"Hello World\" <= `5`'
          processors:
            - python: 
                string: true
                code: |
                  import json
                  new_string = f\"python: {root}\"
                  root = new_string
            - echo: {}
      - echo: {}
- array: 要运行的处理器数组,通常与- check处理器一起使用。一旦某个处理器成功,则不会运行其他处理器
输出
标准输出
output:
  stdout: {}
检查
output:
  check:
    condition: '\"Hello World\" > `5`'
    output:
      stdout: {}
- condition:- string: 如果处理器正在运行,则评估jmespath表达式
- output:- object: 如果检查为真,则使用此输出
切换
output:
  switch:
    - check:
        condition: '\"Hello World\" > `5`'
        output:
          validate: 
            expected: []
- array: 输出数组,通常与- check输出一起使用。
Elasticsearch
output:
  elasticsearch:
    url: http://example.com:9200
    username: user
    password: password
    cloud_id: some_cloud_id
    index: example
- url: 如果不使用Elasticsearch云,指定es集群的URL。例如 http://127.0.0.1:9200
- username: 身份验证用户名
- password: 身份验证密码
- cloud_id: 如果使用Elasticsearch云,指定cloud_id
- index: 插入事件索引
注意:变量可以来自环境,因此当提供密码时,您可以将其设置为 password: "{{ ElasticSearchPassword }}",ElasticSearchPassword将从环境变量中提取并提供给配置。
贡献
欢迎并鼓励贡献!贡献可以采取多种形式。您可以
- 通过 issue 提交功能请求或错误报告。
- 通过 issue 请求改进文档。
- 在 需要反馈的问题 上发表评论。
- 通过 pull requests 贡献代码。
请注意,除非您明确说明,否则您提交给fiddler的任何贡献都应按照Apache License,版本2.0许可,没有任何附加条款或条件。
已知问题
- 在Windows上编译时,Cargo在切换插件上显示警告,称它们将被跳过,但实际上并没有。
- build.rs在Windows上编译时不验证Python是否可用
- Windows GHA上的集成测试失败
依赖项
~21–38MB
~668K SLoC