计划时间触发器

计划时间触发器(Schedule trigger)可以按照计划时间来触发自动化流程,支持的计划类型如下:

  • 每小时(hourly):指定在每小时的特定分钟循环触发。
  • 每天(daily):指定在每天的特定小时和分钟循环触发。
  • 每周(weekly):指定在每周的特定某天的小时和分钟循环触发。
  • 每月(monthly):指定在每月的特定某天的小时和分钟循环触发。
  • 单次(once):指定在特定的年/月/日/小时/分钟触发一次。
config system automation-trigger
    edit <name>
        set trigger-type scheduled
        set trigger-frequency {hourly | daily | weekly | monthly | once}
        set trigger-hour <inetger>
        set trigger-minute <integer>
        set trigger-weekday {sunday | monday | tuesday | wednesday | thursday | friday | saturday}
        set trigger-day <integer>
        set trigger-datetime <YYYY-MM-DD HH:MM:SS>
    next
end

网络需求

在每天的凌晨3点备份FortiGate的配置文件到FTP服务器,备份的配置文件名称中要包含备份的日期。

配置步骤

  1. 进入FortiGate的“Security Fabric→自动化→触发器”页面,点击“新建”按钮。

    image-20240313113653130

  2. 在弹出的页面的“其他条件”分类中点击“计划任务”。

    image-20240313113803409

  3. 配置触发器名称,计划任务频率选择“每天”,小时填写“3”,分钟保持默认“0”(24小时表示法),点击确认下发配置。

    image-20240313114151740

    image-20240313114301527

    config system automation-trigger
        edit "Daily_3am"
            set trigger-type scheduled
            set trigger-hour 3
        next
    end
    
  4. 进入FortiGate的“Security Fabric→自动化→操作”页面,点击“新建”按钮。

    image-20240313114358103

  5. 在弹出的页面的“通用”分类中点击“CLI脚本”。

    image-20240313114505183

  6. 配置动作名称,脚本中填写备份配置到FTP服务器的CLI命令,点击确认下发配置。

    image-20240313151826107

    config system automation-action
        edit "Backup_config_to_FTP"
            set action-type cli-script
            set script "exe backup config ftp AutoBackup_%%date%%.conf 192.168.100.110 backup 111111"
            set accprofile "super_admin"
        next
    end
    
    • AutoBackup_%%date%%.conf表示备份到FTP服务器的配置文件名称,其中%%date%%是一个变量,表示备份时的日期。
    • 192.168.100.110为FTP服务器的IP,如果FTP服务器使用的是非21端口,则需要在IP后添加加:<port>,如192.168.100.110:2121
    • backup:FTP用户名。
    • 111111:FTP用户密码。
  7. 进入FortiGate的“Security Fabric→自动化→工作流”页面,点击“新建”按钮。

    image-20240308160251703

  8. 配置工作流(Stitch的)名称,在触发中选择步骤3创建的触发器,在Action中选择步骤6创建的动作,点击“确认”下发配置。

    image-20240313152733366

    config system automation-stitch
        edit "Auto_backup"
            set trigger "Daily_3am"
            config actions
                edit 1
                    set action "Backup_config_to_FTP"
                    set required enable
                next
            end
        next
    end
    

结果验证

  1. 等待自动化流程被触发,检查FortiGate自动备份并上传到FTP服务器上的配置文件,可以看到文件名字与自动化Action中配置的CLI脚本的格式一致,包含备份日期。

    image-20240313161142749

  2. 查看FortiGate的自动化触发日志,可以看到该自动化流程在凌晨3点被触发并完成执行对应动作。

    date=2024-03-13 time=03:00:17 eventtime=1710316517425603720 tz="+0800" logid="0100046600" type="event" subtype="system" level="notice" vd="root" logdesc="Automation stitch triggered" stitch="Auto_backup" trigger="Daily_3am" stitchaction="Backup_config_to_FTP" from="scheduled" msg="stitch:Auto_backup is triggered."
    
    date=2024-03-13 time=03:00:22 eventtime=1710316522252196480 tz="+0800" logid="0100032549" type="event" subtype="system" level="information" vd="root" logdesc="Autoscript stop automatically" msg="script autod.10 stopped automatically"
    date=2024-03-13 time=15:55:22 eventtime=1710316522239782720 tz="+0800" logid="0100032142" type="event" subtype="system" level="notice" vd="root" logdesc="System configuration backed up" ui="auto-script" action="backup" msg="User  backed up the configuration from auto-script"
    
  3. 查看自动化触发的Debug信息,可以看到整个触发和执行备份配置文件到FTP的全部过程。

    FortiGate # diagnose debug application autod -1
    FortiGate # diagnose debug enable
    
    __action_cli_script_open()-186: cli script action:Backup_config_to_FTP is called. svc ctx:0xa1cabf0
    accprof:super_admin script:
    exe backup config ftp AutoBackup_%%date%%.conf 192.168.100.110 backup 111111
    
    pid:283-__handle_msg()-414: Subscriber:4 received package. pubid:2 pkgid:65017 pkg_index:0
    pid:283-__handle_pkg_logs()-356: Subscriber:4 processing package size:1198 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:1198 logs:1
    __cli_script_close()-121: cli script:
    autod.10
     output:
    ########## script name: autod.10 ##########
    
    ========== #1, 2024-03-13 15:55:17 ==========
    FW1_FGT101F $  exe backup config ftp AutoBackup_2024-03-13.conf 192.168.100.110 backup 111111
    
    Connect to ftp server 192.168.100.110 ...
    Please wait...
    Send config file to ftp server OK.
    
    __action_cli_script_close()-213: cli script action is done. script:
    exe backup config ftp AutoBackup_%%date%%.conf 192.168.100.110 backup 111111 
    output:
    ########## script name: autod.10 ##########
    
    ========== #1, 2024-03-13 15:55:17 ==========
    FW1_FGT101F $  exe backup config ftp AutoBackup_2024-03-13.conf 192.168.100.110 backup 111111
    
    Connect to ftp server 192.168.100.110 ...
    Please wait...
    Send config file to ftp server OK.
    
  4. 查看该自动化流程的状态统计信息。

    FortiGate # diagnose test application autod 3
    alert mail log count: 0
    
    stitch: Auto_backup (scheduled)
    
            local hit: 1 relayed to: 0 relayed from: 0
            last trigger:Wed Mar 13 15:55:17 2024
            last relay:
            next scheduled trigger:Thu Mar 14 15:55:00 2024
            actions:
                    Backup_config_to_FTP:
                            done: 1 relayed to: 0 relayed from: 0
                            last trigger:Wed Mar 13 03:00:17 2024
                            last relay:
    
    logid to stitch mapping:
    id:0 (scheduled stitches) local hit: 1 relayed hits: 0
            Auto_backup
    
    log category to stitch mapping:
    
  5. 附备份配置文件的CLI命令格式。

    FTP:
    execute backup config ftp <backup_filename> <ftp_server>[<:ftp_port>] [<user_name>] [<password>] [<backup_password>]
    
    TFTP:
    execute backup config tftp <backup_filename> <tftp_servers> [<backup_password>]
    
    SFTP:
    execute backup config sftp <backup_filename> <sftp_server>[<:sftp_port>] <user> <password> [<backup_password>]
    

Copyright © 2024 Fortinet Inc. All rights reserved. Powered by Fortinet TAC Team.
📲扫描下方二维码分享此页面👇
该页面修订于: 2024-03-18 09:42:27

results matching ""

    No results matching ""