systemd journal watcher daemon in ruby
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

36 行
715 B

  1. module JournaldWatcher
  2. class App
  3. attr_reader :config
  4. def run
  5. load_config
  6. create_listener
  7. create_mailer
  8. listen
  9. end
  10. def load_config
  11. @config = Config.new
  12. end
  13. def create_listener
  14. @listener = Listener.new(
  15. Systemd::Journal.new(flags: @config.flags),
  16. @config.filter
  17. )
  18. end
  19. def create_mailer
  20. @mailer = Mailer.new(@config.mailer_from, @config.mailer_to, @config.mailer_subject)
  21. end
  22. def listen
  23. min_priority = @config.min_priority
  24. @listener.listen do |entry|
  25. @mailer.mail_entry(entry) if entry.priority.to_i <= min_priority # lower priorities have higher values
  26. end
  27. end
  28. end
  29. end