自动抓包
自动抓包
网络需求
某客户遇到 HA 中的成员 FortiGate 由于 HA 心跳包丢失而成为双主状态,影响到正常业务。但出现该问题后一段时间会自动恢复,且出现的时间随机。
需要在出现此问题时在两台 FortiGate 的心跳接口抓取 HA 心跳报文,以进一步定位问题,但由于该问题出现的时间不固定,不好掌握抓包的时机。
通过自动化功能,可以实现在 FortiGate HA 心跳包丢失时,自动抓取心跳接口的报文,并发送至指定邮箱。
配置步骤
自动化触发器
配置自动化触发器为事件日志类型,事件日志类型为“Heartbeat packet lost”,logid 为 37910。
config system automation-trigger
edit "HA_HB_Lost"
set event-type event-log
set logid 37910
next
end自动化动作
配置第 1 个自动化动作,在 HA 心跳接口抓取 HA 心跳报文,该报文为二层报文,ether protocol 默认为 0x8890,抓取个数为 100 个。为了防止频繁触发抓包进程导致的内存占用问题,配置最小触发间隔为 120s。
config system automation-action edit "Sniffer_HA_HB_Start" set action-type cli-script set minimum-interval 120 set script "diagnose sniffer packet port8 \'ether proto 0x8890\' 6 100 l" set accprofile "super_admin" next end配置第 2 个自动化动作,将抓包结果发送到指定邮箱。
config system automation-action edit "Email_HA_HB_Lost_Sniffer_Result" set action-type email set email-to "bbai@fortinet.com" set email-subject "HA_HB_Lost_Sniffer_Result" set message "%%results%%" next end
自动化工作流
配置自动化工作流,触发器引用已创建的“Heartbeat packet lost”类型的事件日志触发器,触发器触发后,动作为开始在 HA 心跳接口抓包,并发送抓包结果。
config system automation-stitch
edit "HA_HB_Lost_Sniffer"
set trigger "HA_HB_Lost"
config actions
edit 1
set action "Sniffer_HA_HB_Start"
set required enable
next
edit 2
set action "Email_HA_HB_Lost_Sniffer_Result"
set required enable
next
end
next
end- 触发器引用已创建的“Heartbeat packet lost”类型的事件日志触发器。
- 第 1 个动作引用开始抓取 HA 心跳报文的动作,抓取到 100 个包后会自动停止。
- 第 2 个动作引用发送邮件的动作,发送抓包结果。
- 第 3 个动作引用停止抓包的动作。
配置验证
触发 HA 中两台 FortiGate 的心跳报文检测超时,并产生“Heartbeat packet lost”的 HA 系统事件日志。
date=2024-04-02 time=17:02:22 eventtime=1712048543265466260 tz="+0800" logid="0108037910" type="event" subtype="ha" level="critical" vd="root" logdesc="Heartbeat packet lost" msg="Heartbeat packet lost" ha_role="primary" devintfname="dmz"随后触发了自动化流程。
date=2024-04-02 time=17:02:22 eventtime=1712048543265705880 tz="+0800" logid="0100046600" type="event" subtype="system" level="notice" vd="root" logdesc="Automation stitch triggered" stitch="HA_HB_Lost_Sniffer" trigger="HA_HB_Lost" stitchaction="Sniffer_HA_HB_Start,Sniffer_HA_HB_Stop,Email_HA_HB_Lost_Sniffer_Result" from="log" msg="stitch:HA_HB_Lost_Sniffer is triggered."配置的收件邮箱收到了包含抓包结果的邮件。
重要
当 HA 心跳接口只有一对时,HA 发生心跳丢失会造成 HA 成员成为双主状态,此时 HA 的 2 个成员设备由于都触发了“Heartbeat packet lost”类型的事件日志,均会执行自动化流程,并发送抓包结果邮件到指定邮箱。

FortiGate 上的 autod 进程对应的自动化执行 Debug 信息。
FW1 # diagnose debug application autod -1 FW1 # diagnose debug enable pid:2044-__handle_pkg_logs()-356: Subscriber:4 processing package size:459 logs:1 pickup:1 pid:2044-__subscr_close_cur_pkg()-140: close package size:459 logs:1 __action_cli_script_open()-186: cli script action:Sniffer_HA_HB_Start is called. svc ctx:0x1072dd90 accprof:super_admin script: diagnose sniffer packet port8 'ether proto 0x8890' 6 100 l ...... __cli_script_close()-121: cli script: autod.0 output: ########## script name: autod.0 ########## ========== #1, 2024-04-03 16:01:29 ========== FW1 $ diagnose sniffer packet port8 'ether proto 0x8890' 6 100 l Using Original Sniffing Mode interfaces=[port8] filters=[ether proto 0x8890] pcap_lookupnet: port8: no IPv4 address assigned 2024-04-03 16:01:30.743701 port8 -- Ether type 0x8890 printer hasn't been added to sniffer. 0x0000 ffff ffff ffff 5000 0001 0007 8890 5201 ......P.......R. ...... __action_email_hdl()-181: email action (Email_HA_HB_Lost_Sniffer_Result) is called. from: to:bbai@fortinet.com; subject:HA_HB_Lost_Sniffer_Result