Using JSON Variables With Webhooks
Variables of type JSON are useful in conjunction with Webhook triggers, making it easy to manipulate JSON content carried by a webhook so it can be used in other nodes in a runbook. Handling JSON in a variable also makes it usable as a subflow input, and you can use one or more subflows as ready-made components for processing JSON in runbooks (such as Riverbed IQ's built-in Parse Aternity Service Desk Alert subflow, for example). A JSON variable can be used in a number of node types, including HTTP Request and Transform nodes. In any case, your runbook or subflow will need to include a Transform node to convert the JSON to a format usable by other nodes.
Note that a JSON variable, being unstructured, cannot be used in a Decision Branch node.
Example 1
A simple example follows to illustrate the use of a JSON variable and the Transform node.
Add a user-defined variable such as this one, "myjson", shown below. The variable is initialized with a default key and value ("hello: mytest"), and can be used subsequently in the runbook.
This simple runbook illustrates the JSON variable's behavior:
Edit the Transform node's properties. Note the addition of "mystr" in the Output Data Properties; this causes the Transform node to output the string value associated with "mystr". Now, look at the Transform Template. Specify Select Trigger Property from Trigger, and, in the Liquid template, assign "mystr" to the "myjson" runtime variable key "hello".
The complete Liquid template is:
{
"data": [
{
"keys": {
"mystr": "{{variables["runtime.myjson"]["hello"]}}"
},
"data": {}
},
{
"keys": {
"mystr": "Key2"
},
"data": {}
}
],
"info": {
"keys": [
{
"id": "mystr",
"label": "mystr",
"type": "string",
"unit": ""
}
],
"metrics": []
}
}
Now, edit the Table node's properties. This output table will show a single column containing "mystr".
Execute a test run of the runbook; the output will look like so. Note the value "mytest" output for "mystr".
Example 2
A practical example of using a JSON variable with a Webhook trigger uses a subflow to parse data streamed to Riverbed IQ via a webhook. JSON carried by the webhook trigger is passed to the subflow, which will parse it and process it and pass it to the Table and Text visualizations.
The subflow, named test-subflow-json, has these properties:
Note the Input Context for the subjsonVar variable. Content from the Webhook trigger is passed to the subflow as JSON variable input. The subflow passes output to the two visualization nodes, Table and Text.
Edit ing the subflow shows its constituent nodes:
Edit the Subflow Input node's properties like so. Note the "subjsonVar" that is received from the parent runbook:
Edit the Transform node's properties and configure them as shown. Note the addition of "mystr" in the Output Data Properties.
The complete Liquid template comprises the following (this accesses the Hello parameter the same as in the previous example):
{
"data": [
{
"keys": {
"mystr": "{{variables["subflow.subjsonVar"].hello}}"
},
"data": {}
},
{
"keys": {
"mystr": "Key2"
},
"data": {}
}
],
"info": {
"keys": [
{
"id": "mystr",
"label": "mystr",
"type": "string",
"unit": ""
}
],
"metrics": []
}
}
Edit the Set Primitive Variable node. The string variable gets set and is passed from the subflow back to the parent runbook via the Subflow Output node.
Execute a test run of the runbook. Use these test inputs:
The test execution results are: