Class: WCC::SyslogNotificator

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/syslog.rb

Constant Summary collapse

LEVELS =
['crit', 'emerg', 'alert', 'err', 'warning', 'notice', 'info', 'debug']

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ SyslogNotificator

Returns a new instance of SyslogNotificator.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wcc/syslog.rb', line 7

def initialize(opts)
  if LEVELS.include?(opts) 
    @prio = opts
    @enable = true
  else
    @enable = false
    raise ArgumentError, "The given priority '#{opts}' is not known, use one of: #{LEVELS.join(', ')}."
  end
  begin
    # from ruby std lib
    require 'syslog'
  rescue LoadError
    @enable = false
    raise ArgumentError, "Won't log to syslog since your system does NOT support syslog!"
  end
end

Class Method Details

.parse_conf(conf) ⇒ Object



31
# File 'lib/wcc/syslog.rb', line 31

def self.parse_conf(conf); {} end

.shut_downObject



33
# File 'lib/wcc/syslog.rb', line 33

def self.shut_down; end

Instance Method Details

#notify!(data) ⇒ Object

TODO: ERB template for syslog



25
26
27
28
29
# File 'lib/wcc/syslog.rb', line 25

def notify!(data)
  Syslog.open(data.tag, Syslog::LOG_PID | Syslog::LOG_CONS) do |s|
    s.send(@prio.to_sym, "Change at #{data.site.uri.to_s} (tag #{data.site.id}) detected")
  end if @enable
end