Module: Jamf::MDM::ClassMethods
- Defined in:
- lib/jamf/api/classic/api_objects/mdm.rb,
lib/jamf/api/classic/api_objects/mdm_classic.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.
Class Method Summary collapse
-
.extended(extender) ⇒ Object
when this module is included, also extend our Class Methods.
Instance Method Summary collapse
-
#blank_push(targets, api: nil, cnx: Jamf.cnx) ⇒ see .send_mdm_command
(also: #send_blank_push, #noop)
Send a blank push to one or more targets.
-
#clear_passcode(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an clear_passcode command to one or more targets.
-
#clear_restrictions_password(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an clear_restrictions_password command to one or more targets.
-
#delete_user(targets, user, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send a delete_user command to one or more targets.
-
#device_lock(targets, passcode: '', message: nil, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #lock_device, #lock)
Send a Device Lock to one or more targets.
-
#device_name(targets, name, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #set_name, #set_device_name)
Send a device_name command to one or more targets.
-
#disable_app_analytics(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send a disable_app_analytics command to one or more targets.
-
#disable_data_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send andisable_data_roaming command to one or more targets.
-
#disable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send a disable_diagnostic_submission command to one or more targets.
-
#disable_lost_mode(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send a disable_lost_mode command to one or more targets.
-
#disable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send a disable_remote_desktop command to one or more targets.
-
#disable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send a disable_voice_roaming command to one or more targets.
-
#enable_app_analytics(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an enable_app_analytics command to one or more targets.
-
#enable_data_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an enable_data_roaming command to one or more targets.
-
#enable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an enable_diagnostic_submission command to one or more targets.
-
#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.
-
#enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an enable_remote_desktop command to one or more targets.
-
#enable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an enable_voice_roaming command to one or more targets.
-
#erase_device(targets, passcode: '', preserve_data_plan: false, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #wipe, #wipe_device, #erase, #wipe_computer)
Send an Erase Device command to one or more targets.
-
#flush_mdm_commands(targets, status: nil, api: nil, cnx: Jamf.cnx) ⇒ void
Flush pending or failed commands on devices or groups.
-
#mdm_command_xml(command, options, targets) ⇒ String
Generate the XML to send to the API, sending the MDM command to the targets.
-
#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.
-
#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.
-
#process_computer_xml_result(result) ⇒ Hash{Integer=>String}
Convert the result of senting a computer MDM command into the appropriate hash.
-
#process_mobiledevice_xml_result(result) ⇒ Hash{Integer=>String}
Convert the result of senting a device MDM command into the appropriate hash.
-
#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.
-
#raw_targets_to_mgmt_ids(targets, expand_groups: true, unmanaged_ok: false, jamf_ids: false, api: nil, cnx: Jamf.cnx) ⇒ Array<String,Integer>
Convert the targets provided for sending a command into the final list of computer or mobile device management ids.
-
#restart_device(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #restart)
Send a restart_device command to one or more targets.
-
#send_command_rsrc ⇒ String
The API rsrc for sending MDM commands to this kind of target.
-
#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.
-
#shut_down_device(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #shutdown_device, #shut_down, #shutdown)
Send a shut_down_device command to one or more targets.
-
#unlock_user_account(targets, user, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an unlock_user_account command to one or more targets.
-
#unmanage_device(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #remove_mdm_profile)
Send an Unmanage Device command to one or more targets.
-
#update_inventory(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #recon)
Send an update_inventory command to one or more targets.
-
#validate_command(command) ⇒ String
Validate that this command is known and can be sent to this kind of object, raising an error if not.
-
#wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
(also: #set_wallpaper)
Send a wallpaper command to one or more targets.
Class Method Details
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
560 561 562 563 564 565 566 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 560 def blank_push(targets, api: nil, cnx: Jamf.cnx) cnx = api if api targets = raw_targets_to_mgmt_ids targets, cnx: cnx data = { clientManagementIds: targets } cnx.jp_post BLANK_PUSH_RSRC, data end |
#clear_passcode(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an clear_passcode command to one or more targets
790 791 792 793 794 795 796 797 798 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 790 def clear_passcode(targets, unlock_token:, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: CLEAR_PASSCODE, unlockToken: unlock_token } send_mdm_command targets, data, 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
808 809 810 811 812 813 814 815 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 808 def clear_restrictions_password(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: CLEAR_RESTRICTIONS_PASSWORD } send_mdm_command targets, data, 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
715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 715 def delete_user(targets, user = nil, force: false, all: false, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: DELETE_USER, userName: user, forceDeletion: force, deleteAllUsers: all } send_mdm_command targets, data, 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
584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 584 def device_lock(targets, passcode: nil, message: nil, phoneNumber: nil, api: nil, cnx: Jamf.cnx) cnx = api if api cmd_data = { commandType: DEVICE_LOCK } cmd_data[:message] = if cmd_data[:phoneNumber] = phoneNumber if phoneNumber cmd_data[:pin] = passcode unless passcode.pix_empty? send_mdm_command(targets, cmd_data, 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
902 903 904 905 906 907 908 909 910 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 902 def device_name(targets, name, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, deviceName: name } send_mdm_command targets, data, 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
1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1075 def disable_app_analytics(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, appAnalytics: DISABLE_APP_ANALYTICS } send_mdm_command targets, data, 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
843 844 845 846 847 848 849 850 851 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 843 def disable_data_roaming(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, dataRoaming: DISABLE_DATA_ROAMING } send_mdm_command targets, data, 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
1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1111 def disable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, diagnosticSubmission: DISABLE_DIAGNOSTIC_SUBMISSION } send_mdm_command targets, data, 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
1192 1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1192 def disable_lost_mode(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: DISABLE_LOST_MODE } send_mdm_command targets, data, 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
752 753 754 755 756 757 758 759 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 752 def disable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: DISABLE_REMOTE_DESKTOP } send_mdm_command targets, data, 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
879 880 881 882 883 884 885 886 887 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 879 def disable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, voiceRoaming: DISABLE_VOICE_ROAMING } send_mdm_command targets, data, 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
1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1057 def enable_app_analytics(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, appAnalytics: ENABLE_APP_ANALYTICS } send_mdm_command targets, data, 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
825 826 827 828 829 830 831 832 833 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 825 def enable_data_roaming(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, dataRoaming: ENABLE_DATA_ROAMING } send_mdm_command targets, data, 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
1093 1094 1095 1096 1097 1098 1099 1100 1101 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1093 def enable_diagnostic_submission(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, diagnosticSubmission: ENABLE_DIAGNOSTIC_SUBMISSION } send_mdm_command targets, data, 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
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1141 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 data = { commandType: ENABLE_LOST_MODE } data[:lostModeMessage] = if data[:lostModePhone] = phone if phone data[:lostModeFootnote] = footnote if footnote result = send_mdm_command targets, data, cnx: cnx return result unless play_sound sound_result = play_lost_mode_sound targets, cnx: cnx { enable_lost_mode: result, play_lost_mode_sound: sound_result } end |
#enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) ⇒ Hash{Integer=>String}
Send an enable_remote_desktop command to one or more targets
735 736 737 738 739 740 741 742 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 735 def enable_remote_desktop(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: ENABLE_REMOTE_DESKTOP } send_mdm_command targets, data, 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
861 862 863 864 865 866 867 868 869 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 861 def enable_voice_roaming(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, voiceRoaming: ENABLE_VOICE_ROAMING } send_mdm_command targets, data, 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
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 615 def erase_device( targets, passcode: nil, preserve_data_plan: false, disallow_proximity_setup: false, obliteration_behavior: 'Default', return_to_service: nil, api: nil, cnx: Jamf.cnx ) cnx = api if api return_to_service ||= { enabled: false } cmd_data = { commandType: ERASE_DEVICE, preserveDataPlan: preserve_data_plan, disallowProximitySetup: disallow_proximity_setup, obliterationBehavior: obliteration_behavior, returnToService: return_to_service } cmd_data[:pin] = passcode if passcode send_mdm_command(targets, cmd_data, 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
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1219 def flush_mdm_commands(targets, status:, 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_mgmt_ids method, so that we can # use this to flush commands for unmanaged machines. target_ids = raw_targets_to_mgmt_ids targets, cnx: cnx, jamf_ids: true, 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
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 483 def mdm_command_xml(command, , 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 xml.root.name = command_elem cmd_xml = xml.root general = cmd_xml.add_element GENERAL_ELEMENT general.add_element(COMMAND_ELEMENT).text = command .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
987 988 989 990 991 992 993 994 995 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 987 def passcode_lock_grace_period(targets, secs, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SETTINGS, passcodeLockGracePeriod: secs } send_mdm_command targets, data, 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
1175 1176 1177 1178 1179 1180 1181 1182 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1175 def play_lost_mode_sound(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: PLAY_LOST_MODE_SOUND } send_mdm_command targets, data, cnx: cnx end |
#process_computer_xml_result(result) ⇒ Hash{Integer=>String}
Convert the result of senting a computer MDM command into the appropriate hash
373 374 375 376 377 378 379 380 381 |
# File 'lib/jamf/api/classic/api_objects/mdm_classic.rb', line 373 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
390 391 392 393 394 395 396 397 398 399 |
# File 'lib/jamf/api/classic/api_objects/mdm_classic.rb', line 390 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.
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/jamf/api/classic/api_objects/mdm_classic.rb', line 427 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 && 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 |
#raw_targets_to_mgmt_ids(targets, expand_groups: true, unmanaged_ok: false, jamf_ids: false, api: nil, cnx: Jamf.cnx) ⇒ Array<String,Integer>
Convert the targets provided for sending a command into the final list of computer or mobile device management ids
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 379 def raw_targets_to_mgmt_ids(targets, expand_groups: true, unmanaged_ok: false, jamf_ids: 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 target_ids = [] this_is_a_group_class = GROUP_TARGETS.include?(self::MDM_COMMAND_TARGET) targets.each do |ident| id = valid_id ident, cnx: cnx raise Jamf::NoSuchItemError, "No #{self} matches identifier: #{ident}" unless id if this_is_a_group_class target_ids += fetch(id: id).member_ids else target_ids << id end 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 # get all managed ids in an array all_mgd = map_all_ids_to(:managed, cnx: cnx).select { |_id, mgd| mgd }.keys target_ids.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 # unless # return the jamf ids if requested return target_ids if jamf_ids # return the management id for each target target_ids.map { |t| management_id t, cnx: cnx } 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
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1031 def restart_device(targets, rebuild_kernel_cache: false, kext_paths: nil, notify_user: true, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: RESTART_DEVICE, rebuildKernelCache: rebuild_kernel_cache, notifyUser: notify_user } if kext_paths raise ArgumentError, 'kext_paths must be an Array of Strings' unless kext_paths.is_a?(Array) && kext_paths.all? { |kp| kp.is_a? String } data[:kextPaths] = kext_paths end send_mdm_command targets, data, cnx: cnx end |
#send_command_rsrc ⇒ String
The API rsrc for sending MDM commands to this kind of target
405 406 407 408 409 410 411 412 413 414 |
# File 'lib/jamf/api/classic/api_objects/mdm_classic.rb', line 405 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.
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 347 def send_mdm_command(targets, command_data, api: nil, cnx: Jamf.cnx) cnx = api if api targets = raw_targets_to_mgmt_ids(targets, cnx: cnx) targets.map! { |mid| { managementId: mid } } data = { clientData: targets, commandData: command_data } puts "Sending data:\n#{data}" if JSS.devmode? cnx.jp_post MDM_COMMAND_RSRC, data 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
1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 1005 def shut_down_device(targets, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: SHUT_DOWN_DEVICE } send_mdm_command targets, data, 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
693 694 695 696 697 698 699 700 701 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 693 def unlock_user_account(targets, user, api: nil, cnx: Jamf.cnx) cnx = api if api data = { commandType: UNLOCK_USER_ACCOUNT, userName: user } send_mdm_command targets, data, 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.
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 658 def unmanage_device(targets, api: nil, cnx: Jamf.cnx) cnx = api if api target_ids = raw_targets_to_mgmt_ids targets, jamf_ids: true, cnx: cnx results = [] computer_targets = COMPUTER_TARGETS.include?(self::MDM_COMMAND_TARGET) target_ids.each do |tid| rsrc = if computer_targets "#{COMPUTER_INV_RSRC}/#{tid}/#{UNMANAGE_COMPUTER_RSRC}" else "#{MOBILE_DEVICE_RSRC}/#{tid}/#{UNMANAGE_MOBILE_DEVICE_RSRC}" end results << cnx.jp_post(rsrc) end results 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
775 776 777 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 775 def update_inventory(_targets, api: nil, cnx: Jamf.cnx) raise Jamf::UnsupportedError, 'The Jamf Pro no longer uses an MDM command to update MobileDevice inventory.' 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.
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 525 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
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/jamf/api/classic/api_objects/mdm.rb', line 932 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 targets = raw_targets_to_mgmt_ids targets, jamf_ids: true, cnx: cnx cmd_xml = mdm_command_xml(:Wallpaper, opts, targets) rsrc = 'mobiledevicecommands/command/Wallpaper' if JSS.devmode? puts "Sending XML:\n" REXML::Document.new(cmd_xml).write STDOUT, 2 puts "\n\nTo rsrc: #{rsrc}" end xml_resp = cnx.c_post rsrc, cmd_xml hash = {} mds = REXML::Document.new(xml_resp).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 |