Skip to content

Instantly share code, notes, and snippets.

@icelander
Created August 24, 2020 17:28
Show Gist options
  • Save icelander/d241bb3f90886edc0d716de0522b387a to your computer and use it in GitHub Desktop.
Save icelander/d241bb3f90886edc0d716de0522b387a to your computer and use it in GitHub Desktop.
This is a query that gets session diagnostic information from the Mattermost database
-- Find diagnostic information for a specific user's sessions
SELECT u.Id as UserId,
u.Username,
u.Email,
s.Id As SessionId,
s.Roles,
s.DeviceId, -- For mobile sessions
IF (s.ExpiresAt IS NOT NULL && s.ExpiresAt < (UNIX_TIMESTAMP() * 1000), "Expired", "Active") as SessionActive,
IF (FROM_UNIXTIME(s.ExpiresAt/1000) IS NULL, "Token", "User") as SessionType, -- Tokens are bot or personal access tokens, User are sessions where the user logged in
FROM_UNIXTIME(s.CreateAt/1000) AS SessionCreateDate,
FROM_UNIXTIME(s.ExpiresAt/1000) AS SessionExpireDate,
FROM_UNIXTIME(s.LastActivityAt/1000) AS SessionLastActivityDate,
s.Props
FROM Users u
JOIN Sessions s ON s.UserId = u.Id
WHERE u.Id = '<User Id>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment