Creating a Webhook sink

You can configure the webhook sink to perform an HTTP action per message (default) or code created that controls the frequency (for instance, every N messages). When developing webhook sinks, it is recommended to check your webhook before pointing at your true destination.

  1. Go to your cluster in Cloudera Manager.
  2. Click on SQL Stream Builder from the list of Services.
  3. Click on SQLStreamBuilder Console.
    The Streaming SQL Console opens up in a new window.
  4. Select Console from the main menu.
  5. Select the Virtual Tables tab.
  6. Select the Virtual Table Sink sub-tab.
  7. Select Add Sink > Webhook.
    The Webhook Sink window appears.
  8. Provide a name to the Virtual Table.
  9. Enter an HTTP EndPoint. The endpoint must start with http:// or https://.
  10. Add a Description about the webhook sink.
  11. Select POST or PUT in the HTTP Method select box.
  12. Choose to Disable SSL Validation, if needed.
  13. Enable Request Template, if needed.
    1. If you selected Yes, then the template defined in the Request Template tab is used for output.
      This is useful if the service you are posting requires a particular data output format. The data format must be valid JSON, and use "${columnname}" to represent fields. For example, a template for use with Pagerduty looks like this:
      {
         "incident":{
            "type":"incident",
            "title":"${icao} is too high!",
              "body":{
         "type":"incident_body",
               "details":"Airplane with id ${icao} has reached an altitude of ${altitude} meters."
       }
          }
      }
      
  14. In the Code editor, you can specify a code block that controls how the webhook outputs the data.
    For a webhook that is called for each message the following code would be used:
    // Boolean function that takes entire row from query as Json Object
    function onCondition(rowAsJson)
    {return true;   // return false here for no-op, or plug in custom
            logic}
    onCondition($p0)
  15. Add HTTP headers via the HTTP Headers tab, if needed.
    Headers are name:value header elements. For instance, Content-Type:application/json, etc.
  16. Click Save Changes.
The Webhook Virtual Table Sink is ready for queries to be run. You can add the created sink on the Compose tab by selecting its name from the list of sinks.