Module: Chook::Samplers

Defined in:
lib/chook/subject/samplers.rb

Overview

A namespace for holding Constants and methods for pulling sample data from a JSS for use with Test events and test subjects

Class Method Summary collapse

Class Method Details

.all_patch_ids(_patch_hash, api: JSS.api) ⇒ Array<Integer>

All Patch IDs

Parameters:

  • API (JSS::APIConnection)

    Connection object

Returns:

  • (Array<Integer>)

    An Array of enabled Patch Reporting Software IDs from the JSS



305
306
307
308
309
310
311
# 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(api: JSS.api) ⇒ Array<Hash>

All Patches

Parameters:

  • API (JSS::APIConnection)

    Connection object

Returns:

  • (Array<Hash>)

    Array of Hashes containing ids and names of enabled Patches



335
336
337
# 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(device_object) ⇒ String

Building Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A building from a Computer or MobileDevice in the JSS



224
225
226
227
228
229
230
# 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(device_object) ⇒ String

Department Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A department from a Computer or MobileDevice in the JSS



215
216
217
# File 'lib/chook/subject/samplers.rb', line 215

def self.department(device_object)
  device_object.department
end

.device_name(device_object) ⇒ String

Device Name Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A name sampled from a MobileDevice or Computer in the JSS



137
138
139
# File 'lib/chook/subject/samplers.rb', line 137

def self.device_name(device_object)
  device_object.name
end

.email_address(device_object) ⇒ String

Email Address Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    An email address from a Computer or MobileDevice in the JSS



188
189
190
# File 'lib/chook/subject/samplers.rb', line 188

def self.email_address(device_object)
  device_object.email_address
end

.iccid(mobile_device_object) ⇒ String

ICCID Sampler

Parameters:

  • device_object (JSS:MobileDevice)

    JSS Mobile Device Object

Returns:

  • (String)

    An ICCID sampled from a MobileDevice in the JSS



67
68
69
# File 'lib/chook/subject/samplers.rb', line 67

def self.iccid(mobile_device_object)
  mobile_device_object.network[:iccid]
end

.imei(mobile_device_object) ⇒ String

IMEI Sampler

Parameters:

  • device_object (JSS:MobileDevice)

    JSS Mobile Device Object

Returns:

  • (String)

    An IMEI sampled from a MobileDevice in the JSS



58
59
60
# File 'lib/chook/subject/samplers.rb', line 58

def self.imei(mobile_device_object)
  mobile_device_object.network[:imei]
end

.institution(api: JSS.api) ⇒ String

Institution Sampler

Parameters:

  • API (JSS::APIConnection)

    Connection object

Returns:

  • (String)

    The name of the JSS’s Organization Name



14
15
16
# File 'lib/chook/subject/samplers.rb', line 14

def self.institution(api: JSS.api)
  api.get_rsrc('activationcode')[:activation_code][:organization_name]
end

.jssid(device_object) ⇒ Integer

JSS ID Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (Integer)

    A JSS ID sampled from a MobileDevice or Computer in the JSS



102
103
104
# File 'lib/chook/subject/samplers.rb', line 102

def self.jssid(device_object)
  device_object.id
end

.mac_address(device_object) ⇒ String

MAC Address Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A MAC Address sampled from a MobileDevice or Computer in the JSS



32
33
34
35
36
37
38
# 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(device_object) ⇒ String

Model Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A model sampled from a MobileDevice or Computer in the JSS



146
147
148
149
150
151
152
# 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(mobile_device_object) ⇒ String

Model Display

Parameters:

  • device_object (JSS:MobileDevice)

    JSS Mobile Device Object

Returns:

  • (String)

    Mobile Device Model String



93
94
95
# File 'lib/chook/subject/samplers.rb', line 93

def self.model_display(mobile_device_object)
  mobile_device_object.model_display
end

.os_build(device_object) ⇒ String

OS Build Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    Operating System Build from a MobileDevice or Computer in the JSS



111
112
113
114
115
116
117
# 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(device_object) ⇒ String

OS Version Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    Operating System Version from a MobileDevice or Computer in the JSS



124
125
126
127
128
129
130
# 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(_patch_hash, api: JSS.api) ⇒ Integer

Patch ID Sampler

Parameters:

  • API (JSS::APIConnection)

    Connection object

Returns:

  • (Integer)

    An enabled Patch Reporting Software ID from the JSS



296
297
298
# 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(_patch_hash) ⇒ Time

Patch Last Update Sampler

Returns:

  • (Time)

    A Time for a Patch, since they can’t be sampled via the API.



317
318
319
# File 'lib/chook/subject/samplers.rb', line 317

def self.patch_last_update(_patch_hash)
  Time.now
end

.patch_latest_version(raw_patch, api: JSS.api) ⇒ String

Patch Latest Version

Parameters:

  • raw_patch (Hash)

    Hash of output from API query like get_rsrc(“patches/id/#id”)

Returns:

  • (String)

    The lastest version of a patch software title



353
354
355
356
# 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(raw_patch) ⇒ String

Patch Name Sampler

Parameters:

  • raw_patch (Hash)

    Hash of output from API query like get_rsrc(“patches/id/#id”)

Returns:

  • (String)

    A Patch Reporting Software Title Name



344
345
346
# 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(_patch_hash, api: JSS.api) ⇒ String

Patch Report URL

Parameters:

  • API (JSS::APIConnection)

    Connection object

Returns:

  • (String)

    description of returned object



326
327
328
# 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(device_object) ⇒ String

Phone Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A phone number from a Computer or MobileDevice in the JSS



197
198
199
# File 'lib/chook/subject/samplers.rb', line 197

def self.phone(device_object)
  device_object.phone
end

.position(device_object) ⇒ String

Position Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A position from a Computer or MobileDevice in the JSS



206
207
208
# File 'lib/chook/subject/samplers.rb', line 206

def self.position(device_object)
  device_object.position
end

.productNilClass

Product is always nil in the sample JSONs… And there isn’t anything labeled “product” in api.get_rsrc(“mobiledevices/id/#id”)

Returns:

  • (NilClass)

    nil



85
86
87
# File 'lib/chook/subject/samplers.rb', line 85

def self.product
  nil
end

.real_name(device_object) ⇒ String

Real Name Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A real name from a Computer or MobileDevice in the JSS



179
180
181
# File 'lib/chook/subject/samplers.rb', line 179

def self.real_name(device_object)
  device_object.real_name
end

.room(device_object) ⇒ String

Room Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A room from a Computer or MobileDevice in the JSS



237
238
239
# File 'lib/chook/subject/samplers.rb', line 237

def self.room(device_object)
  device_object.room
end

.serial_number(device_object) ⇒ Type

Serial Number

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (Type)

    Sampled Computer or Mobile Device Serial Number



23
24
25
# File 'lib/chook/subject/samplers.rb', line 23

def self.serial_number(device_object)
  device_object.serial_number
end

.smart_group_type(device_object) ⇒ Integer

Smart Group ID Sampler

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

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (Integer)

    The ID # of a MobileDevice or Computer Smart Group from JSS



273
274
275
276
277
278
279
# 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(device_object) ⇒ String

UDID Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A UDID sampled from a MobileDevice or Computer in the JSS



45
46
47
48
49
50
51
# 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(computer_object) ⇒ Integer

User Directory ID Sampler

Parameters:

  • computer_object (JSS::Computer)

    JSS Computer Object

Returns:

  • (Integer)

    A randomly sampled uid from a Computer in the JSS



168
169
170
171
172
# File 'lib/chook/subject/samplers.rb', line 168

def self.user_directory_id(computer_object)
   = computer_object.groups_accounts[:local_accounts].sample
  return '-1' if .empty?
  [:uid]
end

.username(device_object) ⇒ String

Username Sampler

Parameters:

  • device_object (JSS:MobileDevice or JSS::Computer)

    JSS Mobile Device or Computer Object

Returns:

  • (String)

    A username sampled from a MobileDevice or Computer in the JSS



159
160
161
# File 'lib/chook/subject/samplers.rb', line 159

def self.username(device_object)
  device_object.username
end

.version(mobile_device_object) ⇒ String

Version

Parameters:

  • API (JSS::APIConnection)

    Connection object

Returns:

  • (String)

    Carrier Version String



76
77
78
# File 'lib/chook/subject/samplers.rb', line 76

def self.version(mobile_device_object)
  mobile_device_object.network[:carrier_settings_version]
end