os.rb 702 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SystemReport::Plugin::Os < SystemReport::Plugin
  3. OS_RELEASE_FILE = '/etc/os-release'.freeze
  4. DESCRIPTION = __('Operating system').freeze
  5. def fetch
  6. os_release.merge(platform: RUBY_PLATFORM).deep_symbolize_keys
  7. end
  8. private
  9. def os_release
  10. return {} if !File.exist?(OS_RELEASE_FILE)
  11. os_release = File.read(OS_RELEASE_FILE)
  12. begin
  13. os_release.split("\n").to_h do |line|
  14. key, value = line.split('=')
  15. key.downcase!
  16. value.delete!('"')
  17. [key, value]
  18. end
  19. rescue
  20. Rails.logger.error("Failed to parse #{OS_RELEASE_FILE}")
  21. {}
  22. end
  23. end
  24. end