As we want to view logs in N number of fortigate log through fortimanager using TCL script.
execute log filter category 9 execute log filter start-line 1 execute log filter view-lines 20 execute log display how can I integrate the above commands with TCL scripts. Thanks in advance.Regards
Manivannan N
Here is the TCL script that executes your commands on selected FortiGates.
#!/usr/bin/tclsh
############################################################
############################################################
# define procedures section
############################################################
# execute commands
proc do_cmd {cmd} {
# note that the prompt (#|\$) is special to handle non super user FMG users
puts [exec "$cmd\n" " (#|\$) " 10]
}
proc get_sys_status aname {
upvar $aname a
set a(vdom) true
set input [exec "get system status\n" "# " 15 ]
set linelist [split $input \n]
foreach line $linelist {
if {[regexp {Virtual domain configuration: disable} $line]} { set a(vdom) false }
if {![regexp {([^:]+):(.*)} $line dummy key value]} continue
switch -regexp -- $key {
Version { regexp {FortiGate-([^ ]+) ([^,]+),build([\d]+),.*} $value dummy a(platform) a(version) a(build) }
Serial-Number { set a(serial-number) [string trim $value] }
Hostname { set a(hostname) [string trim $value] }
}
}
}
############################################################
############################################################
# set verbose to true to increase output
set verbose true
############################################################
############################################################
# begin main script
############################################################
# get FortiGate information
get_sys_status status
if { ($verbose == true) } {
puts "This Fortigate is model: \[$status(platform)\]."
puts "It is running FortOS version: \[$status(version)\]."
puts "The firmware is build number: \[$status(build)\]."
puts "The device serial number is: \[$status(serial-number)\]."
puts "The machine hostname is: \[$status(hostname)\]."
}
############################################################
############################################################
# enter vdom if vdoms are enabled
if { ($status(vdom) == true) } {
# Enter VDOM if its enabled
if { ($verbose == true) } { puts "Entering vdom:\[root\]" }
do_cmd "config vdom"
do_cmd "edit root"
} else {
if { ($verbose == true) } { puts "No vdoms on this Fortigate" }
}
############################################################
############################################################
do_cmd "execute log filter category 9"
do_cmd "execute log filter start-line 1"
do_cmd "execute log filter view-lines 20"
do_cmd "execute log display"
############################################################
############################################################
puts "Script Finished"
do_cmd "end"
# End of script
############################################################
Select Forum Responses to become Knowledge Articles!
Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.
User | Count |
---|---|
1759 | |
1116 | |
766 | |
447 | |
242 |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2025 Fortinet, Inc. All Rights Reserved.