module Jamf::MDM::ClassMethods

See codereview.stackexchange.com/questions/23637/mixin-both-instance-and-class-methods-in-ruby for discussion of this technique for mixing in both Class and Instance methods when including a module.

Public Instance Methods

blank_push(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a blank push to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)]

    # File lib/jamf/api/classic/api_objects/mdm.rb
569 def blank_push(targets, api: nil, cnx: Jamf.cnx)
570   cnx = api if api
571 
572   send_mdm_command targets, :blank_push, cnx: cnx
573 end
Also aliased as: send_blank_push, noop
clear_passcode(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an clear_passcode command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
746 def clear_passcode(targets, api: nil, cnx: Jamf.cnx)
747   cnx = api if api
748 
749   send_mdm_command targets, :clear_passcode, cnx: cnx
750 end
clear_restrictions_password(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an clear_restrictions_password command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
760 def clear_restrictions_password(targets, api: nil, cnx: Jamf.cnx)
761   cnx = api if api
762 
763   send_mdm_command targets, :clear_restrictions_password, cnx: cnx
764 end
delete_user(targets, user, api: nil, cnx: Jamf.cnx) click to toggle source

Send a delete_user command to one or more targets

@param targets @see .send_mdm_command

@param user the username of the acct to delete

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
686 def delete_user(targets, user, api: nil, cnx: Jamf.cnx)
687   cnx = api if api
688 
689   send_mdm_command targets, :delete_user, opts: { user_name: user }, cnx: cnx
690 end
device_lock(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx) click to toggle source

Send a Device Lock to one or more targets

@param targets @see .send_mdm_command

@param passcode a six-char passcode, required for computers & computergroups

@param message An optional message to display on mobiledevices & mobiledevicegroups

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
589 def device_lock(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx)
590   cnx = api if api
591 
592   case self::MDM_COMMAND_TARGET
593   when *COMPUTER_TARGETS
594     raise Jamf::InvalidDataError, 'Locking computers requires a 6-character String passcode' unless passcode.size == 6
595 
596     opts = { passcode: passcode }
597   when *DEVICE_TARGETS
598     opts = {}
599     opts[:lock_message] = message if message
600   end # case
601   send_mdm_command targets, :device_lock, opts: opts, cnx: cnx
602 end
Also aliased as: lock_device, lock
device_name(targets, name, api: nil, cnx: Jamf.cnx) click to toggle source

Send a device_name command to one or more targets

@param targets @see .send_mdm_command

@param name The new name

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
835 def device_name(targets, name, api: nil, cnx: Jamf.cnx)
836   cnx = api if api
837 
838   send_mdm_command targets, :device_name, opts: { device_name: name }, cnx: cnx
839 end
Also aliased as: set_name, set_device_name
disable_app_analytics(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a disable_app_analytics command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
954 def disable_app_analytics(targets, api: nil, cnx: Jamf.cnx)
955   cnx = api if api
956 
957   send_mdm_command targets, :disable_app_analytics, cnx: cnx
958 end
disable_data_roaming(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send andisable_data_roaming command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
788 def disable_data_roaming(targets, api: nil, cnx: Jamf.cnx)
789   cnx = api if api
790 
791   send_mdm_command targets, :disable_data_roaming, cnx: cnx
792 end
disable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a disable_diagnostic_submission command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
982 def disable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx)
983   cnx = api if api
984 
985   send_mdm_command targets, :disable_diagnostic_submission, cnx: cnx
986 end
disable_lost_mode(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a disable_lost_mode command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

     # File lib/jamf/api/classic/api_objects/mdm.rb
1053 def disable_lost_mode(targets, api: nil, cnx: Jamf.cnx)
1054   cnx = api if api
1055 
1056   send_mdm_command targets, :disable_lost_mode, cnx: cnx
1057 end
disable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a disable_remote_desktop command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
714 def disable_remote_desktop(targets, api: nil, cnx: Jamf.cnx)
715   cnx = api if api
716 
717   send_mdm_command targets, :disable_remote_desktop, cnx: cnx
718 end
disable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a disable_voice_roaming command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
816 def disable_voice_roaming(targets, api: nil, cnx: Jamf.cnx)
817   cnx = api if api
818 
819   send_mdm_command targets, :disable_voice_roaming, cnx: cnx
820 end
enable_app_analytics(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an enable_app_analytics command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
940 def enable_app_analytics(targets, api: nil, cnx: Jamf.cnx)
941   cnx = api if api
942 
943   send_mdm_command targets, :enable_app_analytics, cnx: cnx
944 end
enable_data_roaming(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an enable_data_roaming command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
774 def enable_data_roaming(targets, api: nil, cnx: Jamf.cnx)
775   cnx = api if api
776 
777   send_mdm_command targets, :enable_data_roaming, cnx: cnx
778 end
enable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an enable_diagnostic_submission command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
968 def enable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx)
969   cnx = api if api
970 
971   send_mdm_command targets, :enable_diagnostic_submission, cnx: cnx
972 end
enable_lost_mode( targets, message: nil, phone: nil, footnote: nil, play_sound: false, enforce_lost_mode: false, api: nil, cnx: Jamf.cnx ) click to toggle source

Send a enable_lost_mode command to one or more targets

Either or both of message and phone number must be provided

@param targets @see .send_mdm_command

@param message The message to display on the lock screen

@param phone The phone number to display on the lock screen

@param footnote Optional footnote to display on the lock screen

@param play_sound Play a sound when entering lost mode

@param enforce_lost_mode Re-enable lost mode when re-enrolled after wipe. Default is false

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

     # File lib/jamf/api/classic/api_objects/mdm.rb
1008 def enable_lost_mode(
1009   targets,
1010   message: nil,
1011   phone: nil,
1012   footnote: nil,
1013   play_sound: false,
1014   enforce_lost_mode: false,
1015   api: nil,
1016   cnx: Jamf.cnx
1017 )
1018   cnx = api if api
1019 
1020   raise ArgumentError, 'Either message: or phone_number: must be provided' unless message || phone
1021 
1022   opts = { always_enforce_lost_mode: enforce_lost_mode }
1023   opts[:lost_mode_message] = message if message
1024   opts[:lost_mode_phone] = phone if phone
1025   opts[:lost_mode_footnote] = footnote if footnote
1026   opts[:lost_mode_with_sound] = 'true' if play_sound
1027 
1028   send_mdm_command targets, :enable_lost_mode, opts: opts, cnx: cnx
1029 end
enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an enable_remote_desktop command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
700 def enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx)
701   cnx = api if api
702 
703   send_mdm_command targets, :enable_remote_desktop, cnx: cnx
704 end
enable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an enable_voice_roaming command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
802 def enable_voice_roaming(targets, api: nil, cnx: Jamf.cnx)
803   cnx = api if api
804 
805   send_mdm_command targets, :enable_voice_roaming, cnx: cnx
806 end
erase(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx)
Alias for: erase_device
erase_device(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx) click to toggle source

Send an Erase Device command to one or more targets

@param targets @see .send_mdm_command

@param passcode a six-char passcode, required for computers & computergroups

@param preserve_data_plan Should the data plan of the mobile device be preserved?

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
618 def erase_device(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx)
619   cnx = api if api
620 
621   case self::MDM_COMMAND_TARGET
622   when *COMPUTER_TARGETS
623     raise Jamf::InvalidDataError, 'Erasing computers requires a 6-character String passcode' unless passcode.size == 6
624 
625     opts = { passcode: passcode }
626   when *DEVICE_TARGETS
627     opts = {}
628     opts[:preserve_data_plan] = 'true' if preserve_data_plan
629   end # case
630   send_mdm_command targets, :erase_device, opts: opts, cnx: cnx
631 end
Also aliased as: wipe, wipe_device, erase, wipe_computer
flush_mdm_commands(targets, status: nil, api: nil, cnx: Jamf.cnx) click to toggle source

Flush pending or failed commands on devices or groups

@param targets

the name or id of the device or group to flush commands, or
an array of such names or ids, or a comma-separated string
of them. NOTE: when calling this on a Group class, the targets
are the groups themselves, not the individual members.

@param status a key from {Jamf::Commandable::FLUSHABLE_STATUSES}

@param cnx [Jamf::Connection] an API connection to use.

Defaults to the corrently active API. See {Jamf::Connection}

@return [void]

     # File lib/jamf/api/classic/api_objects/mdm.rb
1077 def flush_mdm_commands(targets, status: nil, api: nil, cnx: Jamf.cnx)
1078   cnx = api if api
1079 
1080   raise Jamf::InvalidDataError, "Status must be one of :#{FLUSHABLE_STATUSES.keys.join ', :'}" unless FLUSHABLE_STATUSES.keys.include? status
1081 
1082   status = FLUSHABLE_STATUSES[status]
1083 
1084   # TODO: add 'unmanaged_ok:' param to raw_targets_to_ids method, so that we can
1085   # use this to flush commands for unmanaged machines.
1086   target_ids = raw_targets_to_ids targets, cnx: cnx, expand_groups: false, unmanaged_ok: true
1087 
1088   command_flush_rsrc = "commandflush/#{self::MDM_COMMAND_TARGET}/id"
1089 
1090   flush_rsrc = "#{command_flush_rsrc}/#{target_ids.join ','}/status/#{status}"
1091 
1092   puts "Sending API DELETE: #{flush_rsrc}" if JSS.devmode?
1093 
1094   cnx.c_delete flush_rsrc
1095 end
lock(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx)
Alias for: device_lock
lock_device(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx)
Alias for: device_lock
mdm_command_xml(command, options, targets) click to toggle source

Generate the XML to send to the API, sending the MDM command to the targets

@param command [Symbol] the command to be sent, a key from COMMANDS

@param options [Hash] different commands require different options,

see each command method

@param targets @see .send_mdm_command

@return [String] The XML content to send to the API

    # File lib/jamf/api/classic/api_objects/mdm.rb
494 def mdm_command_xml(command, options, targets)
495   raise Jamf::MissingDataError, 'Targets cannot be empty' if targets.empty?
496 
497   case self::MDM_COMMAND_TARGET
498   when *COMPUTER_TARGETS
499     command_elem = COMPUTER_COMMAND_ELEMENT
500     target_list_elem = Jamf::Computer::RSRC_LIST_KEY.to_s
501     target_elem = Jamf::Computer::RSRC_OBJECT_KEY.to_s
502   when *DEVICE_TARGETS
503     command_elem = DEVICE_COMMAND_ELEMENT
504     target_list_elem = Jamf::MobileDevice::RSRC_LIST_KEY.to_s
505     target_elem = Jamf::MobileDevice::RSRC_OBJECT_KEY.to_s
506   else
507     raise Jamf::NoSuchItemError, "Unknonwn MDM command target: #{self::MDM_COMMAND_TARGET}"
508   end # case
509 
510   xml = REXML::Document.new Jamf::Connection::XML_HEADER
511   cmd_xml = xml.add_element command_elem
512 
513   general = cmd_xml.add_element GENERAL_ELEMENT
514   general.add_element(COMMAND_ELEMENT).text = command
515   options.each do |opt, val|
516     general.add_element(opt.to_s).text = val.to_s
517   end # do opt val
518 
519   tgt_list = cmd_xml.add_element target_list_elem
520   targets.each do |tgt_id|
521     tgt = tgt_list.add_element(target_elem)
522     tgt.add_element(TARGET_ID_ELEMENT).text = tgt_id.to_s
523   end
524 
525   xml.to_s
526 end
noop(targets, api: nil, cnx: Jamf.cnx)
Alias for: blank_push
passcode_lock_grace_period(targets, secs, api: nil, cnx: Jamf.cnx) click to toggle source

Send a passcode_lock_grace_period command to one or more targets

@param targets @see .send_mdm_command

@param secs The numer of seconds for the grace period

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
894 def passcode_lock_grace_period(targets, secs, api: nil, cnx: Jamf.cnx)
895   cnx = api if api
896 
897   send_mdm_command targets, :passcode_lock_grace_period, opts: { passcode_lock_grace_period: secs }, cnx: cnx
898 end
play_lost_mode_sound(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a play_lost_mode_sound command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

     # File lib/jamf/api/classic/api_objects/mdm.rb
1039 def play_lost_mode_sound(targets, api: nil, cnx: Jamf.cnx)
1040   cnx = api if api
1041 
1042   send_mdm_command targets, :play_lost_mode_sound, cnx: cnx
1043 end
process_computer_xml_result(result) click to toggle source

Convert the result of senting a computer MDM command into the appropriate hash

@param result [String] The raw XML from POSTing a computer command

@return (see send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
391 def process_computer_xml_result(result)
392   hash = {}
393   REXML::Document.new(result).elements[COMPUTER_COMMAND_ELEMENT].each_element do |cmd|
394     compid = cmd.elements[COMPUTER_ID_ELEMENT].text.to_i
395     udid = cmd.elements[COMPUTER_COMMAND_UDID_ELEMENT].text
396     hash[compid] = udid
397   end
398   hash
399 end
process_mobiledevice_xml_result(result) click to toggle source

Convert the result of senting a device MDM command into the appropriate hash

@param result [String] The raw XML from POSTing a device command

@return (see send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
408 def process_mobiledevice_xml_result(result)
409   hash = {}
410   mds = REXML::Document.new(result).elements[DEVICE_COMMAND_ELEMENT].elements[DEVICE_LIST_ELEMENT]
411   mds.each_element do |md|
412     id = md.elements[DEVICE_ID_ELEMENT].text.to_i
413     status = md.elements[DEVICE_COMMAND_STATUS_ELEMENT].text
414     hash[id] = status
415   end
416   hash
417 end
raw_targets_to_ids(targets, expand_groups: true, unmanaged_ok: false, api: nil, cnx: Jamf.cnx) click to toggle source

Convert the targets provided for sending a command into the final list of computers or mobile devices.

@param targets See {#send_mdm_command}

@param expand_groups Should groups be expanded into member ids?

@param cnx [Jamf::Connection] an API connection to use.

@return [Array<Integer>] The ids of the target devices for a command

    # File lib/jamf/api/classic/api_objects/mdm.rb
445 def raw_targets_to_ids(targets, expand_groups: true, unmanaged_ok: false, api: nil, cnx: Jamf.cnx)
446   cnx = api if api
447 
448   targets = targets.is_a?(Array) ? targets : [targets]
449 
450   # flush caches before checking ids and managment
451   cnx.flushcache self::RSRC_LIST_KEY
452 
453   # make sure its an array of ids
454   targets.map! do |md|
455     id = valid_id md, cnx: cnx
456     raise Jamf::NoSuchItemError, "No #{self} matches identifier: #{md}" unless id
457 
458     id
459   end # map!
460 
461   # expand group members if needed
462   if expand_groups && GROUP_TARGETS.include?(self::MDM_COMMAND_TARGET)
463     target_ids = []
464     targets.each { |group_id| target_ids += fetch(id: group_id).member_ids }
465     targets = target_ids
466   end
467 
468   # make sure all of them are managed, or else the API will raise a 400
469   # 'Bad Request' when sending the command to an unmanaged target.
470   # Some actions, like flushing MDM commands (see .flush_mdm_commands)
471   # are OK on unmanaged machines, so they will specify 'unmanaged_ok'
472   unless unmanaged_ok
473     all_mgd = map_all_ids_to(:managed, cnx: cnx).select { |_id, mgd| mgd }.keys
474 
475     targets.each do |target_id|
476       raise Jamf::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
477     end
478   end # unles
479 
480   targets
481 end
recon(targets, api: nil, cnx: Jamf.cnx)
Alias for: update_inventory
remove_mdm_profile(targets, api: nil, cnx: Jamf.cnx)
Alias for: unmanage_device
restart(targets, api: nil, cnx: Jamf.cnx)
Alias for: restart_device
restart_device(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a restart_device command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
925 def restart_device(targets, api: nil, cnx: Jamf.cnx)
926   cnx = api if api
927 
928   send_mdm_command targets, :restart_device, cnx: cnx
929 end
Also aliased as: restart
send_blank_push(targets, api: nil, cnx: Jamf.cnx)
Alias for: blank_push
send_command_rsrc() click to toggle source

The API rsrc for sending MDM commands to this kind of target

@return [String] The API rsrc.

    # File lib/jamf/api/classic/api_objects/mdm.rb
423 def send_command_rsrc
424   case self::MDM_COMMAND_TARGET
425   when *COMPUTER_TARGETS
426     COMPUTER_RSRC
427   when *DEVICE_TARGETS
428     DEVICE_RSRC
429   else
430     raise Jamf::InvalidDataError, "Unknown MDM command target: #{self::MDM_COMMAND_TARGET}"
431   end
432 end
send_mdm_command(targets, command, opts: {}, api: nil, cnx: Jamf.cnx) click to toggle source

Send an MDM command to one or more targets without instantiating them.

This general class method, and all the specific ones that all it, have matching instance methods. Use the class method when you don’t have, or don’t want to retrieve, instances of all the targets.

If you do have an instance or a target, call the matching instance method to send commands to that specific target.

@example send a blank push to mobiledevice id 12 without instantiating:

Jamf::MobileDevice.send_blank_push 12

@example send a blank push to mobiledevice id 12 with instantiating:

device = Jamf::MobileDevice.fetch id: 12
device.send_blank_push

@example send a blank push to computers in computer groups

'SpecialMacs' and 'FooBarGroup'

Jamf::ComputerGroup.send_blank_push ['SpecialMacs', 'FooBarGroup']

@param targets

the name or id of the device(s), or devicegroup(s) to receive the
command, or an array of such names or ids. NOTE: when calling this on a
Group class, the targets are the groups themselves, not the individual
members - the membership will be expanded.

@param command the command to send, one of the keys

of COMMANDS

@param opts Some commands require extra data, e.g. a device name.

Put it here

@param cnx [Jamf::Connection] the API connection to use. Defaults to the

currently active API, see {Jamf::Connection}

@return [Hash{Integer=>String}] Keys are the target device ids.

Values depend on the kind of target:
- Computers will have the udid of the command sent to that computer.
  The udid can be used to later retrieve info about the command.
- Mobile Devices seem to only have one command udid returned - for the
  last device to have the command sent to it. (even in the Database,
  not just in the API). So instead, the Hash value is the status of
  the command for that device, most often 'Command sent'
Blank pushes do not generate return values, so Hash values are
always 'Command sent' (an error will be raised if there are problems
sending)
    # File lib/jamf/api/classic/api_objects/mdm.rb
353 def send_mdm_command(targets, command, opts: {}, api: nil, cnx: Jamf.cnx)
354   cnx = api if api
355 
356   command = validate_command(command)
357 
358   rsrc = "#{send_command_rsrc}/command/#{command}"
359 
360   targets = raw_targets_to_ids targets, cnx: cnx
361 
362   cmd_xml = mdm_command_xml(command, opts, targets)
363 
364   if JSS.devmode?
365     puts "Sending XML:\n"
366     REXML::Document.new(cmd_xml).write STDOUT, 2
367     puts "\n\nTo rsrc: #{rsrc}"
368   end
369 
370   result = cnx.c_post rsrc, cmd_xml
371 
372   if command == BLANK_PUSH
373     hash = {}
374     targets.each { |t| hash[t] = BLANK_PUSH_RESULT }
375   elsif COMPUTER_TARGETS.include? self::MDM_COMMAND_TARGET
376     hash = process_computer_xml_result(result)
377   elsif DEVICE_TARGETS.include? self::MDM_COMMAND_TARGET
378     hash = process_mobiledevice_xml_result(result)
379   end
380 
381   hash
382 end
set_device_name(targets, name, api: nil, cnx: Jamf.cnx)
Alias for: device_name
set_name(targets, name, api: nil, cnx: Jamf.cnx)
Alias for: device_name
set_wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx)
Alias for: wallpaper
shut_down(targets, api: nil, cnx: Jamf.cnx)
Alias for: shut_down_device
shut_down_device(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send a shut_down_device command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
908 def shut_down_device(targets, api: nil, cnx: Jamf.cnx)
909   cnx = api if api
910 
911   send_mdm_command targets, :shut_down_device, cnx: cnx
912 end
Also aliased as: shutdown_device, shut_down, shutdown
shutdown(targets, api: nil, cnx: Jamf.cnx)
Alias for: shut_down_device
shutdown_device(targets, api: nil, cnx: Jamf.cnx)
Alias for: shut_down_device
unlock_user_account(targets, user, api: nil, cnx: Jamf.cnx) click to toggle source

Send an unlock_user_account command to one or more targets

@param targets @see .send_mdm_command

@param user the username of the acct to unlock

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
670 def unlock_user_account(targets, user, api: nil, cnx: Jamf.cnx)
671   cnx = api if api
672 
673   send_mdm_command targets, :unlock_user_account, opts: { user_name: user }, cnx: cnx
674 end
unmanage_device(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an Unmanage Device command to one or more targets

NOTE: when used with computers, the mdm profile will probably be re-installed immediately unless the computer is also no longer managed by Jamf Pro itself. To fully unmanage a computer, use the {Jamf::Computer#make_unmanaged} instance method.

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
650 def unmanage_device(targets, api: nil, cnx: Jamf.cnx)
651   cnx = api if api
652 
653   send_mdm_command targets, :unmanage_device, cnx: cnx
654 end
Also aliased as: remove_mdm_profile
update_inventory(targets, api: nil, cnx: Jamf.cnx) click to toggle source

Send an update_inventory command to one or more targets

@param targets @see .send_mdm_command

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
731 def update_inventory(targets, api: nil, cnx: Jamf.cnx)
732   cnx = api if api
733 
734   send_mdm_command targets, :update_inventory, cnx: cnx
735 end
Also aliased as: recon
validate_command(command) click to toggle source

Validate that this command is known and can be sent to this kind of object, raising an error if not.

@param command One of the symbolic commands as keys in COMMANDS

@return [String] the matching value for the command symbol given

    # File lib/jamf/api/classic/api_objects/mdm.rb
535 def validate_command(command)
536   raise Jamf::NoSuchItemError, "Unknown command '#{command}'" unless COMMANDS.keys.include? command
537 
538   command = COMMANDS[command]
539 
540   case self::MDM_COMMAND_TARGET
541   when *COMPUTER_TARGETS
542     return command if COMPUTER_COMMANDS.include? command
543 
544     raise Jamf::UnsupportedError, "'#{command}' cannot be sent to computers or computer groups"
545   when *DEVICE_TARGETS
546     return command if DEVICE_COMMANDS.include? command
547 
548     raise Jamf::UnsupportedError, "'#{command}' cannot be sent to mobile devices or mobile device groups"
549   end
550 
551   raise Jamf::NoSuchItemError, "'#{command}' is known, but not available for computers or mobile devices. This is a bug. Please report it."
552 end
wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx) click to toggle source

Send a wallpaper command to one or more targets

@param targets @see .send_mdm_command

@param wallpaper_setting :lock_screen, :home_screen, or :lock_and_home_screen

@param wallpaper_content The local path to a .png or .jpg to use

as the walpaper image, required if no wallpaper_id

@param wallpaper_id The id of an Icon in Jamf Pro to use as the wallpaper image,

required if no wallpaper_content

@param cnx [Jamf::Connection] the API thru which to send the command

@return (see .send_mdm_command)

    # File lib/jamf/api/classic/api_objects/mdm.rb
859 def wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx)
860   cnx = api if api
861 
862   unless WALLPAPER_LOCATIONS.keys.include? wallpaper_setting
863     raise ArgumentError,
864           "wallpaper_setting must be one of: :#{WALLPAPER_LOCATIONS.keys.join ', :'}"
865   end
866 
867   opts = { wallpaper_setting: WALLPAPER_LOCATIONS[wallpaper_setting] }
868 
869   if wallpaper_content
870     file = Pathname.new wallpaper_content
871     raise Jamf::NoSuchItemError, "Not a file: #{file}" unless file.file?
872 
873     opts[:wallpaper_content] = Base64.encode64 file.read
874   elsif wallpaper_id
875     opts[:wallpaper_id] = wallpaper_id
876   else
877     raise ArgumentError, 'Either wallpaper_id: or wallpaper_content must be provided'
878   end
879 
880   send_mdm_command targets, :wallpaper, opts: opts, cnx: cnx
881 end
Also aliased as: set_wallpaper
wipe(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx)
Alias for: erase_device
wipe_computer(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx)
Alias for: erase_device
wipe_device(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx)
Alias for: erase_device