Class: Fluent::GrowlOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_growl.rb

Constant Summary collapse

DEFAULT_SERVER =
"localhost"
DEFAULT_PASSWORD =
nil
DEFAULT_APPNAME =
"Fluent Growl Notification"
DEFAULT_NOTIFICATION_NAME =
"Fluent Defalt Notification"
DEFAULT_TITLE =
"Fluent Notification"

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fluent/plugin/out_growl.rb', line 16

def configure(conf)
	super

	server = conf['server'] || DEFAULT_SERVER
	password = conf['password'] || DEFAULT_PASSWORD
	appname = conf['appname'] || DEFAULT_APPNAME

	@notifies = {}
	conf.elements.select{|e|
		e.name = "notify"
	}.each{|e|
		name = e['name']
		unless name
			raise ConfigError, "Missing 'name' parameter on <notify> directive"
		end
		priority = e['priority'].to_i
		sticky = (e.has_key? "sticky") && (e["sticky"].match /y(es)?|on|true/i ) && true
		@notifies[name] = { :priority => priority, :sticky => sticky }
	}
	# if @notifies.empty?
	#  raise ConfigError, "At least one <notify> directive is needed"
	# end
	@notifies[DEFAULT_NOTIFICATION_NAME] = { :priority => 0, :sticky => false }

	@growl = Growl.new server, appname, @notifies.keys, nil, password
end

#emit(tag, es, chain) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fluent/plugin/out_growl.rb', line 43

def emit(tag, es, chain)
	es.each{|time,record|
		title = record["title"] || DEFAULT_TITLE
		message = record["message"] || "#{record.to_json} at #{Time.at(time).localtime}"
		notifyname = record["notify"] || DEFAULT_NOTIFICATION_NAME
		notify = @notifies[notifyname]
		unless notify
			# TODO: ConfigError?
			raise ConfigError, "Unknown notify name '#{notifyname}'"
		end

		@growl.notify notifyname, title, message, notify[:priority], notify[:sticky]
	}
	chain.next
end