systemd journal watcher daemon in ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. module JournaldWatcher
  2. class Config
  3. def initialize
  4. @data = YAML.load_file(File.dirname(__FILE__) + '/../config/config.yml')
  5. end
  6. def flags
  7. return nil unless @data['flags']
  8. @data['flags'] = [@data['flags']] unless @data['flags'].is_a? Array
  9. flags_arr = @data['flags']
  10. flags = 0
  11. flags |= Systemd::Journal::Flags::LOCAL_ONLY if flags_arr.include? 'local'
  12. flags |= Systemd::Journal::Flags::RUNTIME_ONLY if flags_arr.include? 'runtime'
  13. flags |= Systemd::Journal::Flags::SYSTEM_ONLY if flags_arr.include? 'system'
  14. flags
  15. end
  16. def filter
  17. @data['filter'] or raise 'No filter given'
  18. end
  19. def mailer_from
  20. @data['mail'] && @data['mail']['from'] or raise 'No from address given'
  21. end
  22. def mailer_to
  23. @data['mail'] && @data['mail']['to'] or raise 'No to address(es) given'
  24. end
  25. def mailer_subject
  26. @data['mail'] && @data['mail']['subject'] || ''
  27. end
  28. def min_priority
  29. priority_str = @data['min_priority']
  30. case priority_str
  31. when 'emerg'
  32. Systemd::Journal::LOG_EMERG
  33. when 'alert'
  34. Systemd::Journal::LOG_ALERT
  35. when 'crit'
  36. Systemd::Journal::LOG_CRIT
  37. when 'err'
  38. Systemd::Journal::LOG_ERR
  39. when 'warning'
  40. Systemd::Journal::LOG_WARNING
  41. when 'notice'
  42. Systemd::Journal::LOG_NOTICE
  43. when 'info'
  44. Systemd::Journal::LOG_INFO
  45. when 'debug'
  46. Systemd::Journal::LOG_DEBUG
  47. else
  48. Systemd::Journal::LOG_DEBUG
  49. end
  50. end
  51. end
  52. end