module Chook::Samplers
A namespace for holding Constants and methods for pulling sample data from a JSS for use with Test events and test subjects
Public Class Methods
All Patch IDs
@param [JSS::APIConnection] API Connection object @return [Array<Integer>] An Array of enabled Patch Reporting Software IDs from the JSS
# File lib/chook/subject/samplers.rb, line 305 def self.all_patch_ids(_patch_hash, api: JSS.api) all_patches = api.get_rsrc('patches')[:patch_reporting_software_titles] all_ids = [] all_patches.each { |patch| all_ids << patch[:id] } raise 'No Patch Reporting Software Titles found' if all_ids.empty? all_ids end
All Patches
@param [JSS::APIConnection] API Connection object @return [Array<Hash>] Array of Hashes containing ids and names of enabled Patches
# File lib/chook/subject/samplers.rb, line 335 def self.all_patches(api: JSS.api) api.get_rsrc('patches')[:patch_reporting_software_titles] end
Building Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A building from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 224 def self.building(device_object) if device_object.is_a? JSS::Computer device_object.building else device_object.location[:building] end end
Department Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A department from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 215 def self.department(device_object) device_object.department end
Device Name Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A name sampled from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 137 def self.device_name(device_object) device_object.name end
Email Address Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] An email address from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 188 def self.email_address(device_object) device_object.email_address end
ICCID Sampler
@param [JSS:MobileDevice] device_object JSS Mobile Device Object @return [String] An ICCID sampled from a MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 67 def self.iccid(mobile_device_object) mobile_device_object.network[:iccid] end
IMEI Sampler
@param [JSS:MobileDevice] device_object JSS Mobile Device Object @return [String] An IMEI sampled from a MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 58 def self.imei(mobile_device_object) mobile_device_object.network[:imei] end
Institution Sampler
@param [JSS::APIConnection] API Connection object @return [String] The name of the JSS's Organization Name
# File lib/chook/subject/samplers.rb, line 14 def self.institution(api: JSS.api) api.get_rsrc('activationcode')[:activation_code][:organization_name] end
JSS ID Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [Integer] A JSS ID sampled from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 102 def self.jssid(device_object) device_object.id end
MAC Address Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A MAC Address sampled from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 32 def self.mac_address(device_object) if device_object.is_a? JSS::Computer device_object.mac_address else device_object.wifi_mac_address end end
Model Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A model sampled from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 146 def self.model(device_object) if device_object.is_a? JSS::Computer device_object.hardware[:model] else device_object.model end end
Model Display @param [JSS:MobileDevice] device_object JSS Mobile Device Object @return [String] Mobile Device Model String
# File lib/chook/subject/samplers.rb, line 93 def self.model_display(mobile_device_object) mobile_device_object.model_display end
OS Build Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] Operating System Build from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 111 def self.os_build(device_object) if device_object.is_a? JSS::Computer device_object.hardware[:os_build] else device_object.os_build end end
OS Version Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] Operating System Version from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 124 def self.os_version(device_object) if device_object.is_a? JSS::Computer device_object.hardware[:os_version] else device_object.os_version end end
Patch ID Sampler
@param [JSS::APIConnection] API Connection object @return [Integer] An enabled Patch Reporting Software ID from the JSS
# File lib/chook/subject/samplers.rb, line 296 def self.patch_id(_patch_hash, api: JSS.api) all_patch_ids(api).sample.to_i end
Patch Last Update Sampler
@return [Time] A Time for a Patch, since they can't be sampled via the API.
# File lib/chook/subject/samplers.rb, line 317 def self.patch_last_update(_patch_hash) Time.now end
Patch Latest Version
@param [Hash] raw_patch Hash of output from API query like get_rsrc(“patches/id/#{id}”) @return [String] The lastest version of a patch software title
# File lib/chook/subject/samplers.rb, line 353 def self.patch_latest_version(raw_patch, api: JSS.api) patch = api.get_rsrc("patches/id/#{raw_patch[:id]}") patch[:software_title][:versions].select { |i| i.is_a? String }.first end
Patch Name Sampler
@param [Hash] raw_patch Hash of output from API query like get_rsrc(“patches/id/#{id}”) @return [String] A Patch Reporting Software Title Name
# File lib/chook/subject/samplers.rb, line 344 def self.patch_name(raw_patch) # , api: JSS.api) raw_patch[:software_title][:name] end
Patch Report URL
@param [JSS::APIConnection] API Connection object @return [String] description of returned object
# File lib/chook/subject/samplers.rb, line 326 def self.patch_report_url(_patch_hash, api: JSS.api) api.rest_url.chomp('/JSSResource') end
Phone Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A phone number from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 197 def self.phone(device_object) device_object.phone end
Position Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A position from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 206 def self.position(device_object) device_object.position end
Product is always nil in the sample JSONs… And there isn't anything labeled “product” in api.get_rsrc(“mobiledevices/id/#{id}”)
@return [NilClass] nil
# File lib/chook/subject/samplers.rb, line 85 def self.product nil end
Real Name Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A real name from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 179 def self.real_name(device_object) device_object.real_name end
Room Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A room from a Computer or MobileDevice in the JSS
# File lib/chook/subject/samplers.rb, line 237 def self.room(device_object) device_object.room end
Serial Number
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [Type] Sampled Computer or Mobile Device Serial Number
# File lib/chook/subject/samplers.rb, line 23 def self.serial_number(device_object) device_object.serial_number end
Smart Group ID Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [Integer] The ID # of a MobileDevice or Computer Smart Group from JSS
def self.smart_group_jssid(device_object)
if device_object.is_a? JSS::Computer device_object.smart_groups[:smart_groups].sample[:id] elsif device_object.is_a? JSS::MobileDevice device_object.mobile_device_groups.sample[:id] else 0 end # if device_object.is_a? JSS::Computer
end # end group_jssid
# File lib/chook/subject/samplers.rb, line 273 def self.smart_group_type(device_object) if device_object.is_a? JSS::Computer true elsif device_object.is_a? JSS::MobileDevice false end # if device_object.is_a? JSS::Computer end
UDID Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A UDID sampled from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 45 def self.udid(device_object) if device_object.is_a? JSS::Computer device_object.udid else device_object.uuid end end
User Directory ID Sampler
@param [JSS::Computer] computer_object JSS Computer Object @return [Integer] A randomly sampled uid from a Computer in the JSS
# File lib/chook/subject/samplers.rb, line 168 def self.user_directory_id(computer_object) an_account = computer_object.groups_accounts[:local_accounts].sample return '-1' if an_account.empty? an_account[:uid] end
Username Sampler
@param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object @return [String] A username sampled from a MobileDevice or Computer in the JSS
# File lib/chook/subject/samplers.rb, line 159 def self.username(device_object) device_object.username end
Version
@param [JSS::APIConnection] API Connection object @return [String] Carrier Version String
# File lib/chook/subject/samplers.rb, line 76 def self.version(mobile_device_object) mobile_device_object.network[:carrier_settings_version] end