# coding: utf-8 Dir[File.dirname(__FILE__) + '/config/*.rb'].each {|file| require file } module Splash module Config include Splash::Helpers include Splash::Constants include Splash::ConfigUtilities # Class to manage configuration in Splash from Splash::Constants override by Yaml CONFIG class Configuration < Hash include Splash::Constants def initialize(config_file=CONFIG_FILE) config_from_file = readconf config_file self[:version] = VERSION self[:author] = "#{AUTHOR} <#{EMAIL}>" self[:copyright] = "#{COPYRIGHT} #{LICENSE}" self[:prometheus_pushgateway_host] = (config_from_file[:prometheus][:pushgateway][:host])? config_from_file[:prometheus][:pushgateway][:host] : PROMETHEUS_PUSHGATEWAY_HOST self[:prometheus_pushgateway_port] = (config_from_file[:prometheus][:pushgateway][:port])? config_from_file[:prometheus][:pushgateway][:port] : PROMETHEUS_PUSHGATEWAY_PORT self[:daemon_process_name] = (config_from_file[:daemon][:process_name])? config_from_file[:daemon][:process_name] : DAEMON_PROCESS_NAME self[:daemon_logmon_scheduling] = (config_from_file[:daemon][:logmon_scheduling])? config_from_file[:daemon][:logmon_scheduling] : DAEMON_LOGMON_SCHEDULING self[:execution_template_tokens] = EXECUTION_TEMPLATE_TOKENS_LIST self[:execution_template_path] = (config_from_file[:templates][:execution][:path])? config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE self[:pid_path] = (config_from_file[:daemon][:paths][:pid_path])? config_from_file[:daemon][:paths][:pid_path] : DAEMON_PID_PATH self[:trace_path] = (config_from_file[:daemon][:paths][:trace_path])? config_from_file[:daemon][:paths][:trace_path] : TRACE_PATH self[:pid_file] = (config_from_file[:daemon][:files][:pid_file])? config_from_file[:daemon][:files][:pid_file] : DAEMON_PID_FILE self[:stdout_trace] = (config_from_file[:daemon][:files][:stdout_trace])? config_from_file[:daemon][:files][:stdout_trace] : DAEMON_STDOUT_TRACE self[:stderr_trace] = (config_from_file[:daemon][:files][:stderr_trace])? config_from_file[:daemon][:files][:stderr_trace] : DAEMON_STDERR_TRACE self[:transports] = {} ; self[:transports].merge! TRANSPORTS_STRUCT ; self[:transports].merge! config_from_file[:transports] if config_from_file[:transports] self[:backends] = {} ; self[:backends].merge! BACKENDS_STRUCT ; self[:backends].merge! config_from_file[:backends] if config_from_file[:backends] self[:logs] = (config_from_file[:logs])? config_from_file[:logs] : {} self[:commands] = (config_from_file[:commands])? config_from_file[:commands] : {} end # @!group accessors on configurations Items def backends return self[:backends] end def transports return self[:transports] end def daemon_logmon_scheduling return self[:daemon_logmon_scheduling] end def execution_template_path return self[:execution_template_path] end def execution_template_tokens return self[:execution_template_tokens] end def logs return self[:logs] end def commands return self[:commands] end def author return self[:author] end def copyright return self[:copyright] end def version return self[:version] end def daemon_process_name return self[:daemon_process_name] end def prometheus_pushgateway_host return self[:prometheus_pushgateway_host] end def prometheus_pushgateway_port return self[:prometheus_pushgateway_port] end def full_pid_path return "#{self[:pid_path]}/#{self[:pid_file]}" end def full_stdout_trace_path return "#{self[:trace_path]}/#{self[:stdout_trace]}" end def full_stderr_trace_path return "#{self[:trace_path]}/#{self[:stderr_trace]}" end # @!endgroup private def readconf(file = CONFIG_FILE) return YAML.load_file(file)[:splash] end end # factory of Configuration Class instance # @param [String] config_file the path of the YAML Config file # @return [SPlash::Config::Configuration] def get_config(config_file=CONFIG_FILE) return Configuration::new config_file end end end