How to use SQL statement to query JumpServer related information?

Official website address: JumpServer - Open Source Bastion Host - Official Website

Online phone: 400-052-0755

Technical support: JumpServer technical consultation


1 Overview

This article mainly introduces how to query the relevant information of JumpServer that cannot be found on the page through SQL statements

2. SQL statement

2.1 Query zombie users who have not logged in to JumpServer within seven days;

select username,name from users_user where TO_DAYS(NOW()) - TO_DAYS(users_user.last_login) >= 7 or last_login is NULL and is_service_account=0;

2.2 Query zombie users who have not logged in to JumpServer within 30 days;

select username,name from users_user where TO_DAYS(NOW()) - TO_DAYS(users_user.last_login) >= 30 or last_login is NULL and is_service_account=0;

2.3 Query zombie users who have not logged in to assets;

SELECT username,email from users_user where users_user.id not in(SELECT DISTINCT REPLACE(terminal_session.user_id,'-','') FROM terminal_session) and is_service_account=0;

2.4 Query the assets that have not been logged in within the log statistics time;

select id,hostname from assets_asset where id not in(SELECT distinct replace(terminal_session.asset_id,'-','') FROM terminal_session);

2.5 Query the number of logged-in users and user login times in the past 30 days;

select username,count( * ) AS 'numbertime' from audits_userloginlog where TO_DAYS( now( ) ) - TO_DAYS( datetime ) <= 30 GROUP BY username ORDER BY 'numbertime' DESC;

2.6 Query the asset registration and the number of asset registrations within 30 days;

select asset,count(*) as number from terminal_session where TO_DAYS( now() ) - TO_DAYS(date_end) <=30 GROUP BY asset order by count(*) DESC;

2.7 Count the number of assets in each organization;

SELECT t.NAME, COUNT(*) FROM assets_asset a, orgs_organization t WHERE LEFT ( a.org_id, 8 ) = LEFT ( t.id, 8 ) GROUP BY t.NAME ORDER BY COUNT(*) DESC;

Guess you like

Origin blog.csdn.net/qq_43174065/article/details/128814724