lib/sfpagent/agent.rb in sfpagent-0.1.5 vs lib/sfpagent/agent.rb in sfpagent-0.1.6
- old
+ new
@@ -4,10 +4,11 @@
require 'openssl'
require 'thread'
require 'uri'
require 'net/http'
require 'logger'
+require 'json'
module Sfp
module Agent
NetHelper = Object.new.extend(Nuri::Net::Helper)
@@ -240,16 +241,17 @@
#
# @param action contains the action's schema.
#
def self.execute_action(action)
logger = (@@config[:daemon] ? @@logger : Logger.new(STDOUT))
+ action_string = "#{action['name']} #{JSON.generate(action['parameters'])}"
begin
result = @@runtime.execute_action(action)
- logger.info "Executing #{action['name']} " + (result ? "[OK]" : "[Failed]")
+ logger.info "Executing #{action_string} " + (result ? "[OK]" : "[Failed]")
return result
rescue Exception => e
- logger.info "Executing #{action['name']} [Failed] #{e}\n#{e.backtrace.join("\n")}"
+ logger.info "Executing #{action_string} [Failed] #{e}\n#{e.backtrace.join("\n")}"
logger.error "#{e}\n#{e.bracktrace.join("\n")}"
end
false
end
@@ -259,29 +261,28 @@
# :dir => directory that holds all modules
#
def self.load_modules(p={})
dir = p[:modules_dir]
- logger = @@logger # (p[:daemon] ? @@logger : Logger.new(STDOUT))
@@modules = []
counter = 0
if dir != '' and File.exist?(dir)
- logger.info "Modules directory: #{dir}"
+ @@logger.info "Modules directory: #{dir}"
Dir.entries(dir).each { |name|
next if name == '.' or name == '..' or File.file?("#{dir}/#{name}")
module_file = "#{dir}/#{name}/#{name}.rb"
next if not File.exist?(module_file)
begin
load module_file #require module_file
- logger.info "Loading module #{dir}/#{name} [OK]"
+ @@logger.info "Loading module #{dir}/#{name} [OK]"
counter += 1
@@modules << name
rescue Exception => e
- logger.warn "Loading module #{dir}/#{name} [Failed]\n#{e}"
+ @@logger.warn "Loading module #{dir}/#{name} [Failed]\n#{e}"
end
}
end
- logger.info "Successfully loading #{counter} modules."
+ @@logger.info "Successfully loading #{counter} modules."
end
def self.get_schemata(module_name)
dir = @@config[:modules_dir]