工作流
工作流
自动化简介
自动化(Automation)功能能够根据特定的触发条件自动执行相应的动作,可以让客户更快的发现设备发生的事件,以及更快地处理事件。它可以监控来自 Security Fabric 中任何成员的事件,然后设置对应的执行动作。
自动化设置可以在 Security Fabric 成员中同步,或只用于 Security Fabric 中的一个单独 FortiGate。当 FortiGate 加入了 Security Fabric,自动化只能在 Security Fabric 的 Root FortiGate 上创建。
当然,如果一台 FortiGate 未加入 Security Fabric,也可以使用自动化功能。
FortiGate 上的每个自动化配置包含 3 个部分:
- 触发器(Trigger):用于触发自动化流程的条件,可以是某个系统事件日志、UTM 日志、计划时间等。系统会内置一些常用的 Trigger。
- 动作(Action):触发器触发后执行的动作,可以是执行 CLI 脚本、发送邮件、重启设备等。系统会内置一些常用的 Action。
- 串联器(Stitch):将触发器(Trigger)和动作(Action)关联起来,在 Stitch 中,一个 Stitch 可以包含 1 个 Trigger 和多个 Action,可以单独设置每个 Action 和 Trigger 的执行延迟时间。系统会内置一些常用的 Stitch。Stitch 有两种执行 Action 的模式:
- 顺序:如果有多个动作(Action),触发器(Trigger)触发后,按照动作(Action)的顺序依次执行。
- 并行:如果有多个动作(Action),触发器(Trigger)触发后,同时执行所有动作(Action)。
工作流(Workflow)就是每个自动化配置的统称。
单动作配置示例
网络需求
当 IPSec 由于 DPD 超时中断,等待 5s 后,向管理员的邮箱发送通知邮件。
配置步骤
首先配置告警邮件发送的配置(参考 日志 → 邮件告警章节,也可使用默认配置)。
进入 FortiGate 的“Security Fabric → 自动化 → 工作流”页面,点击新建按钮,新建一个工作流(此页也有一些内置的工作流,可根据需求自行使用或禁用)。

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

- 操作执行 - 顺序:如果有多个动作(Action),触发器(Trigger)触发后,按照动作(Action)的顺序依次执行。
- 操作执行 - 并行:如果有多个动作(Action),触发器(Trigger)触发后,同时执行所有动作(Action)。
在右侧弹出的窗口中,找到“其他条件”分类,点击“FortiOS 事件日志”选项。

配置触发器(Trigger)的名称,事件选择“IPSec DPD failed”(可根据需求在字段过滤中配置日志中要求包含的字段),点击确认下发配置。

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

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

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

配置动作(Action)的名称,以及邮件通知的收件人,邮件内容为 DPD 失败的日志内容,点击确认下发配置。

- 最小间隔:如果 Trigger 频繁触发了,Action 执行的最小间隔。
- 源:指定邮件通知的发件人,默认为
DoNotReply@notification.fortinet.net。 - 目的:配置邮箱的收件人,可以配置多个收件人。
- Body:邮件内容。
- 更换信息:可以更换为自定义内容和格式。
config system automation-action edit "Email_DPD_Failure" set action-type email set email-to "bbai@fortinet.com" set email-subject "DPD_Failure_Notice" next end在选择条目中选择上步创建的动作(Action),点击应用按钮。

可以点击“Add delay”添加触发器(Trigger)触发后执行动作(Action)间的延迟,这里以 5s 为例。

检查无误后,点击确认下发配置。

config system automation-stitch edit "DPD_Failure" set trigger "DPD_Failure" config actions edit 1 set action "Email_DPD_Failure" set delay 5 set required enable next end next end
配置验证
触发 FortiGate 上的 DPD 超时日志。

date=2024-03-11 time=15:32:47 eventtime=1710142366681265100 tz="+0800" logid="0101037136" type="event" subtype="vpn" level="error" vd="root" logdesc="IPsec DPD failed" msg="IPsec DPD failure" action="dpd" remip=123.112.245.194 locip=172.22.6.128 remport=4500 locport=4500 outintf="wan1" cookies="8ceb76158cfa95bd/108585f6157d655b" user="192.168.123.175" group="N/A" useralt="N/A" xauthuser="N/A" xauthgroup="N/A" assignip=N/A vpntunnel="to_Home_WAN1" status="dpd_failure" advpnsc=05s 后,触发自动化程序,相关自动化日志如下。

date=2024-03-11 time=15:32:48 eventtime=1710142367401695780 tz="+0800" logid="0100046600" type="event" subtype="system" level="notice" vd="root" logdesc="Automation stitch triggered" stitch="DPD_Failure" trigger="DPD_Failure"收件人邮箱收到了告警邮件,邮件内容为 DPD Failed 的日志内容,发件人为默认的 DoNotReply@notification.fortinet.net。

对应的自动化触发 Debug 信息。
FortiGate # diagnose debug application autod -1 FortiGate # diagnose debug enable ...... __action_email_hdl()-181: email action (Email_DPD_Failure) is called. from: to:bbai@fortinet.com; subject:DPD_Failure_Notice ......发送邮件的 Debug 信息如下。
FortiGate # diagnose debug application alertmail -1 FortiGate # diagnose debug enable Arrived msg(type 9, 415 bytes):bbai@fortinet.com; DPD_Failure_Notice date=2024-03-11 time=16:11:15 devid="FGT61FTK22063594" devname="FortiGate" eventtime=1710144674391662240 tz="+0800" logid="0100032014" type="event" subtype="system" level="warning" vd="root" logdesc="Support license expiring" ui="automation" action="test" msg="Automation Stitch Test: FortiCare license will expire in 1 day(s)" stitch="License Expired Notification" mail_info: from:notification.fortinet.net user:DoNotReply@notification.fortinet.net mail_info: reverse path:DoNotReply@notification.fortinet.net user name:DoNotReply to[0]:bbai@fortinet.com <==_init_mail_info create session resolve notification.fortinet.net to 1 IP ==> send mail connecting to 208.91.114.151 port 465 send mail 0x9988160 session 0x99863c0 session_io_event: creating ssl structure for session 0x99863c0 create_ssl: 0x7f9ff88000 sessionn 0x99863c0, SSL connected session: 0x99863c0, rsp_state: greeting, code: 220 session: 0x99863c0, rsp_state: ehlo, code: 250 session: 0x99863c0, rsp_state: mail, code: 250 session: 0x99863c0, rsp_state: rcpt, code: 250 session: 0x99863c0, rsp_state: data, code: 354 === send: date=2024-03-11 time=16:11:15 devid="FGT61FTK22063594" devname="FortiGate" eventtime=1710144674391662240 tz="+0800" logid="0100032014" type="event" subtype="system" level="warning" vd="root" logdesc="Support license expiring" ui="automation" action="test" msg="Automation Stitch Test: FortiCare license will expire in 1 day(s)" stitch="License Expired Notification" session: 0x99863c0, rsp_state: data2, code: 250 session: 0x99863c0, rsp_state: quit, code: 221 session finined _session_on_destroy <== send mail success, m = 0x9988160 s = 0x99863c0
多动作顺序执行示例
网络需求
当 IPSec 由于 DPD 超时中断时,等待 5s 后向管理员的邮箱发送通知邮件,邮件发送成功后,再通过 Webhook 向 Teams 发送消息。
配置步骤
在以上配置的基础上,使该自动化工作流以顺序模式执行多个动作。新建一个动作(Action),这里以 Teams Webhook 为例。

配置下发后,查看自动化工作流对应的 CLI 配置,可以看到 action 部分多了
set required enable字段,该字段表示必须前一个 Action 执行完毕后,才会执行本 Action,这也就实现了“顺序”的效果。config system automation-stitch edit "DPD_Failure" set trigger "DPD_Failure" config actions edit 1 set action "Email_DPD_Failure" set delay 5 set required enable next edit 2 set action "Teams_Webhook" set required enable next end next end将该自动化工作流改为并行模式,查看 CLI 配置,可以看到
set required enable配置消失。只要触发器被触发,所有的动作会立即执行。
config system automation-stitch edit "DPD_Failure" set trigger "DPD_Failure" config actions edit 1 set action "Email_DPD_Failure" next edit 2 set action "Teams_Webhook" next end next end
手动测试自动化
部分自动化程序可以手动触发,作为配置完成后的测试手段。如下所示,在工作流页面中,右键点击某个自动化工作流,点击“测试自动化工作流程”按钮。

此动作可以不需要配置的触发器真实触发,而直接触发执行动作。通过 CLI
diagnose automation test <Stitch_name>也可以执行该动作。FortiGate # diagnose automation test "License Expired Notification" automation test is done. stitch:License Expired Notification
查看自动化状态信息
GUI
在工作流页面可以直接查看每个工作流的触发次数和最后触发时间。

CLI
通过
diagnose test application autod 2可以看到所有的自动化工作流的配置与匹配计数。FortiGate # diagnose test application autod 2 csf: disabled root: no sync connection: connecting version:0 sync time: total stitches activated: 4 stitch: DPD_Failure destinations: all trigger: DPD_Failure type:logid logids: 0: 37136 local hit: 6 relayed to: 0 relayed from: 0 actions: Email_DPD_Failure type:email interval:0 delay:5 required:yes subject: DPD_Failure_Notice body: %%log%% sender: mailto:bbai@fortinet.com; ......查看自动化工作流的触发次数、最后触发时间、被自动化引用的日志 ID 等统计。
FortiGate # diagnose test application autod 3 alert mail log count: 0 stitch: DPD_Failure local hit: 7 relayed to: 0 relayed from: 0 last trigger:Mon Mar 11 16:00:45 2024 last relay: actions: Email_DPD_Failure: done: 6 relayed to: 0 relayed from: 0 last trigger:Mon Mar 11 16:00:45 2024 last relay: ...... logid to stitch mapping: id:20101 local hit: 0 relayed hits: 0 License Expired Notification id:20102 local hit: 0 relayed hits: 0 License Expired Notification id:20103 local hit: 0 relayed hits: 0 License Expired Notification id:20104 local hit: 0 relayed hits: 0 License Expired Notification id:22902 local hit: 0 relayed hits: 0 FortiAnalyzer Connection Down id:32014 local hit: 2 relayed hits: 0 License Expired Notification id:32045 local hit: 0 relayed hits: 0 License Expired Notification id:32049 local hit: 0 relayed hits: 0 License Expired Notification id:37136 local hit: 7 relayed hits: 0 DPD_Failure id:52000 local hit: 47 relayed hits: 0 Security Rating Notification log category to stitch mapping:查看正在运行的自动化工作流状态,以及已运行的自动化工作流的执行统计。
FortiGate # diagnose test application autod 5 runned stitches: total:56 done:55 drop:0 running stitches: 1 1. stitch:DPD_Failure id:55 running time:Mon Mar 11 16:00:45 2024 log relayed:0 sn:FGT61FTK22063594 logid:37136 log(531):date=2024-03-11 time=16:00:45 devid="FGT61FTK22063594" devname="FortiGate" eventtime=1710144045841282220 tz="+0800" logid="0101037136" type="event" subtype="vpn" level="error" vd="root" logdesc="IPsec DPD failed" msg="IPsec DPD failure" action="dpd" remip=123.112.245.97 locip=172.22.6.128 remport=4500 locport=4500 outintf="wan1" cookies="aa470ef86bf5705d/9d33378890990748" user="192.168.123.175" group="N/A" useralt="N/A" xauthuser="N/A" xauthgroup="N/A" assignip=N/A vpntunnel="to_Home_WAN1" status="dpd_failure" advpnsc=0 1. action:Email_DPD_Failure status:ready id:0 running time:Mon Mar 11 16:09:05 2024 delay:500 required:1