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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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”)


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

def self.product
  nil
end

.real_name(device_object) ⇒ String

Real Name Sampler


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


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


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


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


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


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


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


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