简体   繁体   English

使用 Rundeck webhook 插件从 post 请求中获取数据

[英]Get data from post request with Rundeck webhook plugin

I am trying to get data with rundeck webhook plugin, and for this i am usig curl command:我正在尝试使用 rundeck webhook 插件获取数据,为此我使用了 curl 命令:

curl -X POST -d '{"name":"John", "age":30, "car":null}' https://rundeck_server/api/12/webhook/QSxTDYd08dcYxKh1R5YJNOPQvmSJH2Z8#Netbox_Job

In rundeck webhook plugin options i add those 2 variables, 'whkpayload' to get all the json data and 'name' to get the name only (must return John in this example):在 rundeck webhook 插件选项中,我添加了这两个变量,'whkpayload' 用于获取所有 json 数据,'name' 仅获取名称(在此示例中必须返回 John):

-whkpayload ${raw} -name ${data.name}

And finally i show them with those lines:最后我用这些台词向他们展示:

echo @option.whkpayload@
echo @option.name@

I get an empty result and i can't figure out why.我得到一个空结果,我不知道为什么。 Any one may help me please ?任何人都可以帮助我吗?

Following this , you need to use an option called whkpayload in your job, and set it as ${raw} in the webhook configuration.之后,您需要在作业中使用名为whkpayload的选项,并在 webhook 配置中将其设置为${raw}

I made an example:我举了一个例子:

  1. The job definition in YAML format (with the whkpayload option): YAML 格式的作业定义(使用whkpayload选项):
- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 0fcfca07-02f6-4583-a3eb-0002276bdf2d
  loglevel: INFO
  name: HelloWorld
  nodeFilterEditable: false
  options:
  - name: age
  - name: car
  - name: name
  - name: whkpayload
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: command step
      exec: echo "name ${option.name} - age ${option.age} - car ${option.car} - payload
        ${option.whkpayload}"
    - description: inline-script step
      fileExtension: .sh
      interpreterArgsQuoted: false
      script: echo "name @option.name@ - age @option.age@ - car @option.car@ - payload
        @option.whkpayload@"
      scriptInterpreter: /bin/bash
    keepgoing: false
    strategy: node-first
  uuid: 0fcfca07-02f6-4583-a3eb-0002276bdf2d
  1. The webhook configuration .网络钩子配置

  2. The webhook calling from cURL:来自 cURL 的 webhook 调用:

curl -H "Content-Type: application/json" -X POST -d '{"field1":"John", "field2":30, "field3":"chevy"}' http://localhost:4440/api/40/webhook/0vBZjWWrnXWvqENEdxkn0JRvjn5R63J0#MyWebhook
  1. The result .结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM