Class: Cfruby::Cfp_FlowMonitor

Inherits:
FlowMonitor::Observer show all
Defined in:
lib/libcfenjin/cfp_flowmonitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Cfp_FlowMonitor

Returns a new instance of Cfp_FlowMonitor.



11
12
13
14
# File 'lib/libcfenjin/cfp_flowmonitor.rb', line 11

def initialize(logger)
	@logger = logger
	Cfruby.controller.register(self)
end

Instance Method Details

#handle_message(message) ⇒ Object

Every message from any controller this observer is registered with is passed through handle_message. This is a simple implementation that logs every message, and



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/libcfenjin/cfp_flowmonitor.rb', line 19

def handle_message(message)
	if(message.type == 'exception')
		@logger.error(LOG_ERR,message.message)
		return()
	end

	# If the message has a type of intention, then we have the chance to
	# basically say "NO" to the action.  In this case we are going to
	# say no to any intention that references the filename 'notouch'.  We could
	# in theory filter on any aspect of the message (the type, the tags, or
	# the content of the message itself), but in this case a simple regex hack
	# for example purposes will do nicely
	if(message.type == 'intention')

		# we can only really block intentions, so only bother checking
		# if the message is an intention

		@logger.notify(VERBOSE_MAJOR,message.message)
	elsif (message.type == 'info')
		if(message.message =~ /^search|lock|backup/)
			# overrule status of these
			@logger.notify(VERBOSE_MINOR,message.message)
		else
			@logger.notify(VERBOSE_CRITICAL,message.message)
		end
	elsif (message.type == 'verbose')
		@logger.notify(VERBOSE_MAJOR,message.message)
	elsif (message.type == 'debug')
		@logger.notify(VERBOSE_MINOR,message.message)
	else
		@logger.notify(VERBOSE_MINOR,message.message)
	end
	true
end