Home > Blockchain >  Get data from post request with Rundeck webhook plugin
Get data from post request with Rundeck webhook plugin

Time:10-29

I am trying to get data with rundeck webhook plugin, and for this i am usig curl command:

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):

-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 ?

CodePudding user response:

Following this, you need to use an option called whkpayload in your job, and set it as ${raw} in the webhook configuration.

I made an example:

  1. The job definition in YAML format (with the whkpayload option):
- 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 -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.
  • Related