Websocket
Websocket Provider
WebsocketProvider is a class that implements a simple websocket provider.
Inputs
The query
function of WebsocketProvider
takes the following arguments:
socket_url
(str): The websocket URL to query.timeout
(int | None, optional): Connection Timeout. Defaults to None.data
(str | None, optional): Data to send through the websocket. Defaults to None.**kwargs
(optional): Additional optional parameters can be provided as key-value pairs.
See documentation for more information.
Outputs
The query
function of WebsocketProvider
outputs the following format:
{
"connection": true,
"data": "Received data from the websocket"
}
The connection
field indicates whether the websocket connection was successful (true
) or not (false
). The data
field contains the received data from the websocket.
If the connection
field indicates unsuccessful connection (false
) then the object will also include an error
field with details about the failed connection.
Authentication Parameters
The Websocket provider does not require any specific authentication parameters.
Connecting with the Provider
To connect with the Websocket provider and perform queries, follow these steps:
Initialize the provider and provider configuration in your system. Use the query function of the WebsocketProvider to interact with the websocket.
Example usage:
alert:
id: check-websocket-is-up
description: Monitor that this HTTP endpoint is up and running
steps:
- name: websocket-test
provider:
type: websocket
with:
socket_url: "ws://echo.websocket.events"
actions:
- name: trigger-slack-websocket
condition:
- name: assert-condition
type: assert
assert: "{{ steps.websocket-test.results.connection }} == true"
provider:
type: slack
config: "{{ providers.slack-demo }}"
with:
message: "Could not connect to ws://echo.websocket.events using websocket"
on-failure:
provider:
type: slack
config: "{{ providers.slack-demo }}"