Create a custom template
Choose the variables each Data Stream log line carries with a custom template, then use it in a stream, in Azion Console or with the Azion API.
You can create a custom template for Data Stream from Azion Console or with the Azion API, and use it in any stream on your account. To change how a Standard HTTP/HTTPS POST endpoint joins the log lines, refer to Customize the HTTP POST payload instead.
A preset template sends every variable it carries, and you cannot change its variables. A custom template sends only the entries of its Data Set, a JSON object whose keys you name and whose values are variables of the stream’s data source. For the format, refer to Custom templates.
The examples build status-analysis, a template with five Applications variables for an analysis of response status. Replace them with the variables you need.
Choose the interface you work in. The prerequisites and the three tasks follow that choice.
Prerequisites
- The Edit Data Stream permission. With View Data Stream only, you can see templates and streams but not create or change them. For details, refer to Stream settings.
- The variables you want in each log line, from the data source of the stream that uses the template. For every variable and the presets that carry it, refer to Data sources and variables.
- To use the template, a stream on your account. To create one, refer to the Data Stream quickstart.
- Access to Azion Console. To sign in, refer to How to access Azion Console.
- An account with fewer than 3,000 workloads. At 3,000 workloads or more, the Console blocks the stream forms, which hold the template drawer, and you manage templates through the API only.
Create the template
The Console creates templates in a drawer of the stream form, not on a page of their own. The template belongs to the account, so every stream can use it.
To create the template with the API, send a POST request with name and data_set. The data_set value is the JSON object as a string, with its quotes escaped:
The API answers 201 with the stored template:
The template exists with custom: true. Keep the value of id, which a stream uses to name the template. A GET request to /v4/workspace/stream/templates lists it beside the presets.
Use the template in a stream
A stream names one template. Selecting the custom template replaces the preset or template the stream used before.
To use the template in a stream with the API, set transform[render_template].attributes.template to the template’s id. Send the whole transform array: the render_template item, and the filter_workloads or sampling item the stream already has. Without either of those two items, the request fails with 32002. Replace <stream-id> with the ID of your stream and <workload-id> with a workload of the stream:
The stored stream names template 1234 in transform[render_template].attributes.template. To use the template in a stream you create, put the same render_template item in the create body. For the full body, refer to Stream settings.
A stream with a workload filter, as in the API example, leaves the other streams running. Saving an active stream that uses sampling deactivates every other stream on the account.
The log lines the stream sends after the change carry only the keys of the data set, such as {"time": …, "host": …, "status": …, "request_uri": …, "upstream_status": …}. To check the delivery, read one log line at the endpoint. Each send is also recorded, with the status code the endpoint returned, in Real-Time Events.
Edit the template
To add or remove a variable on a running stream, change the data set of its custom template. A preset cannot be edited: duplicate it, then use the copy.
To edit the template with the API, send a PATCH request with only the keys you change. This example renames the template. Replace <template-id> with the template’s id:
The API answers 200 with the stored template:
The response carries the changed name and a later last_modified, and data_set keeps its five entries. To change the variables, send data_set with the complete changed JSON object as an escaped string, as in the create. A DELETE request to the same path removes the template and answers 200 with {"state":"executed"}.