fritz
11/02/2020, 3:16 PMrpm_packages
where an install_time
exists?Zach Zeid
11/02/2020, 3:18 PMTRUE
or FALSE
in this case. I don't know of an instance where an installed rpm package would have an empty install_time columnfritz
11/02/2020, 3:19 PMZach Zeid
11/02/2020, 3:20 PMdate()
object and return either True or Falseselect datetime(install_time, 'unixepoch', 'localtime') as last_install_time from rpm_packages where last_install_time >= date('now', '-14 days') order by last_install_time desc limit 1;
is where I could use COUNT()
here, right?osquery> select datetime(install_time, 'unixepoch', 'localtime') as last_install_time from rpm_packages where last_install_time >= date('now', '-14 days') order by last_install_time desc limit 1;
+---------------------+
| last_install_time |
+---------------------+
| 2020-10-30 11:40:57 |
+---------------------+
Run Time: real 1.454 user 1.372736 sys 0.081052
osquery> select datetime(install_time, 'unixepoch', 'localtime') as last_install_time from rpm_packages where last_install_time >= date('now', '-1 days') order by last_install_time desc limit 1;
Run Time: real 1.461 user 1.376146 sys 0.085041
osquery>
fritz
11/02/2020, 3:30 PMosquery> SELECT name, bundle_identifier, datetime(last_opened_time, 'unixepoch', 'localtime') AS last_opened_at FROM apps WHERE datetime(last_opened_time, 'unixepoch') > datetime('now', '-14 days') ORDER BY last_opened_time DESC;
+-----------------------------------+------------------------------------------------+---------------------+
| name | bundle_identifier | last_opened_at |
+-----------------------------------+------------------------------------------------+---------------------+
| <http://FaceTime.app|FaceTime.app> | com.apple.FaceTime | 2020-11-01 16:50:33 |
| <http://PTPCamera.app|PTPCamera.app> | com.apple.PTPCamera | 2020-10-31 14:08:09 |
| <http://Sketch.app|Sketch.app> | com.bohemiancoding.sketch3 | 2020-10-30 17:39:30 |
| <http://FindMy.app|FindMy.app> | com.apple.findmy | 2020-10-30 10:29:41 |
| Archive <http://Utility.app|Utility.app> | com.apple.archiveutility | 2020-10-30 09:43:18 |
| The <http://Unarchiver.app|Unarchiver.app> | cx.c3.theunarchiver | 2020-10-30 09:43:04 |
| <http://Screen.app|Screen.app> | <http://so.screen.screen.app|so.screen.screen.app> | 2020-10-30 09:37:59 |
| <http://Numbers.app|Numbers.app> | com.apple.iWork.Numbers | 2020-10-29 21:06:42 |
| <http://Maps.app|Maps.app> | com.apple.Maps | 2020-10-29 15:50:18 |
| Google <http://Chrome.app|Chrome.app> | com.google.Chrome | 2020-10-29 13:12:31 |
Zach Zeid
11/02/2020, 3:31 PMosquery> select case when exists (select datetime(install_time, 'unixepoch', 'localtime') as last_install_time from rpm_packages where last_install_time >= date('now', '-1 days') order by last_install_time desc limit 1) then 'TRUE' else 'FALSE' end as updates_ran;
+-------------+
| updates_ran |
+-------------+
| FALSE |
+-------------+
Run Time: real 1.473 user 1.374503 sys 0.098190
osquery> select case when exists (select datetime(install_time, 'unixepoch', 'localtime') as last_install_time from rpm_packages where last_install_time >= date('now', '-28 days') order by last_install_time desc limit 1) then 'TRUE' else 'FALSE' end as updates_ran;
+-------------+
| updates_ran |
+-------------+
| TRUE |
+-------------+
Run Time: real 1.459 user 1.380649 sys 0.078003
fritz
11/02/2020, 3:35 PMdatetime('now', '-1 days')
WITH rpm_reduced AS (
SELECT datetime(MAX(install_time), 'unixepoch', 'localtime') AS max_install_time FROM rpm_packages)
SELECT CASE WHEN max_install_time >= datetime('now', '-1 days') THEN 'true' ELSE 'false' END AS updates_run_last_24h FROM rpm_reduced;
Zach Zeid
11/02/2020, 3:41 PMfritz
11/02/2020, 3:42 PMSELECT CASE WHEN datetime(MAX(install_time), 'unixepoch', 'local_time') >= datetime('now', '-1 days')
THEN 'true'
ELSE 'false'
END AS updates_run_last_24h
FROM rpm_packages;
Zach Zeid
11/02/2020, 3:42 PMfritz
11/02/2020, 3:43 PMZach Zeid
11/02/2020, 3:44 PMfritz
11/02/2020, 3:44 PMZach Zeid
11/02/2020, 3:47 PMfritz
11/02/2020, 3:49 PMWITH
relevant_users AS (
SELECT DISTINCT(username) AS username, u.uid
FROM users u CROSS JOIN logged_in_users liu
WHERE liu.user = u.username),
Zach Zeid
11/02/2020, 3:50 PMfritz
11/02/2020, 3:50 PMZach Zeid
11/02/2020, 3:50 PMfritz
11/02/2020, 3:51 PM-- Reduce user accounts
WITH user_accounts AS (
SELECT username, description, uid, directory
FROM users WHERE SUBSTR(uuid, 0, 8) != 'FFFFEEE'),
-- Check against logged in users
liu AS (
SELECT ua.*
FROM logged_in_users JOIN user_accounts ua ON ua.username = logged_in_users.user
WHERE logged_in_users.tty = 'console'),
-- Check ByHost plists for screensaver settings
screensaver_byhost_multiple AS (
SELECT
u.username,
datetime(f.mtime, 'unixepoch') AS screensaver_pref_plist_modified,
MAX(CASE WHEN key = 'idleTime' THEN CAST(value AS int) END) AS screensaver_idle
FROM kolide_plist kp, file f USING(path)
JOIN user_accounts u ON u.directory = ('/Users/' || SPLIT(kp.path, '/', 1))
WHERE path LIKE '/Users/%/Library/Preferences/ByHost/com.apple.screensaver.%.plist'
GROUP BY path),
-- Cleanup ByHost files by resolving multiples
...
Zach Zeid
11/02/2020, 3:58 PMfritz
11/02/2020, 3:58 PM--
Zach Zeid
11/02/2020, 3:59 PMfritz
11/02/2020, 3:59 PMZach Zeid
11/02/2020, 3:59 PM