Introduction to Webhooks
Many online/cloud services provide a feature called ‘Webhooks’. These services can provide a web address that the user can send specifically formatted messages to, and have the service perform an action based on that message. For example, a messaging application may provide a webhook that takes in a message and sends that on to one or more users in the application, or a logging service may provide a webhook that takes in a message and writes it to a log.
EdgeVis Server 7.3 allows these types of webhook for notifications in alarm rules, scheduled events and maintenance alerts. This allows for integration into third party services that provide this feature.
For alarm rules and scheduled events, webhook notifications are fully customisable and should work with most ‘webhook’ services. The message can be templated and customised in the same way as other notifications. Supported parameters are:
HTTP or HTTPS web addresses
HTTPS will protect the messages sent to the webhook by encryption them and is recommended for security.
Optional strict SSL certificate checking.
This option is intended to aid testing prior to deployment. Enabling the check is strongly recommended for live server environments to maintain security.
Content type, this defines the format of the message that the webhook is expecting. Supported content types are:
text/plain
application/json
application/xml
multipart/form-data
For maintenance alerts the format is fixed to application/json and the message has a fixed structure that the receiving service will need to accept.
Example: Sending a Message to Slack
To be able to complete this example, the following elements are required:
An EdgeVis Server deployment on a PC which has direct access to the web, i.e. doesn’t require proxy settings for a web browser to work.
An account with Slack (https://slack.com/get-started), a free one will work for this example.
An encoder connected to EdgeVis Server.
Configuring Slack
Slack requires an App to be added that will receive webhook requests from EdgeVis Server. To do this follow the instructions here: https://api.slack.com/incoming-webhooks
Once complete you should have a URL that starts with:
https://hooks.slack.com/services/....
Keep a note of the URL as it will be used when configuring EdgeVis Server.
Enabling Webhooks within EdgeVis Server
Via the EdgeVis Server web UI, enable Webhooks under Messaging configuration in Advanced server settings.
Creating an alarm rule to fire a web hook
Create a new Alarm Rule on the encoder.
Use the Encoder connected environmental alarm as a trigger.
Add a Notification and select the Send a message to a Webhook option.
Paste in the Slack URL from step 2 above.
Select application/json as the content type.
Enter the following as the message:
{
"text": "Encoder '$ENCODER_NAME$' connected."
}Disconnect the encoder’s power until it shows offline in the server, then re-apply.
Check Slack - there should be a message saying Encoder XXX connected.