HTTP Output
The HTTP output plugin is used to make HTTP requests. It can be configured to to send information when a query finds a match.
This can be particularly useful to integrate with remote APIs such as PagerDuty, Slack, etc.
Parameters
content_type: OPTIONAL. The valid options are ‘application/json’ or ‘text/plain’, which is the default.
delimiter: OPTIONAL. If using content_type ‘text/plain’, the delimiter parameter can be used to specify how to separate fields. If not entered, the default value is ‘,’ making the output message comma-separated.
method: OPTIONAL. The valid options are ‘GET’,’POST’, ‘POST’. The default is ‘POST’.
parent_key: OPTIONAL. If using content_type ‘application/json’, then field values will be automatically formatted in json using the field name as keys and the field value as values. In case you need all these fields nested under a parent key, then you specify the parent_key.
proxy: OPTIONAL. Can be the address or ip address of the proxy host, or ‘none’, which forces no proxy in case the operating system has a proxy configuration.
queue_capacity: OPTIONAL. If a remote http server is not responding, or taking too long to respond, request could begin to pile up. RioDB is used in a variety of high-performance use cases, so there could be a use-case where you would pile up a queue of millions of requests waiting to be sent. The queue_capacity sets a limit to prevent JVM running out of memory.
template_file: OPTIONAL. You can specify the directory path of a file on your system to be used as an output template. The file can have variables like ${field_name} to be dynamically substituted by a field value from the query.
timeout: OPTIONAL. How long to wait for a response from the remote server before giving up on the request. The unit is seconds, and the default value is 10.
url: REQUIRED. The http or https address to send the request. It must start with ‘http://‘ or ‘https://‘. There is not parameter for port number. So you want to include the port number as part of the URL.
You can also pass a query field as a dynamic URL, such as: ${field1}
workers: OPTIONAL. How many CPU threads to handle making HTTP requests. The default is 1, and usually that’s all you need.
Syntax
OUTPUT http (
content_type <string>
delimiter <single character>
method <string>
parent_key <string>
proxy <string>
queue_capacity <integer>
template_file <string>
timeout <integer>
url <string>
workers <integer>
Example
A simple output posting JSON payload to myremoteapi.com:443 for every message received by STREAM mystream:
SELECT session_id
FROM mystream
OUTPUT http (
content_type 'application/json'
method 'POST'
proxy '123.123.123.123'
timeout 60
url 'https://myremoteapi.com:443/dosomething?session=${mystream.session_id}'
Using the template file parameter, suppose I create a template in /mydrive/mytemplate.txt as
{
"source": "riodb-01",
"action": "session_detected",
"session_id": "${mystream.session_id}"
}
Now we can write the query that utilizes that template for string substitution:
SELECT session_id
FROM mystream
OUTPUT http (
content_type 'application/json'
method 'POST'
proxy '123.123.123.123'
timeout 60
url 'https://myremoteapi.com:443/dosomething'
template_file '/mydrive/mytemplate.txt'
The output message will be the text in the template file, but substituting “${mystream.session_id}” with the value from “SELECT session_id”.