1. Introduction
This article will explain how to integrate DataFlux Func with Slack on the observation cloud to push alarm information to Slack in a timely manner.
1.1 About Slack
Slack is a popular collaboration tool that provides a centralized platform for team members to communicate and collaborate through instant messaging, file sharing, search, and integration with third-party services. Here are some of the key features of Slack:
- Instant messaging: Slack allows users to send one-to-one or group messages, with support for text, pictures, video and audio messages.
- Channels: Users can create different channels to organize discussions, such as by project, topic, or department.
- Direct messages: Users can communicate privately with other members of the team.
- File sharing: Slack allows users to share files, including documents, pictures and videos, within a conversation.
- Search function: The powerful search function can help users quickly find past conversations or files.
- Integrations: Slack can integrate with many third-party services, such as Google Drive, Trello, GitHub, and more, making workflows more seamless.
- Automation: By using Slack's APIs and bots, users can create automated workflows, such as automating messages or performing tasks.
- Security: Slack offers a variety of security measures, including data encryption, two-factor authentication, and more.
- Mobile and desktop apps: Slack offers mobile apps for iOS and Android, as well as desktop apps for Windows, macOS and Linux.
Overall, Slack aims to improve team communication, reduce email usage and help team members collaborate better. It is suitable for teams of all sizes, from small startups to large enterprises.
1.2 观测云和 Slack
The Observation Cloud can configure integrated alerts with Slack to automatically send notifications to Slack when there is an issue with an application or service. Enables teams to respond and resolve issues quickly.
2. Instructions for integration steps
2.1 Slack's Configuration Instructions
2.1.1 Create a notification channel
2.1.2 为渠道添加 Incoming WebHook 自定义应用
2.1.3 Incoming WebHook 的配置
In the configuration of the Incoming webhook, review the URL and example of the invoking webhook
After the creation is complete, the following information is displayed:
2.2 DataFlux Func Configuration Description
Integrate with DataFlux Func and Slack's notification channels. The instructions are as follows:
2.2.1 The relevant code is as follows
import requests
import json
events_url = "https://hooks.slack.com/services/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"
@DFF.API('Slack_Webhook_Proxy_API')
def create_slack_message(**event):
try:
if event:
checker_name = event.get("df_monitor_checker_name")
checker_value = event.get("df_monitor_checker_value")
severity = event.get("df_status")
label = event.get("df_label")
event_link = event.get("df_event_link")
workspace_name = event.get("df_workspace_name")
ts = event.get("timestamp")
headers = {"Content-Type": "application/json"}
severity_icons = {
"critical": ":fire:",
"error": ":no_entry:",
"warning": ":warning:",
"ok": ":large_green_circle:"
}
color_list = {
"critical": "#ff0000",
"error": "#eb9b34",
"warning": "#e5eb34",
"ok": "#03fc14"
}
icon = severity_icons.get(severity)
payload_colors = color_list.get(severity)
severity = severity.upper()
payload = {
"attachments": [{
"color": f"{payload_colors}",
"author_name": f"{icon} {severity}",
"title": f"CF Alerts | {workspace_name} workspace",
"title_link": f"{event_link}",
"text": f"The {checker_name} monitor has triggered a {severity} alert (value: *{checker_value}*) in the {workspace_name} workspace.",
"footer": "Time",
"ts": f"{ts}"
}]
}
print(payload)
## Post to Webhook
res = requests.post(events_url, headers=headers, data=json.dumps(payload))
print(res.status_code)
except Exception as e:
# 捕获HTTP错误
print(f"错误发生: {e}")
Configure the synchronization API in DataFlux Func
See the call address and call example of the API through the example:
2.3 Configuration on the observation cloud
2.3.1 Create a notification object for a webhook
The address of the webhook is the API call address in DataFlux Func.
2.3.2 Create an alarm policy
2.3.3 Monitor Settings
In Alert policies, select the Slack policy you created earlier.
3. Effect display
When the alarm threshold is reached, we will receive the following alerts in Slack:
In addition, after clicking the following link, you will be automatically redirected to the event of the observed cloud to view the alarm details.
At this point, we have preliminarily completed the integration configuration of the observation cloud through DataFlux Func and Slack.