Created on
02-11-2024
06:09 AM
Edited on
11-20-2025
05:17 AM
By
Jean-Philippe_P
This article describes creating a report to track VPN users' connection and disconnection times, for FortiAnalyzer versions 7.2 and 7.4. Below is a separate section for FortiAnalyzer v7.6.
|
User |
VPN Status |
Time |
|
User a |
Connected |
2024-01-30 04:36 |
|
User a |
Disconnected |
2024-01-30 15:02 |
|
User b |
Connected |
2024-01-29 04:46 |
|
User b |
Disconnected |
2024-01-29 07:09 |
FortiAnalyzer v7.2, v7.4, v7.6.
SELECT
`user` AS "User",
(
CASE
WHEN `action` = 'tunnel-up' THEN 'Connected'
ELSE 'Disconnected'
END
) AS "VPN Status",
$calendar_time(itime) AS `Time Stamp`
FROM
$log
WHERE
$filter
AND (
(`action` = 'tunnel-up')
OR (`action` = 'tunnel-down')
)
GROUP BY
`Time Stamp`,
`action`,
`user`
ORDER BY
`user`,
`Time Stamp`
If the above query shows the IP addresses in the 'USER' column, then it may be because FortiGate is functioning either as an XAuth server or client, and logs are showing the user name as 'xauthuser'. Then replace 'user' with 'xauthuser' in the SQL query to see the usernames instead of IP addresses.
For FortiAnalyzer version 7.6, a slightly modified dataset can be used (it includes login, logout, and duration of a user as well) :
SELECT
a.`user`,
a.login,
b.logout,
b.duration,
b.transferred_bytes
FROM
###(
SELECT
`user`,
min(from_dtime(dtime)) AS login,
tunnelid
FROM
$log-event
WHERE
action = 'tunnel-up'
and $filter
GROUP BY
`user`,
tunnelid
)### a,
###(
SELECT
max(from_dtime(dtime)) AS logout,
duration,
sum(sentbyte + rcvdbyte) AS transferred_bytes,
tunnelid
FROM
$log-event
WHERE
action = 'tunnel-down'
and $filter
GROUP BY
duration,
tunnelid
HAVING
sum(sentbyte + rcvdbyte) > 0
)### b
WHERE
a.tunnelid = b.tunnelid
ORDER BY
login,
`user`
Related documents:
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.