module Chook::Randomizers
A namespace for holding methods and constants used for creating random data for Test Events and Test Subjects.
Constants
- COMPUTER_SERIAL_CHARACTER_SETS
- MOBILE_SERIAL_CHARACTER_SETS
- NAMES
- PATCH_SOFTWARE_TITLES
A full list of supported titles is unfortunately not available via the API :(
- PUSH_COMMANDS
Keeping this set of
PUSH_COMMANDS
in here just in case JAMF decides to make the Push webhooks more useful…PUSH_COMMANDS
= ['Settings', 'DeviceLock', 'EraseDevice', 'ClearPasscode', 'UnmanageDevice', 'UpdateInventory', 'ClearRestrictionsPassword', 'SettingsEnableDataRoaming', 'SettingsDisableDataRoaming', 'SettingsEnableVoiceRoaming', 'SettingsDisableVoiceRoaming', 'SettingsEnableAppAnalytics', 'SettingsDisableAppAnalytics', 'SettingsEnableDiagnosticSubmission', 'SettingsDisableDiagnosticSubmission', 'BlankPush', 'Wallpaper', # supervised only 'DeviceName', # supervised only 'ShutDownDevice', # supervised only 'RestartDevice', # supervised only 'PasscodeLockGracePeriod' # shared iPad only
].freeze
- REST_OPS
- SAMPLE_COMPUTER_MODELS
- SAMPLE_MOBILE_MODELS
- WORDS
Public Class Methods
Random Boolean
@return [Boolean] True or False
# File lib/chook/subject/randomizers.rb, line 434 def self.bool rand(0..1).zero? end
Computer Model (wrapper)
@return [String] Randomly selected Computer model
# File lib/chook/subject/randomizers.rb, line 381 def self.computer_model model end
Computer OS Version (wrapper)
@return [String] Operating System Version from a Computer in the JSS
# File lib/chook/subject/randomizers.rb, line 418 def self.computer_os_version os_version end
Computer Serial Number
@return [String] Valid Computer Serial Number
# File lib/chook/subject/randomizers.rb, line 271 def self.computer_serial_number serial_number_from COMPUTER_SERIAL_CHARACTER_SETS end
Computer UUID (wrapper)
@return [String] Randomly generated computer UUID formatted String
# File lib/chook/subject/randomizers.rb, line 312 def self.computer_udid udid end
Random Email
@return [String] Randomly generated email address formatted String e.g. FirstNameLastName@randomword.com
# File lib/chook/subject/randomizers.rb, line 241 def self.email_address name.gsub(' ','.') + '@' + word + '.com' end
Random hostname-formatted String
@return [String] A random hostname-formatted String
# File lib/chook/subject/randomizers.rb, line 500 def self.host "#{word}.#{word}.com" end
Random ICCID
@return [String] Randomly generated ICCID formatted number String
# File lib/chook/subject/randomizers.rb, line 352 def self.iccid int(20).to_s.scan(/.{4}/).join(' ') end
Random IMEI
@return [String] Randomly generated IMEI formatted number String
# File lib/chook/subject/randomizers.rb, line 341 def self.imei indexes = [2, 9, 16] imei = int(15).to_s indexes.each { |idx| imei.insert(idx, ' ') } imei end
Random Int
@param [Integer] Optionally choose the length of the returned random Integer @return [Integer] Randomized number of an optionally specified length
# File lib/chook/subject/randomizers.rb, line 250 def self.int(x = 1) startpoint = 10**(x - 1) endpoint = (10**x) - 1 rand(startpoint..endpoint) end
Random MAC Address
@return [String] Randomly generated MAC address formatted String
# File lib/chook/subject/randomizers.rb, line 333 def self.mac_address SecureRandom.hex(6).upcase.scan(/.{2}/).join(':') end
Mobile Model (wrapper)
@return [String] Randomly selected MobileDevice model
# File lib/chook/subject/randomizers.rb, line 373 def self.mobile_model model(true) end
Mobile OS Version (wrapper)
@return [String] Operating System Version from a MobileDevice in the JSS
# File lib/chook/subject/randomizers.rb, line 410 def self.mobile_os_version os_version(true) end
Mobile Serial Number (wrapper)
@return [String] Valid Mobile Device Serial Number
# File lib/chook/subject/randomizers.rb, line 279 def self.mobile_serial_number serial_number_from MOBILE_SERIAL_CHARACTER_SETS end
Mobile UDID (wrapper)
@return [String] Randomly generated mobile UDID formatted String
# File lib/chook/subject/randomizers.rb, line 320 def self.mobile_udid udid(true) end
Random Model
@param [Boolean] mobile Returns a valid Computer model by default, mobile: true returns a valid Mobile Device model @return [String] Randomly selected Computer or MobileDevice model
# File lib/chook/subject/randomizers.rb, line 361 def self.model(mobile = false) if mobile SAMPLE_MOBILE_MODELS.sample else SAMPLE_COMPUTER_MODELS.sample end end
Random Name
@return [String] Randomly generated US English formatted “FirstName LastName”.
# File lib/chook/subject/randomizers.rb, line 233 def self.name NAMES.read.lines.sample.chomp + ' ' + NAMES.read.lines.sample.chomp end
Random OS Build
@return [String] Randomized OS build string
# File lib/chook/subject/randomizers.rb, line 426 def self.os_build SecureRandom.hex(3).upcase end
Random OS Version
@param [Boolean] mobile Returns a randomized Computer OS version by default, mobile: true returns a randomized Mobile Device OS version @return [Type] String
# File lib/chook/subject/randomizers.rb, line 398 def self.os_version(mobile = false) if mobile [rand(4..11), int, int].join('.') else [10, rand(6..15), int].join('.') end end
Random Patch Software Title
@return [String] Random Patch Software Title
# File lib/chook/subject/randomizers.rb, line 476 def self.patch PATCH_SOFTWARE_TITLES.sample end
Random Phone Number
@return [String] Random US-formatted Phone Number
# File lib/chook/subject/randomizers.rb, line 450 def self.phone raw_phone = int(10).to_s.split(//) [3, 7].each { |index| raw_phone.insert(index, '-') } raw_phone.join('') end
Product is null in the sample JSONs… And there isn't anything labeled “product” in JSS::API.get_rsrc(“mobiledevices/id/#{id}”)
# File lib/chook/subject/randomizers.rb, line 325 def self.product nil end
Random Push Command
@return [String] Random Push Command from PUSH_COMMANDS
# File lib/chook/subject/randomizers.rb, line 468 def self.push PUSH_COMMANDS.sample end
Random REST Operation
@return [String] Random GET, POST, PUT, or DELETE
# File lib/chook/subject/randomizers.rb, line 442 def self.rest_operation REST_OPS.sample end
Random Room Number
@return [String] Random Room Number
# File lib/chook/subject/randomizers.rb, line 460 def self.room int((1..4).to_a.sample).to_s end
Random Serial Number
@param [Array<Array>] A dataset for generating a serial number @return [String] Valid Computer or Mobile Device Serial Number
# File lib/chook/subject/randomizers.rb, line 261 def self.serial_number_from(dataset) serial = '' dataset.each { |pos| serial << pos.sample } serial end
Random Time (for lastUpdate in Patch Software Update subject)
@return [Time] A random date and time
# File lib/chook/subject/randomizers.rb, line 484 def self.time Time.at(rand * Time.now.to_i) end
Random U*ID MobileDevice UDID and Mac UUID are poorly distingusished in Jamf Pro. In a Jamf Pro Computer record, the “UDID” in the web interface corresponds to the Hardware UUID. On a Jamf Pro MobileDevice record, the UDID is actually a UDID. Since these are actually different things, they are generated differently.
@return [String] Randomly generated UUID/UDID formatted String
# File lib/chook/subject/randomizers.rb, line 291 def self.udid(mobile = false) if mobile # UDID = SHA1(serial + IMEI + wifiMac + bluetoothMac) Digest::SHA1.hexdigest(serial_number(mobile: true) + int(15).to_s + mac_address + mac_address) else # UUID # In its canonical textual representation, the sixteen octets of a UUID are represented as 32 hexadecimal (base 16) digits # displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and four hyphens). # For example: # 123e4567-e89b-12d3-a456-426655440000 indexes = [8, 13, 18, 23] uuid = SecureRandom.hex(16).upcase indexes.each { |idx| uuid.insert(idx, '-') } uuid.upcase end end
Random URL-formatted String
@return [String] A random URL-formatted String
# File lib/chook/subject/randomizers.rb, line 492 def self.url "http://www.#{word}.com:#{int}" end
Version
@return [String] Carrier Settings Version formatted String
# File lib/chook/subject/randomizers.rb, line 389 def self.version [int(2), int].join('.') end
Random Word Use this to generate device or username Strings
@return [String] Randomly generated US English word to stand in for a username, device name, etc.
# File lib/chook/subject/randomizers.rb, line 225 def self.word WORDS.read.lines.sample.chomp end