Module: Jamf::ManagementHistory::ClassMethods
- Defined in:
- lib/jamf/api/classic/api_objects/management_history.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
-
#app_store_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array
(also: #managed_app_history)
Wrapper for app store history for both computers and mobile devices.
-
#audit_history(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::AuditEvent>
(also: #audits)
The history of Audit events for a target.
-
#casper_imaging_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::CasperImagingLog>
The history of Casper Imaging events for a computer.
-
#casper_remote_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::CasperRemoteLog>
The history of Casper Remote events for a computer.
-
#completed_mdm_commands(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand>
(also: #completed_commands)
The history of completed mdm commands for a target.
-
#completed_policies(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
The array from .policy_logs, limited to status = :completed.
-
#computer_usage_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::ComputerUsageLog>
(also: #usage_logs)
The history of usage events for a computer.
-
#ebook_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::Ebook>
(also: #managed_ebook_history)
The history of ebooks for a mobile device.
-
#failed_app_store_apps(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
(also: #failed_managed_apps)
shortcut for app_store_app_history where status = :failed.
-
#failed_ebooks(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
(also: #failed_managed_ebooks)
shortcut for ebook_history where status = :failed.
-
#failed_mdm_commands(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand>
(also: #failed_commands)
The history of failed mdm commands for a target.
-
#failed_policies(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
The array from .policy_logs, limited to status = :failed.
-
#installed_app_store_apps(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
(also: #installed_managed_apps)
shortcut for app_store_app_history where status = :installed.
-
#installed_ebooks(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
(also: #installed_managed_ebooks)
shortcut for ebook_history where status = :installed.
-
#last_mdm_contact(ident, api: nil, cnx: Jamf.cnx) ⇒ Time?
The time of the most recently completed or failed MDM command.
-
#mac_app_store_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MacAppStoreApp>
The history of app store apps for a computer.
-
#management_history(ident, subset = nil, api: nil, cnx: Jamf.cnx) ⇒ Hash, Array
(also: #history)
Return the raw management history for a Computer or Mobile Device.
-
#mdm_command_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand>
(also: #commands, #management_command_history)
The history of mdm commands for a target.
-
#mobile_device_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MobileDeviceApp>
The history of apps for a mobile device.
-
#pending_app_store_apps(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
(also: #pending_managed_apps)
shortcut for app_store_app_history where status = :pending.
-
#pending_ebooks(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
(also: #pending_managed_ebooks)
shortcut for ebook_history where status = :pending.
-
#pending_mdm_commands(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand>
(also: #pending_commands)
The history of pending mdm commands for a target.
-
#policy_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::PolicyLog>
The history of policy execution for a computer.
-
#screen_sharing_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::ScreenSharingLog>
The history of screen sharing events for a computer.
-
#user_location_history(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::UserLocationChange>
The history of User/Location changes for a target.
Instance Method Details
#app_store_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array Also known as: managed_app_history
Wrapper for app store history for both computers and mobile devices
453 454 455 456 457 458 459 460 461 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 453 def app_store_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) cnx = api if api if self == Jamf::MobileDevice mobile_device_app_history(ident, status, cnx: cnx) else mac_app_store_app_history(ident, status, cnx: cnx) end end |
#audit_history(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::AuditEvent> Also known as: audits
The history of Audit events for a target
207 208 209 210 211 212 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 207 def audit_history(ident, api: nil, cnx: Jamf.cnx) cnx = api if api hist = management_history(ident, :audits, cnx: cnx) hist.map! { |aud| Jamf::ManagementHistory::AuditEvent.new aud } end |
#casper_imaging_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::CasperImagingLog>
The history of Casper Imaging events for a computer
506 507 508 509 510 511 512 513 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 506 def casper_imaging_logs(ident, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only computers have casper imaging logs' unless self == Jamf::Computer hist = management_history(ident, :casper_imaging_logs, cnx: cnx) hist.map! { |evt| Jamf::ManagementHistory::CasperImagingLog.new evt } end |
#casper_remote_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::CasperRemoteLog>
The history of Casper Remote events for a computer
524 525 526 527 528 529 530 531 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 524 def casper_remote_logs(ident, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only computers have casper remote logs' unless self == Jamf::Computer hist = management_history(ident, :casper_remote_logs, cnx: cnx) hist.map! { |evt| Jamf::ManagementHistory::CasperRemoteLog.new evt } end |
#completed_mdm_commands(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand> Also known as: completed_commands
The history of completed mdm commands for a target
283 284 285 286 287 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 283 def completed_mdm_commands(ident, api: nil, cnx: Jamf.cnx) cnx = api if api mdm_command_history(ident, :completed, cnx: cnx) end |
#completed_policies(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
The array from .policy_logs, limited to status = :completed
591 592 593 594 595 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 591 def completed_policies(ident, api: nil, cnx: Jamf.cnx) cnx = api if api policy_logs(ident, cnx: cnx).select { |pl| pl.status == :completed } end |
#computer_usage_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::ComputerUsageLog> Also known as: usage_logs
The history of usage events for a computer
542 543 544 545 546 547 548 549 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 542 def computer_usage_logs(ident, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only computers have usage logs' unless self == Jamf::Computer hist = management_history(ident, :computer_usage_logs, cnx: cnx) hist.map! { |evt| Jamf::ManagementHistory::ComputerUsageLog.new evt } end |
#ebook_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::Ebook> Also known as: managed_ebook_history
The history of ebooks for a mobile device
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 617 def ebook_history(ident, status = nil, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only mobile devices have ebooks' unless self == Jamf::MobileDevice hist = management_history(ident, :ebooks, cnx: cnx) if status raise Jamf::InvalidDataError, 'status must be one of :installed, :pending, or :failed' unless HIST_APP_STATUSES.include? status statuses_to_do = [status] else statuses_to_do = HIST_APP_STATUSES end # if status result = [] statuses_to_do.each do |a_status| # merge the sources of installed apps into their hashes books = if a_status == :installed instbooks = [] hist[a_status].each do |src, books_from_src| real_src = case src when HIST_RAW_SOURCE_EBOOK_IN_HOUSE then HIST_SOURCE_IN_HOUSE when HIST_RAW_SOURCE_IBOOKSTORE then HIST_SOURCE_IBOOKSTORE else HIST_SOURCE_OTHER end # case src instbooks += books_from_src.map! { |book| book[:source] = real_src } end instbooks else hist[a_status] end # now 'books' is an array of hashes of books with the same status # and if they are :installed, their source is in the hash # merge the statuses of the books into their hashes result += books.map! do |book| # set the :status in the hash book[:status] = a_status Jamf::ManagementHistory::Ebook.new book end # map do |books| end # statuses_to_do.each do |a_status| result end |
#failed_app_store_apps(ident, api: nil, cnx: Jamf.cnx) ⇒ Object Also known as: failed_managed_apps
shortcut for app_store_app_history where status = :failed
490 491 492 493 494 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 490 def failed_app_store_apps(ident, api: nil, cnx: Jamf.cnx) cnx = api if api app_store_app_history(ident, :failed, cnx: cnx) end |
#failed_ebooks(ident, api: nil, cnx: Jamf.cnx) ⇒ Object Also known as: failed_managed_ebooks
shortcut for ebook_history where status = :failed
692 693 694 695 696 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 692 def failed_ebooks(ident, api: nil, cnx: Jamf.cnx) cnx = api if api ebook_history(ident, :failed, cnx: cnx) end |
#failed_mdm_commands(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand> Also known as: failed_commands
The history of failed mdm commands for a target
315 316 317 318 319 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 315 def failed_mdm_commands(ident, api: nil, cnx: Jamf.cnx) cnx = api if api mdm_command_history(ident, :failed, cnx: cnx) end |
#failed_policies(ident, api: nil, cnx: Jamf.cnx) ⇒ Object
The array from .policy_logs, limited to status = :failed
600 601 602 603 604 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 600 def failed_policies(ident, api: nil, cnx: Jamf.cnx) cnx = api if api policy_logs(ident, cnx: cnx).select { |pl| pl.status == :failed } end |
#installed_app_store_apps(ident, api: nil, cnx: Jamf.cnx) ⇒ Object Also known as: installed_managed_apps
shortcut for app_store_app_history where status = :installed
468 469 470 471 472 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 468 def installed_app_store_apps(ident, api: nil, cnx: Jamf.cnx) cnx = api if api app_store_app_history(ident, :installed, cnx: cnx) end |
#installed_ebooks(ident, api: nil, cnx: Jamf.cnx) ⇒ Object Also known as: installed_managed_ebooks
shortcut for ebook_history where status = :installed
670 671 672 673 674 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 670 def installed_ebooks(ident, api: nil, cnx: Jamf.cnx) cnx = api if api ebook_history(ident, :installed, cnx: cnx) end |
#last_mdm_contact(ident, api: nil, cnx: Jamf.cnx) ⇒ Time?
The time of the most recently completed or failed MDM command. (knowledge of a failure means the device communicated with us)
For Mobile Devices, this seems to be the best indicator of the real last-contact time, since the last_inventory_update is changed when changes are made via the API.
336 337 338 339 340 341 342 343 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 336 def last_mdm_contact(ident, api: nil, cnx: Jamf.cnx) cnx = api if api epochs = completed_mdm_commands(ident, cnx: cnx).map { |cmd| cmd.completed_epoch } epochs += failed_mdm_commands(ident, cnx: cnx).map { |cmd| cmd.failed_epoch } epoch = epochs.max epoch ? JSS.epoch_to_time(epoch) : nil end |
#mac_app_store_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MacAppStoreApp>
The history of app store apps for a computer
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 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 356 def mac_app_store_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only computers have mac app store apps' unless self == Jamf::Computer hist = management_history(ident, :mac_app_store_applications, cnx: cnx) if status raise Jamf::InvalidDataError, 'status must be one of :installed, :pending, or :failed' unless HIST_APP_STATUSES.include? status statuses_to_do = [status] else statuses_to_do = HIST_APP_STATUSES end # if status result = [] statuses_to_do.each do |a_status| result += hist[a_status].map! do |app| # set the :status app[:status] = a_status Jamf::ManagementHistory::MacAppStoreApp.new app end # map do |cmd| end # statuses_to_do.each do |a_status| result end |
#management_history(ident, subset = nil, api: nil, cnx: Jamf.cnx) ⇒ Hash, Array Also known as: history
Return the raw management history for a Computer or Mobile Device
WARNING: It’s huge, better to use a subset.
NOTE: This returns the raw JSON data from the API, parsed into a ruby Hash. Use the subset-specific methods to retrieve more consistent arrays of ruby-jss objects for each kind of history event, e.g. Jamf::Computer.audits(id) or Jamf::MobileDevice.audits(id) to get an array of Jamf::ManagementHistory::AuditEvent objects
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 171 def management_history(ident, subset = nil, api: nil, cnx: Jamf.cnx) cnx = api if api id = valid_id ident, cnx: cnx raise Jamf::NoSuchItemError, "No #{self::RSRC_OBJECT_KEY} matches identifier: #{ident}" unless id if self == Jamf::Computer @hist_subsets ||= HIST_COMPUTER_SUBSETS @hist_rsrc ||= HIST_COMPUTER_RSRC @hist_key ||= HIST_COMPUTER_KEY else @hist_subsets ||= HIST_DEVICE_SUBSETS @hist_rsrc ||= HIST_DEVICE_RSRC @hist_key ||= HIST_DEVICE_KEY end if subset raise "Subset must be one of :#{@hist_subsets.join ', :'}" unless @hist_subsets.include? subset subset_rsrc = @hist_rsrc + "/id/#{id}/subset/#{subset}" cnx.c_get(subset_rsrc)[@hist_key][subset] else cnx.c_get(@hist_rsrc + "/id/#{id}")[@hist_key] end end |
#mdm_command_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand> Also known as: commands, management_command_history
The history of mdm commands for a target
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 242 def mdm_command_history(ident, status = nil, api: nil, cnx: Jamf.cnx) cnx = api if api subset = self == Jamf::Computer ? :commands : :management_commands hist = management_history(ident, subset, cnx: cnx) if status raise Jamf::InvalidDataError, 'status must be one of :completed, :pending, or :failed' unless HIST_MDM_STATUSES.include? status statuses_to_do = [status] else statuses_to_do = HIST_MDM_STATUSES end # if status result = [] statuses_to_do.each do |a_status| result += hist[a_status].map! do |cmd| # failed computer cmds have the error message in cmd[:status] # failed mdm commands have them in cmd[:error], where they should be cmd[:error] ||= cmd[:status] if a_status == :failed # but we always set the :status cmd[:status] = a_status Jamf::ManagementHistory::MdmCommand.new(**cmd) end # map do |cmd| end # statuses_to_do.each do |a_status| result end |
#mobile_device_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MobileDeviceApp>
The history of apps for a mobile device
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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 394 def mobile_device_app_history(ident, status = nil, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only mobile devices have mobile device apps' unless self == Jamf::MobileDevice hist = management_history(ident, :applications, cnx: cnx) if status raise Jamf::InvalidDataError, 'status must be one of :installed, :pending, or :failed' unless HIST_APP_STATUSES.include? status statuses_to_do = [status] else statuses_to_do = HIST_APP_STATUSES end # if status result = [] statuses_to_do.each do |a_status| # merge the sources of installed apps into their hashes apps = if a_status == :installed instapps = [] hist[a_status].each do |src, apps_from_src| real_src = case src when HIST_RAW_SOURCE_APP_IN_HOUSE then HIST_SOURCE_IN_HOUSE when HIST_RAW_SOURCE_APP_STORE then HIST_SOURCE_APP_STORE else HIST_SOURCE_OTHER end # case src instapps += apps_from_src.map! { |iapp| iapp[:source] = real_src } end instapps else hist[a_status] end # now 'apps' is an array of hashes of apps with the same status # and if they are :installed, their source is in the hash # merge the statuses of the apps into their hashes result += apps.map! do |app| # set the :status in the hash app[:status] = a_status Jamf::ManagementHistory::MobileDeviceApp.new app end # map do |cmd| end # statuses_to_do.each do |a_status| result end |
#pending_app_store_apps(ident, api: nil, cnx: Jamf.cnx) ⇒ Object Also known as: pending_managed_apps
shortcut for app_store_app_history where status = :pending
479 480 481 482 483 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 479 def pending_app_store_apps(ident, api: nil, cnx: Jamf.cnx) cnx = api if api app_store_app_history(ident, :pending, cnx: cnx) end |
#pending_ebooks(ident, api: nil, cnx: Jamf.cnx) ⇒ Object Also known as: pending_managed_ebooks
shortcut for ebook_history where status = :pending
681 682 683 684 685 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 681 def pending_ebooks(ident, api: nil, cnx: Jamf.cnx) cnx = api if api ebook_history(ident, :pending, cnx: cnx) end |
#pending_mdm_commands(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::MdmCommand> Also known as: pending_commands
The history of pending mdm commands for a target
299 300 301 302 303 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 299 def pending_mdm_commands(ident, api: nil, cnx: Jamf.cnx) cnx = api if api mdm_command_history(ident, :pending, cnx: cnx) end |
#policy_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::PolicyLog>
The history of policy execution for a computer
579 580 581 582 583 584 585 586 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 579 def policy_logs(ident, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only computers have policy logs' unless self == Jamf::Computer hist = management_history(ident, :policy_logs, cnx: cnx) hist.map! { |evt| Jamf::ManagementHistory::PolicyLog.new(**evt) } end |
#screen_sharing_logs(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::ScreenSharingLog>
The history of screen sharing events for a computer
561 562 563 564 565 566 567 568 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 561 def screen_sharing_logs(ident, api: nil, cnx: Jamf.cnx) cnx = api if api raise Jamf::UnsupportedError, 'Only computers have screen sharing logs' unless self == Jamf::Computer hist = management_history(ident, :screen_sharing_logs, cnx: cnx) hist.map! { |evt| Jamf::ManagementHistory::ScreenSharingLog.new evt } end |
#user_location_history(ident, api: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ManagementHistory::UserLocationChange>
The history of User/Location changes for a target
224 225 226 227 228 229 |
# File 'lib/jamf/api/classic/api_objects/management_history.rb', line 224 def user_location_history(ident, api: nil, cnx: Jamf.cnx) cnx = api if api hist = management_history(ident, :user_location, cnx: cnx) hist.map! { |evt| Jamf::ManagementHistory::UserLocationChange.new evt } end |