System Notification
EdgeLake includes a rule engine that can be configured to execute periodic tasks and monitor and alert using services like REST, SMS and STMP (eMail). For example, users can be alerted on CPU, Network, RAM, Disk utilization and data ingestion.
Details on the Rule Engine is available in the section Alerts and Monitoring.
Setting up Webhooks
Webhooks are user-defined HTTP callbacks that enable real-time communication between web applications; they are the simplest and fastest way to send messages into third-party applications as these callbacks use REST (POST) requests for messaging.
Steps
For demonstration purposes, this document uses Slack, however, the same logic can be applied with other webhooks.
- Go to Slack Applications Sections -- may require to login / admin permissions
- Under _Create_, Create an app from manifest
- Select the preferred channel
- Press continue / next till the end
- Select Incoming Webhooks
- Enable Webhooks
- At the bottom, add Webbooks to workspace
- Select which channel in Slack to send messages to
- When done you should see a Webhook (URL) - this will be used as part of your REST request in EdgeLake
Generated URL:
https://hooks.slack.com/services/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
Send Notifications via EdgeLake
EdgeLake allows to send cURL requests the rest command. Since Webhooks are essentially URLs embedded with messages, below is a rest command that sends notifications from EdgeLake into Slack.
- Create webhook URL as a variables
webhook_url = "https://hooks.slack.com/services/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"
- get percentage of CPU used and current timestamp
cpu_percent = get node info cpu_percent date_time = python "datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')"
- Create payload
text_msg = !date_time + " CPU usage: " + !cpu_percent payload = json {"text": !text_msg}
- Publish information to Slack via _REST_
<rest post where url = !webhook_url and body = !payload and headers = "{'Content-Type': 'application/json'}">
Note: Google Hangouts, Discord and Microsoft Teams usecontent
for the payload key as opposed totext
.
Once sent, an output would appear in the proper Slack channel