Module: Jamf::MDM::ClassMethods

Defined in:
lib/jamf/api/classic/api_objects/mdm.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#blank_push(targets, api: nil, cnx: Jamf.cnx) ⇒ see .send_mdm_command Also known as: send_blank_push, noop

Send a blank push to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:



569
570
571
572
573
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 569

def blank_push(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :blank_push, cnx: cnx
end

#clear_passcode(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an clear_passcode command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



746
747
748
749
750
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 746

def clear_passcode(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :clear_passcode, cnx: cnx
end

#clear_restrictions_password(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an clear_restrictions_password command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



760
761
762
763
764
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 760

def clear_restrictions_password(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :clear_restrictions_password, cnx: cnx
end

#delete_user(targets, user, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a delete_user command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • user (String)

    the username of the acct to delete

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



686
687
688
689
690
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 686

def delete_user(targets, user, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :delete_user, opts: { user_name: user }, cnx: cnx
end

#device_lock(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: lock_device, lock

Send a Device Lock to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • passcode (String) (defaults to: '')

    a six-char passcode, required for computers & computergroups

  • message (String) (defaults to: nil)

    An optional message to display on mobiledevices & mobiledevicegroups

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 589

def device_lock(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  case self::MDM_COMMAND_TARGET
  when *COMPUTER_TARGETS
    raise Jamf::InvalidDataError, 'Locking computers requires a 6-character String passcode' unless passcode.size == 6

    opts = { passcode: passcode }
  when *DEVICE_TARGETS
    opts = {}
    opts[:lock_message] = message if message
  end # case
  send_mdm_command targets, :device_lock, opts: opts, cnx: cnx
end

#device_name(targets, name, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: set_name, set_device_name

Send a device_name command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • name (String)

    The new name

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



835
836
837
838
839
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 835

def device_name(targets, name, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :device_name, opts: { device_name: name }, cnx: cnx
end

#disable_app_analytics(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a disable_app_analytics command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



954
955
956
957
958
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 954

def disable_app_analytics(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :disable_app_analytics, cnx: cnx
end

#disable_data_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send andisable_data_roaming command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



788
789
790
791
792
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 788

def disable_data_roaming(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :disable_data_roaming, cnx: cnx
end

#disable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a disable_diagnostic_submission command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



982
983
984
985
986
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 982

def disable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :disable_diagnostic_submission, cnx: cnx
end

#disable_lost_mode(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a disable_lost_mode command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



1053
1054
1055
1056
1057
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1053

def disable_lost_mode(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :disable_lost_mode, cnx: cnx
end

#disable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a disable_remote_desktop command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



714
715
716
717
718
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 714

def disable_remote_desktop(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :disable_remote_desktop, cnx: cnx
end

#disable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a disable_voice_roaming command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



816
817
818
819
820
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 816

def disable_voice_roaming(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :disable_voice_roaming, cnx: cnx
end

#enable_app_analytics(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an enable_app_analytics command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



940
941
942
943
944
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 940

def enable_app_analytics(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :enable_app_analytics, cnx: cnx
end

#enable_data_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an enable_data_roaming command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



774
775
776
777
778
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 774

def enable_data_roaming(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :enable_data_roaming, cnx: cnx
end

#enable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an enable_diagnostic_submission command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



968
969
970
971
972
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 968

def enable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :enable_diagnostic_submission, cnx: cnx
end

#enable_lost_mode(targets, message: nil, phone: nil, footnote: nil, play_sound: false, enforce_lost_mode: false, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a enable_lost_mode command to one or more targets

Either or both of message and phone number must be provided

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • message (String) (defaults to: nil)

    The message to display on the lock screen

  • phone (String) (defaults to: nil)

    The phone number to display on the lock screen

  • footnote (String) (defaults to: nil)

    Optional footnote to display on the lock screen

  • play_sound (Boolean) (defaults to: false)

    Play a sound when entering lost mode

  • enforce_lost_mode (Boolean) (defaults to: false)

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

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)

Raises:

  • (ArgumentError)


1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1008

def enable_lost_mode(
  targets,
  message: nil,
  phone: nil,
  footnote: nil,
  play_sound: false,
  enforce_lost_mode: false,
  api: nil,
  cnx: Jamf.cnx
)
  cnx = api if api

  raise ArgumentError, 'Either message: or phone_number: must be provided' unless message || phone

  opts = { always_enforce_lost_mode: enforce_lost_mode }
  opts[:lost_mode_message] = message if message
  opts[:lost_mode_phone] = phone if phone
  opts[:lost_mode_footnote] = footnote if footnote
  opts[:lost_mode_with_sound] = 'true' if play_sound

  send_mdm_command targets, :enable_lost_mode, opts: opts, cnx: cnx
end

#enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an enable_remote_desktop command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



700
701
702
703
704
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 700

def enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :enable_remote_desktop, cnx: cnx
end

#enable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an enable_voice_roaming command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



802
803
804
805
806
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 802

def enable_voice_roaming(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :enable_voice_roaming, cnx: cnx
end

#erase_device(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: wipe, wipe_device, erase, wipe_computer

Send an Erase Device command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • passcode (String) (defaults to: '')

    a six-char passcode, required for computers & computergroups

  • preserve_data_plan (Boolean) (defaults to: false)

    Should the data plan of the mobile device be preserved?

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



618
619
620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 618

def erase_device(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  case self::MDM_COMMAND_TARGET
  when *COMPUTER_TARGETS
    raise Jamf::InvalidDataError, 'Erasing computers requires a 6-character String passcode' unless passcode.size == 6

    opts = { passcode: passcode }
  when *DEVICE_TARGETS
    opts = {}
    opts[:preserve_data_plan] = 'true' if preserve_data_plan
  end # case
  send_mdm_command targets, :erase_device, opts: opts, cnx: cnx
end

#flush_mdm_commands(targets, status: nil, api: nil, cnx: Jamf.cnx) ⇒ void

This method returns an undefined value.

Flush pending or failed commands on devices or groups

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    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.

  • status (String) (defaults to: nil)

    a key from Commandable::FLUSHABLE_STATUSES

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    an API connection to use. Defaults to the corrently active API. See Connection

Raises:



1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1077

def flush_mdm_commands(targets, status: nil, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  raise Jamf::InvalidDataError, "Status must be one of :#{FLUSHABLE_STATUSES.keys.join ', :'}" unless FLUSHABLE_STATUSES.keys.include? status

  status = FLUSHABLE_STATUSES[status]

  # TODO: add 'unmanaged_ok:' param to raw_targets_to_ids method, so that we can
  # use this to flush commands for unmanaged machines.
  target_ids = raw_targets_to_ids targets, cnx: cnx, expand_groups: false, unmanaged_ok: true

  command_flush_rsrc = "commandflush/#{self::MDM_COMMAND_TARGET}/id"

  flush_rsrc = "#{command_flush_rsrc}/#{target_ids.join ','}/status/#{status}"

  puts "Sending API DELETE: #{flush_rsrc}" if JSS.devmode?

  cnx.c_delete flush_rsrc
end

#mdm_command_xml(command, options, targets) ⇒ String

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

Parameters:

  • command (Symbol)

    the command to be sent, a key from COMMANDS

  • options (Hash)

    different commands require different options, see each command method

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

Returns:

  • (String)

    The XML content to send to the API

Raises:



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 494

def mdm_command_xml(command, options, targets)
  raise Jamf::MissingDataError, 'Targets cannot be empty' if targets.empty?

  case self::MDM_COMMAND_TARGET
  when *COMPUTER_TARGETS
    command_elem = COMPUTER_COMMAND_ELEMENT
    target_list_elem = Jamf::Computer::RSRC_LIST_KEY.to_s
    target_elem = Jamf::Computer::RSRC_OBJECT_KEY.to_s
  when *DEVICE_TARGETS
    command_elem = DEVICE_COMMAND_ELEMENT
    target_list_elem = Jamf::MobileDevice::RSRC_LIST_KEY.to_s
    target_elem = Jamf::MobileDevice::RSRC_OBJECT_KEY.to_s
  else
    raise Jamf::NoSuchItemError, "Unknonwn MDM command target: #{self::MDM_COMMAND_TARGET}"
  end # case

  xml = REXML::Document.new Jamf::Connection::XML_HEADER
  cmd_xml = xml.add_element command_elem

  general = cmd_xml.add_element GENERAL_ELEMENT
  general.add_element(COMMAND_ELEMENT).text = command
  options.each do |opt, val|
    general.add_element(opt.to_s).text = val.to_s
  end # do opt val

  tgt_list = cmd_xml.add_element target_list_elem
  targets.each do |tgt_id|
    tgt = tgt_list.add_element(target_elem)
    tgt.add_element(TARGET_ID_ELEMENT).text = tgt_id.to_s
  end

  xml.to_s
end

#passcode_lock_grace_period(targets, secs, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a passcode_lock_grace_period command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • secs (Integer)

    The numer of seconds for the grace period

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



894
895
896
897
898
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 894

def passcode_lock_grace_period(targets, secs, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :passcode_lock_grace_period, opts: { passcode_lock_grace_period: secs }, cnx: cnx
end

#play_lost_mode_sound(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send a play_lost_mode_sound command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



1039
1040
1041
1042
1043
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1039

def play_lost_mode_sound(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :play_lost_mode_sound, cnx: cnx
end

#process_computer_xml_result(result) ⇒ Hash{Integer=>String}

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

Parameters:

  • result (String)

    The raw XML from POSTing a computer command

Returns:

  • (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)



391
392
393
394
395
396
397
398
399
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 391

def process_computer_xml_result(result)
  hash = {}
  REXML::Document.new(result).elements[COMPUTER_COMMAND_ELEMENT].each_element do |cmd|
    compid = cmd.elements[COMPUTER_ID_ELEMENT].text.to_i
    udid = cmd.elements[COMPUTER_COMMAND_UDID_ELEMENT].text
    hash[compid] = udid
  end
  hash
end

#process_mobiledevice_xml_result(result) ⇒ Hash{Integer=>String}

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

Parameters:

  • result (String)

    The raw XML from POSTing a device command

Returns:

  • (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)



408
409
410
411
412
413
414
415
416
417
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 408

def process_mobiledevice_xml_result(result)
  hash = {}
  mds = REXML::Document.new(result).elements[DEVICE_COMMAND_ELEMENT].elements[DEVICE_LIST_ELEMENT]
  mds.each_element do |md|
    id = md.elements[DEVICE_ID_ELEMENT].text.to_i
    status = md.elements[DEVICE_COMMAND_STATUS_ELEMENT].text
    hash[id] = status
  end
  hash
end

#raw_targets_to_ids(targets, expand_groups: true, unmanaged_ok: false, api: nil, cnx: Jamf.cnx) ⇒ Array<Integer>

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

Parameters:

  • targets (String, Integer, Array)
  • expand_groups (Boolean) (defaults to: true)

    Should groups be expanded into member ids?

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    an API connection to use.

Returns:

  • (Array<Integer>)

    The ids of the target devices for a command



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 445

def raw_targets_to_ids(targets, expand_groups: true, unmanaged_ok: false, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  targets = targets.is_a?(Array) ? targets : [targets]

  # flush caches before checking ids and managment
  cnx.flushcache self::RSRC_LIST_KEY

  # make sure its an array of ids
  targets.map! do |md|
    id = valid_id md, cnx: cnx
    raise Jamf::NoSuchItemError, "No #{self} matches identifier: #{md}" unless id

    id
  end # map!

  # expand group members if needed
  if expand_groups && GROUP_TARGETS.include?(self::MDM_COMMAND_TARGET)
    target_ids = []
    targets.each { |group_id| target_ids += fetch(id: group_id).member_ids }
    targets = target_ids
  end

  # make sure all of them are managed, or else the API will raise a 400
  # 'Bad Request' when sending the command to an unmanaged target.
  # Some actions, like flushing MDM commands (see .flush_mdm_commands)
  # are OK on unmanaged machines, so they will specify 'unmanaged_ok'
  unless unmanaged_ok
    all_mgd = map_all_ids_to(:managed, cnx: cnx).select { |_id, mgd| mgd }.keys

    targets.each do |target_id|
      raise Jamf::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
    end
  end # unles

  targets
end

#restart_device(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: restart

Send a restart_device command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



925
926
927
928
929
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 925

def restart_device(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :restart_device, cnx: cnx
end

#send_command_rsrcString

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

Returns:



423
424
425
426
427
428
429
430
431
432
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 423

def send_command_rsrc
  case self::MDM_COMMAND_TARGET
  when *COMPUTER_TARGETS
    COMPUTER_RSRC
  when *DEVICE_TARGETS
    DEVICE_RSRC
  else
    raise Jamf::InvalidDataError, "Unknown MDM command target: #{self::MDM_COMMAND_TARGET}"
  end
end

#send_mdm_command(targets, command, opts: {}, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

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.

Examples:

send a blank push to mobiledevice id 12 without instantiating:


Jamf::MobileDevice.send_blank_push 12

send a blank push to mobiledevice id 12 with instantiating:


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

send a blank push to computers in computer groups

'SpecialMacs' and 'FooBarGroup'

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

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    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.

  • command (Symbol)

    the command to send, one of the keys of COMMANDS

  • opts (Hash) (defaults to: {})

    Some commands require extra data, e.g. a device name. Put it here

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API connection to use. Defaults to the currently active API, see Connection

Returns:

  • (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)



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 353

def send_mdm_command(targets, command, opts: {}, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  command = validate_command(command)

  rsrc = "#{send_command_rsrc}/command/#{command}"

  targets = raw_targets_to_ids targets, cnx: cnx

  cmd_xml = mdm_command_xml(command, opts, targets)

  if JSS.devmode?
    puts "Sending XML:\n"
    REXML::Document.new(cmd_xml).write STDOUT, 2
    puts "\n\nTo rsrc: #{rsrc}"
  end

  result = cnx.c_post rsrc, cmd_xml

  if command == BLANK_PUSH
    hash = {}
    targets.each { |t| hash[t] = BLANK_PUSH_RESULT }
  elsif COMPUTER_TARGETS.include? self::MDM_COMMAND_TARGET
    hash = process_computer_xml_result(result)
  elsif DEVICE_TARGETS.include? self::MDM_COMMAND_TARGET
    hash = process_mobiledevice_xml_result(result)
  end

  hash
end

#shut_down_device(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: shutdown_device, shut_down, shutdown

Send a shut_down_device command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



908
909
910
911
912
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 908

def shut_down_device(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :shut_down_device, cnx: cnx
end

#unlock_user_account(targets, user, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}

Send an unlock_user_account command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • user (String)

    the username of the acct to unlock

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



670
671
672
673
674
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 670

def (targets, user, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :unlock_user_account, opts: { user_name: user }, cnx: cnx
end

#unmanage_device(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: remove_mdm_profile

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 Computer#make_unmanaged instance method.

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



650
651
652
653
654
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 650

def unmanage_device(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :unmanage_device, cnx: cnx
end

#update_inventory(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: recon

Send an update_inventory command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



731
732
733
734
735
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 731

def update_inventory(targets, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  send_mdm_command targets, :update_inventory, cnx: cnx
end

#validate_command(command) ⇒ String

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

Parameters:

  • command (Symbol)

    One of the symbolic commands as keys in COMMANDS

Returns:

  • (String)

    the matching value for the command symbol given

Raises:



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 535

def validate_command(command)
  raise Jamf::NoSuchItemError, "Unknown command '#{command}'" unless COMMANDS.keys.include? command

  command = COMMANDS[command]

  case self::MDM_COMMAND_TARGET
  when *COMPUTER_TARGETS
    return command if COMPUTER_COMMANDS.include? command

    raise Jamf::UnsupportedError, "'#{command}' cannot be sent to computers or computer groups"
  when *DEVICE_TARGETS
    return command if DEVICE_COMMANDS.include? command

    raise Jamf::UnsupportedError, "'#{command}' cannot be sent to mobile devices or mobile device groups"
  end

  raise Jamf::NoSuchItemError, "'#{command}' is known, but not available for computers or mobile devices. This is a bug. Please report it."
end

#wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String} Also known as: set_wallpaper

Send a wallpaper command to one or more targets

Parameters:

  • targets (String, Integer, Array<String,Integer>)

    @see .send_mdm_command

  • wallpaper_setting (Symbol) (defaults to: nil)

    :lock_screen, :home_screen, or :lock_and_home_screen

  • wallpaper_content (String, Pathname) (defaults to: nil)

    The local path to a .png or .jpg to use as the walpaper image, required if no wallpaper_id

  • wallpaper_id (Symbol) (defaults to: nil)

    The id of an Icon in Jamf Pro to use as the wallpaper image, required if no wallpaper_content

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the API thru which to send the command

Returns:

  • (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)



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 859

def wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  unless WALLPAPER_LOCATIONS.keys.include? wallpaper_setting
    raise ArgumentError,
          "wallpaper_setting must be one of: :#{WALLPAPER_LOCATIONS.keys.join ', :'}"
  end

  opts = { wallpaper_setting: WALLPAPER_LOCATIONS[wallpaper_setting] }

  if wallpaper_content
    file = Pathname.new wallpaper_content
    raise Jamf::NoSuchItemError, "Not a file: #{file}" unless file.file?

    opts[:wallpaper_content] = Base64.encode64 file.read
  elsif wallpaper_id
    opts[:wallpaper_id] = wallpaper_id
  else
    raise ArgumentError, 'Either wallpaper_id: or wallpaper_content must be provided'
  end

  send_mdm_command targets, :wallpaper, opts: opts, cnx: cnx
end