Using JSON Variables With Webhooks

Variables of type JSON are useful in conjunction with Webhook triggersClosed A set of one or more indicators that have been correlated based on certain relationships, such as time, metric type, application affected, location, or network device., making it easy to manipulate JSON content carried by a webhook so it can be used in other nodesClosed Individual components that make up a runbook automation, each performing a specific function such as data queries, transformations, logic, integrations, or visualizations. in a runbookClosed An automated workflow that executes a series of steps or tasks in response to a triggered event, such as the detection of anomalous behavior generating an incident, a lifecycle event, or a manually executed runbook.. Handling JSON in a variable also makes it usable as a subflowClosed A reusable automation chunk that performs frequently used functions, such as opening a ticket in an external system, and can be used to implement integrations with third-party systems. input, and you can use one or more subflows as ready-made components for processing JSON in runbooks (such as Riverbed IQ Ops'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: 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 OutputClosed A document containing data sets generated by the execution of a runbook, including output of queries and reports from point products, as well as output of analysis or other runbook nodes. Data Properties; this causes the Transform node to outputClosed A document containing data sets generated by the execution of a runbook, including output of queries and reports from point products, as well as output of analysis or other runbook nodes. 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:

Copy
{
    "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 Ops 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):

Copy
{
    "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: