-
Notifications
You must be signed in to change notification settings - Fork 30
noslack
Chris Lasell edited this page Apr 1, 2018
·
2 revisions
This script reports the id and name of every computer that hasn't run Slack.app in the past 60 days.
It's an example of using the JSS::Computer.application_usage method.
On a JSS of about 1700 computers, this takes about 5 minutes to run, since it has to retrieve the 60-day app usage history for all computers and look for usage of the app.
To look for other apps or other time periods, change the APP_TO_CHECK and DAYS_TO_GO_BACK constants.
Be sure to change the connection values in the line starting with JSS.api.connect
#!/usr/bin/ruby
# Find computers that haven't run some application
# in the last XX number of days
#
# NOTE: needs ruby-jss v 0.10.2a1 or higher
# for the JSS::Computer.application_usage method
require 'ruby-jss'
APP_TO_CHECK = 'Slack.app'
DAYS_TO_GO_BACK = 60
JSS.api.connect user: 'mylogin', pw: :prompt, server: 'myjss.myorg.org', verify_cert: false
end_date = Time.now
start_date = end_date - (60 * 60 * 24 * DAYS_TO_GO_BACK)
macs_that_have_run_the_app = []
puts "# Finding computers that haven't run #{APP_TO_CHECK} in the past #{DAYS_TO_GO_BACK} days..."
JSS::Computer.all.each do |comp|
next unless comp[:managed]
app_usage = JSS::Computer.application_usage comp[:id], start_date, end_date
app_usage.each do |day, usage_for_day|
apps_used_this_day = usage_for_day.map { |app| app[:name] }
if apps_used_this_day.include? APP_TO_CHECK
macs_that_have_run_the_app << comp[:id]
break # each day
end # if
end # each day
end # each comp
# Now macs_that_have_run_the_app is an array of JSS IDs of computers that have run
# APP_TO_CHECK in the last DAYS_TO_GO_BACK days, so remove them from the list of all macs
macs_that_havent_run_the_app = JSS::Computer.all.reject { |c| macs_that_have_run_the_app.include? c[:id] }
puts "#"
puts "# id name"
puts "#--- ----"
macs_that_havent_run_the_app.each do |comp|
puts "%-7d %s" % [comp[:id], comp[:name]]
end