Module: Splash::ConfigUtilities

Includes:
Constants, Helpers
Included in:
CLISplash::Config, Config
Defined in:
lib/splash/config/flush.rb,
lib/splash/config/setup.rb,
lib/splash/config/service.rb,
lib/splash/config/sanitycheck.rb

Overview

moudle for Configuration utilities

Constant Summary

Constants included from Constants

Splash::Constants::AUTHOR, Splash::Constants::BACKENDS_STRUCT, Splash::Constants::CONFIG_FILE, Splash::Constants::COPYRIGHT, Splash::Constants::DAEMON_LOGMON_SCHEDULING, Splash::Constants::DAEMON_METRICS_SCHEDULING, Splash::Constants::DAEMON_PID_FILE, Splash::Constants::DAEMON_PROCESS_NAME, Splash::Constants::DAEMON_PROCMON_SCHEDULING, Splash::Constants::DAEMON_STDERR_TRACE, Splash::Constants::DAEMON_STDOUT_TRACE, Splash::Constants::DEFAULT_RETENTION, Splash::Constants::EMAIL, Splash::Constants::EXECUTION_TEMPLATE, Splash::Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Splash::Constants::LICENSE, Splash::Constants::LOGGERS_STRUCT, Splash::Constants::PID_PATH, Splash::Constants::PROMETHEUS_ALERTMANAGER_URL, Splash::Constants::PROMETHEUS_PUSHGATEWAY_URL, Splash::Constants::PROMETHEUS_URL, Splash::Constants::TRACE_PATH, Splash::Constants::TRANSPORTS_STRUCT, Splash::Constants::VERSION, Splash::Constants::WEBADMIN_IP, Splash::Constants::WEBADMIN_PID_FILE, Splash::Constants::WEBADMIN_PID_PATH, Splash::Constants::WEBADMIN_PORT, Splash::Constants::WEBADMIN_PROCESS_NAME, Splash::Constants::WEBADMIN_PROXY, Splash::Constants::WEBADMIN_STDERR_TRACE, Splash::Constants::WEBADMIN_STDOUT_TRACE

Instance Method Summary collapse

Methods included from Helpers

#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Instance Method Details

#addservice(options = {}) ⇒ Hash

clean backend configured

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (Symbol)

    the name of the backend (:redis, :file)

Returns:

  • (Hash)

    An Exiter case hash (:quiet_exit or :configuration_error)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/splash/config/service.rb', line 16

def addservice(options = {})
  local_service_file = search_file_in_gem "prometheus-splash", "templates/splashd.service"
  config = get_config
  self.extend Splash::Loggers
  log = get_logger
  log.info "Splashd Systemd Service installation"
  service_file = "splashd.service"
  systemd_path = "/etc/systemd/system"
  return { :case => :options_incompatibility, :more => "Systemd not avaible on this System" } if verify_folder({ :name => systemd_path}) == [:inexistant]
  log.item "Installing service file : #{service_file} in #{systemd_path}"
  if install_file source: local_service_file, target: "#{systemd_path}/#{service_file}", mode: "755", owner: config.user_root, group: config.group_root then
    return { :case => :quiet_exit, :more => "Splashd Systemd service installed" }
  else
    return { :case => :error_exit, :more => "Splashd Systemd service could not be installed" }
  end
end

#checkconfig(options = {}) ⇒ Hash

Sanitycheck action method for testing installation of Splash

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)

    An Exiter case hash (:splash_sanitycheck_success or :splash_sanitycheck_error)



15
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/splash/config/sanitycheck.rb', line 15

def checkconfig(options ={})
  self.extend Splash::Loggers
  log = get_logger
  log.info "Splash -> sanitycheck : "
  config = get_config
  full_res = 0
  res = verify_file(name: CONFIG_FILE, mode: "644", owner: config.user_root, group: config.group_root)
  target = "Config file : #{CONFIG_FILE}"
  if res.empty? then
    log.ok target
  else
    log.ko target
    full_res =+ 1
    log.flat "    pbm => #{res.map {|p| p.to_s}.join(',')}"
  end

  target = "PID Path : #{config[:pid_path]}"
  res = verify_folder(name: config[:pid_path], mode: "755", owner: config.user_root, group: config.group_root)
  if res.empty? then
    log.ok target
  else
    log.ko target
    full_res =+ 1
    log.flat "    pbm => #{res.map {|p| p.to_s}.join(',')}"

  end

  target =  "Trace Path : #{config[:trace_path]}"
  res = verify_folder(name: config[:trace_path], mode: "755", owner: config.user_root, group: config.group_root)
  if res.empty? then
    log.ok target
  else
    log.ko target
    full_res =+ 1
    log.flat "    pbm => #{res.map {|p| p.to_s}.join(',')}"
  end

  target = "Prometheus PushGateway Service running"
  if verify_service url: config.prometheus_pushgateway_url then
    log.ok target
  else
    log.ko target
    full_res =+ 1
  end

  if full_res > 0 then
    log.error "#{full_res} errors occured"
    return { :case => :splash_sanitycheck_error }
  else
    return { :case => :splash_sanitycheck_success}
  end
end

#flush_backend(options = {}) ⇒ Hash

clean backend action method

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (Symbol)

    the name of the backend (:redis, :file)

Returns:

  • (Hash)

    An Exiter case hash (:quiet_exit or :configuration_error)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/splash/config/flush.rb', line 14

def flush_backend(options ={})
  config = get_config
  self.extend Splash::Backends
  self.extend Splash::Loggers
  log = get_logger
  name  = (options[:name])? options[:name].to_sym : :execution_trace
  log.info "Splash backend #{name.to_s} flushing"
  backend = get_backend name
  if backend.flush then
    return { :case => :quiet_exit, :more => "Splash backend #{name.to_s} flushed" }
  else
    return { :case => :configuration_error, :more => "Splash backend #{name.to_s} can't be flushed" }
  end
end

#setupsplash(options = {}) ⇒ Hash

Setup action method for installing Splash

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :preserve (Symbol)

    flag to preserve config file during setup

Returns:

  • (Hash)

    An Exiter case hash (:splash_setup_success or :splash_setup_error)



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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/splash/config/setup.rb', line 16

def setupsplash(options = {})
  conf_in_path = search_file_in_gem "prometheus-splash", "config/splash.yml"
  full_res = 0
  puts "Splash -> setup : "
  unless options[:preserve] then
    print "* Installing Configuration file : #{CONFIG_FILE} : "
    # TODO TTY plateform
    if install_file source: conf_in_path, target: CONFIG_FILE, mode: "644", owner: user_root, group:  group_root then
      puts "[OK]"
    else
      full_res =+ 1
      puts "[KO]"
    end
  else
    puts "Config file preservation, verify your homemade templates."
  end
  config = get_config
  self.extend Splash::Loggers
  log = get_logger
  log.ok "Splash Initialisation"
  report_in_path = search_file_in_gem "prometheus-splash", "templates/report.txt"
  target =  "Installing template file : #{config.execution_template_path}"
  if install_file source: report_in_path, target: config.execution_template_path, mode: "644", owner: config.user_root, group: config.group_root then
    log.ok target
  else
    full_res =+ 1
    log.ko target
  end

  target = "Creating/Checking pid file path : #{config[:pid_path]}"
  if make_folder path: config[:pid_path], mode: "755", owner: config.user_root, group: config.group_root then
    log.ok target
  else
    full_res =+ 1
    log.ko target
  end

  target = "Creating/Checking trace file path : #{config[:trace_path]} : "
  if make_folder path: config[:trace_path], mode: "755", owner: config.user_root, group: config.group_root then
    log.ok target
  else
    full_res =+ 1
    log.ko target
  end


  if full_res > 0 then
    log.error "#{full_res} errors occured"
    return { :case => :splash_setup_error}
  else
    return { :case => :splash_setup_success }
  end

end