Technical Tip: Displaying logs via FortiGate's CLI
Description
Â
This article describes that a FortiGate can display logs via both the GUI and the CLI and how to display logs through the CLI.
Â
Scope
Â
FortiGate.
Â
Solution
Â
To display log records in the CLI, use the following command (for VDOM-enabled FortiGates, this will be run in non-global VDOMs):
Â
execute log displayÂ
Note:
By default, no filters are applied to the above command, and so log records of all sub-types will be printed to the CLI. To filter this output to show specific log messages or categories of logs, use the execute log filter series of commands. This allows administrators to control which logs will be displayed and how many can be viewed at a time (up to 1000 lines of log messages per batch).
Â
Before applying a new filter, it is recommended to check the current filter settings using execute log filter dump. If necessary, the filter can be reset using the command execute log filter reset:
Â
FortiGate # execute log filter reset
FortiGate # execute log filter dump
category: traffic
device: disk
start-line: 1
view-lines: 10
max-checklines: 0
HA member:
log search mode: on-demand
pre-fetch-pages: 2
Oftp search string:Â
The following is an overview of the available options in the execute log filter command family:
Â
FortiGate # execute log filter ?
category Category.
device Device to get log from.
dump Dump current filter settings.
field Filter by field.
free-style Filter by free-style expression.
ha-member HA member.
local-search-mode local log search mode
max-checklines Maximum number of lines to check.
pre-fetch-pages Number of pages to check in advance under on-demand log search mode.
reset Reset filter.
start-line Start line to display.
view-lines Lines per view.Â
Note:
The field option supports further customization, such as using the 'not' keyword to reverse the filter, or '-' to specify ranges. Hit Enter when the command is incomplete to see the available options. For example:
Â
FortiGate # execute log filter field date ?
You can specify from 1 to 5 values
value1 [value2 ... value5] [not]
Use not to reverse the condition.
Each value can be a individual value or a value range.
For value range, "-" is used to separate two values.
Command fail. Return code -50Â
Applying log display filters - device:
The first step is to specify the logging device on the FortiGate that should be checked and displayed:
Â
execute log filter device <device>Â
From FortiOS 6.2 and later, the following logging devices are available to be searched (assuming the device has them enabled/configured):
Â
FGT81F_PJ_3960(Primary) (root) # execute log filter device ?
Available devices:
0: memory
1: disk
2: fortianalyzer
3: fortianalyzer-cloud
4: forticloudÂ
For example, running the command execute log filter device 0 will result in the FortiGate searching and displaying logs stored in memory.
Â
Note that the 'fortianalyzer-cloud' option was not available in FortiOS 6.0 and earlier, which resulted in the following options list instead:
Â
Available devices:
0: memory
1: disk
2: fortianalyzer
3: forticloudÂ
Applying log display filters - category:
The next step is to choose the category of logs to display:
Â
execute log filter category <category>Â
Generally speaking, each new FortiOS major/minor version (8.0, 7.6, 7.4, etc.) will retain support for the existing category ID numbers while also adding new logging categories. The following are the available categories and IDs available for filtering, as well as which FortiOS versions support them:
Â
FortiOS version support: | Added/available category filters: | Notes: |
|---|---|---|
FortiOS 5.4+ | | |
FortiOS 5.6+ | | |
FortiOS 6.0+ | | FortiOS 6.0 and later renamed the following categories:
|
FortiOS 6.2+ | | FortiOS 6.2 and later renamed '15: dns' to '15: utm-dns' |
FortiOS 6.4+ | | FortiOS 6.4.2 and later removed '18: utm-cifs' since CIFS profiles were moved into Profile-Protocol Options profiles (Change #627100) |
FortiOS 7.0+ | | |
FortiOS 7.2+ | | |
FortiOS 7.4+ | | |
FortiOS 7.6+ | | |
FortiOS 8.0+ | |
Â
Note:
The above filters apply to log searching/displaying logs already stored in the logging device. It is also possible to apply filters on the FortiGate to determine which logs are stored/recorded in the first place (useful for reducing overall logging volume/rates if certain categories are unnecessary). For more information on preventing certain log types from being captured, refer to the following documentation:
Â
Additional filters and examples:
For example, by using the following log filters, FortiGate will display all utm-webfilter logs with the destination IP address 40.85.78.63:
Â
FortiGate # execute log filter category 3Â Â Â Â Â Â Â
FortiGate # execute log filter field dstip 40.85.78.63
FortiGate # execute log display
1 logs found.
1 logs returned.
1: date=2019-09-14 time=14:52:36 logid="0317013312" type="utm" subtype="webfilter" eventtype="ftgd_allow" level="notice" vd="root" eventtime=1568465556531146383 tz="+0200" policyid=1 sessionid=3190297 srcip=172.16.190.216 srcport=10806 srcintf="port3" srcintfrole="undefined" dstip=40.85.78.63 dstport=443 dstintf="port1" dstintfrole="undefined" proto=6 service="HTTPS" hostname="wdcp.microsoft.com" profile="monitor-all" action="passthrough" reqtype="direct" url="/" sentbyte=197 rcvdbyte=3787 direction="outgoing" msg="URL belongs to an allowed category in policy" method="domain" cat=52 catdesc="Information Technology"Â
In addition to specifying category/device/etc. log filters, it is also possible to utilize the free-style filters with execute log filter free-style <BPF_style_filter>. For example, by using the following log filters, FortiGate will display all utm-webfilter logs with destination IP address 40.85.78.63 that are not from September 13, 2019:
Â
execute log filter free-style "(date 2019-09-13 not) and (dstip 40.85.78.63)"
execute log display
1 logs found.
1 logs returned.
1: date=2019-09-14 time=14:52:36 logid="0317013312" type="utm" subtype="webfilter" eventtype="ftgd_allow" level="notice" vd="root" eventtime=1568465556531146383 tz="+0200" policyid=1 sessionid=3190297 srcip=172.16.190.216 srcport=10806 srcintf="port3" srcintfrole="undefined" dstip=40.85.78.63 dstport=443 dstintf="port1" dstintfrole="undefined" proto=6 service="HTTPS" hostname="wdcp.microsoft.com" profile="monitor-all" action="passthrough" reqtype="direct" url="/" sentbyte=197 rcvdbyte=3787 direction="outgoing" msg="URL belongs to an allowed category in policy" method="domain" cat=52 catdesc="Information Technology"Â
Other examples of using the free-style log filter:
Â
execute log filter free-style "srcip 172.16.1.1"
execute log filter free-style "(srcip 172.16.1.1) or (dstip 172.16.1.2)"
execute log filter free-style "(srcip 172.16.1.1) and (dstip 172.16.1.2)"
execute log filter free-style "((srcip 172.16.1.1) or (dstip 172.16.1.2)) and (dstport 80 443 50-60)"Â
The following example filters will provide the output of all the event logs:
Â
execute log filter category 1
execute log filter view-lines <#_of_logs_to_display>
execute log displayÂ
To check the specific event logs such as system event logs, apply further filters as below:
Â
execute log filter category 1
execute log filter field subtype system
execute log filter view-lines <#_of_logs_to_display>
execute log displayÂ
To check two subtypes - for example, 'system' and 'ha' - apply the following filter below:Â
Â
execute log filter category 1
execute log filter field subtype system ha
execute log filter view-lines <#_of_logs_to_display>
execute log displayÂ
Note:
By default, the FortiGate CLI will only output batches of 10 logs each time the execute log display command is run (i.e. logs are paged through with each run). To view more log entries per run, increase the number of log entries displayed at once using the following command:
Â
execute log filter view-lines <5-1000, default = 10>Â
Continue running the 'execute log display'Â command repeatedly to scroll through the pages until reaching the last entry as desired.
Â
Finally, it is also possible to perform additional tasks with the logs:
Â
FortiGate # execute log ?
backup backup
delete Delete local logs of one category.
delete-all Delete all local logs and recreate report database.
detail Display utm log entries for a particular traffic log.
display Display filtered log entries.
filter filter
flush-cache Write disk log cache of current category to disk in compressed format.
flush-cache-all Write disk log cache of all categories to disk in compressed format.
fortianalyzer fortianalyzer
fortianalyzer-cloud fortianalyzer-cloud
fortianalyzer2 fortianalyzer2
fortianalyzer3 fortianalyzer3
list List current and rolled log files info.
raw-backup raw-backup
roll Roll log files now.Â
Related articles:
Technical Tip: Using filters to send only specific logs to the remote logging solution
Technical Tip: Using a CLI command to check the firewall policy creation date and time
