FortiGate
FortiGate Next Generation Firewall utilizes purpose-built security processors and threat intelligence security services from FortiGuard labs to deliver top-rated protection and high performance, including encrypted traffic.
Matt_B
Staff & Editor
Staff & Editor
Article Id 388144
Description This article demonstrates using Switch Controller custom commands and Automation stitches to retrieve information from managed FortiSwitches without needing to log in to SSH locally on the FortiSwitch.
Scope FortiGate managing FortiSwitch.
Solution

FortiGate supports sending any FortiSwitch command to a managed FortiSwitch using the 'execute switch-controller custom-command <command> [<target-switch>]' command. See this document: Executing custom FortiSwitch scripts.


See FortiSwitchOS CLI Reference for a list of FortiSwitch commands. Some commands are not available or applicable to all FortiSwitch platforms. See these documents: FortiSwitchOS Feature Matrix and FortiSwitch Secure Access Data Sheet.


Compound Example:

If needed, multiple FortiSwitch commands can be executed in the same FortiOS custom-command by separating with '%0a'.

 

config switch-controller custom-command

    edit "fan-temp-power"

        set command "diagnose sys fan status 0%a diagnose sys pcb temp 0%a diagnose sys psu status"

    next

end

 

execute switch-controller custom-command "fan-temp-power" [<target-switch>]

 

Note that compound custom-commands will exit the first time a command returns an error on FortiSwitch.

 

Individual:

It is sometimes preferable to configure individual custom commands, especially since some commands are not supported on all FortiSwitch models or FortiSwitch configurations.

 

config switch-controller custom-command

    edit "diagnose sys fan status"

        set command "diagnose sys fan status"

    next

    edit "diagnose sys pcb temp"

        set command "diagnose sys pcb temp"

    next

    edit "diagnose sys psu status"

        set command "diagnose sys psu status"

    next

end

 

execute switch-controller custom-command "diagnose sys fan status" [<target-switch>]
execute switch-controller custom-command "diagnose sys pcb temp" [<target-switch>]
execute switch-controller custom-command "diagnose sys psu status" [<target-switch>]

 

This process can be automated if needed to execute commands or poll information periodically using this document: Creating automation stitches.

 

config system automation-trigger

    edit "Hourly XX:13"

        set trigger-type scheduled
        set trigger-frequency hourly
        set trigger-minute 13

    next

end

 

config system automation-action

    edit "FortiSwitch fan temp psu script"

        set action-type cli-script
        set script "execute switch-controller custom-command \"diagnose sys fan status\"
        execute switch-controller custom-command \"diagnose sys pcb temp\"
        execute switch-controller custom-command \"diagnose sys psu status\""
        set accprofile <switch administrator>

    next

    edit "Send switch script results"

        set action-type email
        set email-to <email>
        set email-subject "Results from FortiSwitch script"
        set message "%%results%%"

    next

end

 

config system automation-stitch

    edit "Hourly switch diagnostics"

        set trigger "Hourly XX:13"

            config actions

                edit 1

                    set action "FortiSwitch fan temp psu script"

                    set required enable

                next

                edit 2

                    set action "Send switch script results"

                    set required enable

                next

            end

    next

end

 

Notes:

  • When more responsive monitoring is required, it is recommended to use SNMP polls or traps instead of custom-command. See Configuring SNMP..
  • custom-command requires HTTPS access is enabled on the managed FortiSwitch. Before enabling FortiSwitch HTTPS access, ensure the FortiSwitch is on a current firmware version.
  • Where available, it is recommended to use FortiOS 'diagnose switch-controller' commands to pull information from the FortiGate instead of custom-command. See diagnose switch-controller for a list of supported switch-info commands on different Minor Versions.