Teams Webhook
Teams Webhook
简介
Microsoft Teams 通知动作可以通过 Webhook 将自动化执行的结果信息发送到指定的 Teams 频道。
需要 FortiGate 可以访问 Internet。
网络需求
当 FortiGate 的配置发生变更时,向 Teams 对应频道发送通知消息。
配置步骤
获取 Teams Webhook 链接
打开 Teams,进入团队页面,右键点击需要接收消息的频道,选择“管理频道”,在“连接器”中点击“编辑”按钮。

在弹出的连接器列表中选择“Incoming Webhook”,点击该连接器右侧的“添加”按钮。

在弹出的连接器详情页面中,继续点击“添加”按钮。

随后会自动弹出连接器配置界面,配置连接器名称,可自行选择性上传发送消息时显示的图标,点击“创建”按钮。

复制生成的 Webhook URL 并妥善保存,点击“完成”按钮,完成“Incoming Webhook”连接器的配置。


FortiGate 自动化配置
- 进入 FortiGate 的“Security Fabric → 自动化 → 工作流”页面,点击“新建”按钮。

配置工作流的名称,点击“添加触发器”按钮,在右侧的“选择条目”中点击“新建”按钮。

在右侧弹出的窗口中,找到“系统”分类,点击“配置改变”选项。

配置触发器(Trigger)的名称,点击确认下发配置。

config system automation-trigger edit "Config_change" set event-type config-change next end在选择条目中选择上步创建的触发器(Trigger),点击应用按钮。

点击“添加动作”按钮,在右侧弹出的“选择条目”中点击“新建”按钮。

在右侧弹出的窗口中,找到“通知”分类,点击“Microsoft Teams 通知”选项。

配置动作(Action)的名称,将从 Teams 连接器中复制出的 Webhook URL 粘贴进“URL”选项(不包含
https字段),消息格式这里以“Text”为例,消息内容为配置变更的日志信息,点击确认下发配置。
在选择条目中选择上步创建的动作(Action),点击应用按钮。

config system automation-action edit "Teams_Webhook" set action-type microsoft-teams-notification set uri "fortinet.webhook.office.com/webhookb2/7e2f667a-91a7-4e1f-8153-25757d7d7e4a@2c36c478-3d00-452f-8535-48396f5f01f0/IncomingWebhook/c20149904d60451fb6f167ba2cd6b129/ab9845cf-2876-49e7-b558-f3824db2f88a" next end检查无误后,点击确认下发配置。

config system automation-stitch edit "Teams_webhook_cfg_change" set trigger "Config_change" config actions edit 1 set action "Teams_Webhook" set required enable next end next end
配置验证
修改 FortiGate 的配置并退出登录管理员账户。
在 Teams 的对应频道中可以看到 FortiGate 通过 Webhook 自动发送了配置变更的消息,消息内容为修改配置产生的系统事件日志。

查看自动化触发的系统事件日志。

date=2024-03-13 time=17:11:20 eventtime=1710321079705445859 tz="+0800" logid="0100046600" type="event" subtype="system" level="notice" vd="root" logdesc="Automation stitch triggered" stitch="Teams_webhook_cfg_change" trigger="Config_change" stitchaction="Teams_Webhook" from="log" msg="stitch:Teams_webhook_cfg_change is triggered."查看自动化触发的 Debug 信息。
FortiGate # diagnose debug application autod -1 FortiGate # diagnose debug enable auto_generate_generic_curl_request()-441: Generating generic automation CURL request for action (Teams_Webhook). auto_generate_generic_curl_request()-493: Generic automation CURL request POST data for action (Teams_Webhook): { "text": "date=2024-03-13 time=17:11:19 devid=\"FG101FTK20007637\" devname=\"FW1_FGT101F\" eventtime=1710321079704881719 tz=\"+0800\" logid=\"0100032102\" type=\"event\" subtype=\"system\" level=\"alert\" vd=\"root\" logdesc=\"Configuration changed\" user=\"admin\" ui=\"https(192.168.100.178)\" msg=\"Configuration is changed in the admin session\"" } auto_generate_generic_curl_request()-548: Generic automation CURL request Host header: fortinet.webhook.office.com auto_generate_generic_curl_request()-551: Adding 0 user defined headers pid:283-__handle_msg()-414: Subscriber:4 received package. pubid:2 pkgid:65509 pkg_index:127 pid:283-__handle_pkg_logs()-356: Subscriber:4 processing package size:1215 logs:1 pickup:1 auto_event_pub_handle_log()-331: publish 46600 to subscr-node pid:283-__subscr_close_cur_pkg()-140: close package size:1215 logs:1 auto_generic_curl_request_close()-632: Generic CURL request response body from Teams_Webhook(https://fortinet.webhook.office.com/webhookb2/7e2f667a-91a7-4e1f-8153-25757d7d7e4a@2c36c478-3d00-452f-8535-48396f5f01f0/IncomingWebhook/c20149904d60451fb6f167ba2cd6b129/ab9845cf-2876-49e7-b558-f3824db2f88a): 1查看该自动化工作流的状态统计信息。
FortiGate # diagnose test application autod 3 alert mail log count: 0 stitch: Teams_webhook_cfg_change local hit: 1 relayed to: 0 relayed from: 0 last trigger:Wed Mar 13 17:11:19 2024 last relay: actions: Teams_Webhook: done: 1 relayed to: 0 relayed from: 0 last trigger:Wed Mar 13 17:11:19 2024 last relay: logid to stitch mapping: id:32099 local hit: 0 relayed hits: 0 Teams_webhook_cfg_change id:32102 local hit: 1 relayed hits: 0 Teams_webhook_cfg_change log category to stitch mapping: