Technical Tip: How to send CLI script action output to email for a custom automation stitch
Description
This article describes how to create a custom automation stitch that runs a CLI script and sends its output to email when the automation stitch is triggered.
Scope
FortiGate V7.0, v7.2, v7.4, v7.6.
Solution
The trigger condition used for this case is when the FortiGuard web filtering service is unavailable.
- Create a Trigger: From the FortiGate GUI, navigate to the following page:


- Create an Action: Here, create two actions: a. CLI Script, b. Email notification to send the CLI output to email.
From the FortiGate GUI, navigate to:- Create a CLI script:
- Create a CLI script:


- Create an email notification to send CLI script output to email. Add %%results%% in the Body section to send the previous action output to email.

- Create a stitch.
Select the Action and Trigger created previously, and select the email notification action after the CLI script Action.

Once completed, the FortiGate will send the CLI output to the email address in the Email Notification section.
CLI Reference:
config system automation-trigger
edit "Webfilter Unreachable"
set event-type event-log
set logid 20119
next
end
config system automation-action
edit "Webfilter Unreachable_Action"
set action-type cli-script
set script "diagnose debug rating
diagnose sniffer packet any \"host 173.243.141.16 or host 173.243.140.16\" 6 50 l"
set accprofile "super_admin"
next
end
config system automation-action
edit "Email Notification_Webfilter"
set action-type email
set email-to "test@example.com"
set email-subject "%%log%%"
set message "%%results%%"
next
end
config system automation-stitch
edit "Webfilter Un reachable"
set trigger "Webfilter Unreachable"
config actions
edit 1
set action "Webfilter Unreachable_Action"
set required enable
next
edit 2
set action "Email Notification_Webfilter"
set required enable
next
end
next
end
To test an automation stitch:
On the FortiGate GUI, go to Security Fabric -> Automation, 'right-click' on the dedicated automation stitch, select Test Automation Stitch. Testing an automation stitch from the CLI is performed using the command: diagnose automation test <stitch-name> <log>.
Related articles:
Technical Tip: Creating automation stitches
Technical Tip: Automation stitch for conserve mode
