prometheus-splash 0.8.3 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -4
  3. data/README.md +400 -178
  4. data/config/splash.yml +15 -13
  5. data/lib/splash/backends/file.rb +1 -1
  6. data/lib/splash/backends.rb +7 -1
  7. data/lib/splash/cli/commands.rb +45 -80
  8. data/lib/splash/cli/config.rb +12 -1
  9. data/lib/splash/cli/daemon.rb +1 -1
  10. data/lib/splash/cli/logs.rb +34 -2
  11. data/lib/splash/cli/process.rb +33 -0
  12. data/lib/splash/cli/webadmin.rb +2 -1
  13. data/lib/splash/commands.rb +31 -22
  14. data/lib/splash/config/flush.rb +2 -2
  15. data/lib/splash/config.rb +15 -8
  16. data/lib/splash/constants.rb +1 -1
  17. data/lib/splash/daemon/orchestrator/grammar.rb +1 -1
  18. data/lib/splash/daemon/orchestrator.rb +6 -7
  19. data/lib/splash/dependencies.rb +1 -0
  20. data/lib/splash/logs.rb +5 -1
  21. data/lib/splash/monkeys.rb +5 -0
  22. data/lib/splash/processes.rb +4 -0
  23. data/lib/splash/sequences.rb +6 -1
  24. data/lib/splash/webadmin/api/routes/commands.rb +13 -1
  25. data/lib/splash/webadmin/api/routes/config.rb +95 -8
  26. data/lib/splash/webadmin/api/routes/process.rb +21 -9
  27. data/lib/splash/webadmin/main.rb +15 -1
  28. data/lib/splash/webadmin/portal/controllers/commands.rb +99 -1
  29. data/lib/splash/webadmin/portal/controllers/logs.rb +31 -4
  30. data/lib/splash/webadmin/portal/controllers/processes.rb +74 -4
  31. data/lib/splash/webadmin/portal/views/command_form.slim +45 -0
  32. data/lib/splash/webadmin/portal/views/command_history.slim +27 -0
  33. data/lib/splash/webadmin/portal/views/commands.slim +69 -19
  34. data/lib/splash/webadmin/portal/views/{logs_form.slim → log_form.slim} +3 -0
  35. data/lib/splash/webadmin/portal/views/log_history.slim +24 -0
  36. data/lib/splash/webadmin/portal/views/logs.slim +34 -7
  37. data/lib/splash/webadmin/portal/views/process_form.slim +24 -0
  38. data/lib/splash/webadmin/portal/views/process_history.slim +24 -0
  39. data/lib/splash/webadmin/portal/views/processes.slim +79 -6
  40. data/lib/splash/webadmin.rb +3 -1
  41. data/prometheus-splash.gemspec +1 -1
  42. data/templates/.env +0 -0
  43. data/templates/Dockerfile +5 -0
  44. data/templates/docker-compose.yml +14 -0
  45. metadata +18 -9
data/lib/splash/config.rb CHANGED
@@ -13,8 +13,14 @@ module Splash
13
13
 
14
14
  class ConfigLinter
15
15
  def initialize
16
- @lints_present = {:logs => [:label, :log, :pattern ]}
17
- @lints_types = {:logs => {:label => Symbol, :log => String, :pattern => String, :retention => Hash}}
16
+ @lints_present = {:logs => [:label, :log, :pattern ],
17
+ :processes => [:process, :patterns ],
18
+ :commands => [:name, :desc, :command ]}
19
+ @lints_types = {:logs => {:label => Symbol, :log => String, :pattern => String, :retention => Hash},
20
+ :processes => {:process => Symbol, :patterns => Array, :retention => Hash},
21
+ :commands => {:name => Symbol, :desc => String, :command => String, :schedule => Hash,
22
+ :retention => Hash, :on_failure => Symbol, :on_success => Symbol,
23
+ :user => String, :delegate_to => Hash}}
18
24
  end
19
25
 
20
26
  def verify(options ={})
@@ -97,15 +103,16 @@ module Splash
97
103
  end
98
104
 
99
105
 
100
- def add_log(options = {})
106
+ def add_record(options = {})
101
107
  @config_from_file = readconf @config_file
108
+ key = options[:key]
102
109
  res = ConfigLinter::new.verify(options)
103
110
  if res[:status] == :success then
104
- if @config_from_file[:logs].select{|item| item[:label] == options[:record][:label]}.count > 0 then
111
+ if @config_from_file[options[:type]].select{|item| item[options[:key]] == options[:record][options[:key]]}.count > 0 then
105
112
  return {:status => :already_exist}
106
113
  else
107
114
  res[:useless].each {|item| options[:record].delete item} if options[:clean]
108
- @config_from_file[:logs].push options[:record]
115
+ @config_from_file[options[:type]].push options[:record]
109
116
  writeconf
110
117
  hash_config_to_default
111
118
  return {:status => :success}
@@ -116,12 +123,12 @@ module Splash
116
123
  end
117
124
 
118
125
 
119
- def delete_log(options = {})
126
+ def delete_record(options = {})
120
127
  @config_from_file = readconf @config_file
121
- unless @config_from_file[:logs].select{|item| item[:label] == options[:label]}.count > 0 then
128
+ unless @config_from_file[options[:type]].select{|item| item[options[:key]] == options[options[:key]]}.count > 0 then
122
129
  return {:status => :not_found}
123
130
  else
124
- @config_from_file[:logs].delete_if {|value| options[:label] == value[:label] }
131
+ @config_from_file[options[:type]].delete_if {|value| options[options[:key]] == value[options[:key]] }
125
132
  writeconf
126
133
  hash_config_to_default
127
134
  return {:status => :success}
@@ -7,7 +7,7 @@ module Splash
7
7
  module Constants
8
8
 
9
9
  # Current splash version
10
- VERSION = "0.8.3"
10
+ VERSION = "0.8.6"
11
11
  # the path to th config file, not overridable by config
12
12
  CONFIG_FILE = "/etc/splash.yml"
13
13
  # the default execution trace_path if backend file
@@ -66,7 +66,7 @@ module Splash
66
66
  # @return [Hash] Exiter case
67
67
  def execute_command(content)
68
68
  payload = content[:payload]
69
- unless get_config.commands.include? payload[:name].to_sym
69
+ unless get_config.commands.select {|cmd| cmd[:name] == payload[:name].to_sym}.count > 0 then
70
70
  @log.item "Command not found", content[:session]
71
71
  return { :case => :not_found }
72
72
  end
@@ -84,7 +84,7 @@ module Splash
84
84
  if VERBS.include? content[:verb]
85
85
  @log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
86
86
  res = self.send content[:verb], content
87
- get_default_client.publish queue: content[:return_to], message: res.to_yaml
87
+ get_default_client.publish queue: content[:return_to], message: res.to_yaml unless content[:return_to] == :ignore
88
88
  @log.send "Result to #{content[:return_to]}.", session
89
89
  else
90
90
  @log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
@@ -155,15 +155,14 @@ module Splash
155
155
 
156
156
  # prepare commands Scheduling
157
157
  def init_commands_scheduling
158
- config = get_config.commands
159
- commands = config.select{|key,value| value.include? :schedule}.keys
158
+ commands = @config.commands.select{|command| command.include? :schedule}
160
159
  commands.each do |command|
161
- sched,value = config[command][:schedule].flatten
162
- @log.arrow "Scheduling command #{command.to_s}"
160
+ sched,value = command[:schedule].flatten
161
+ @log.arrow "Scheduling command #{command[:name].to_s}"
163
162
  @server.send sched,value do
164
163
  session = get_session
165
- @log.trigger "Executing Scheduled command #{command.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
166
- execute command: command.to_s, session: session
164
+ @log.trigger "Executing Scheduled command #{command[:name].to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
165
+ execute command: command[:name].to_s, session: session
167
166
  end
168
167
  end
169
168
  end
@@ -50,6 +50,7 @@ module Splash
50
50
 
51
51
 
52
52
  # Splash
53
+ require 'splash/monkeys'
53
54
  require 'splash/constants'
54
55
  require 'splash/helpers'
55
56
  require 'splash/config'
data/lib/splash/logs.rb CHANGED
@@ -48,6 +48,10 @@ module Splash
48
48
  @backend = get_backend :logs_trace
49
49
  end
50
50
 
51
+ def clear
52
+ @backend.del({:key => @name}) if @backend.exist?({key: @name})
53
+ end
54
+
51
55
  def purge(retention)
52
56
  retention = {} if retention.nil?
53
57
  if retention.include? :hours then
@@ -132,7 +136,7 @@ module Splash
132
136
  logsrec = LogsRecords::new item[:label]
133
137
  errors = (item[:count])? item[:count] : 0
134
138
  lines = (item[:lines])? item[:lines] : 0
135
- missing = (item[:status] = :missing)? 1 : 0
139
+ missing = (item[:status] == :missing)? 1 : 0
136
140
  file = item[:log]
137
141
  logsrec.purge(item[:retention])
138
142
  logsrec.add_record :status => item[:status],
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? !!empty? : !self
4
+ end
5
+ end
@@ -52,6 +52,10 @@ module Splash
52
52
  @backend = get_backend :process_trace
53
53
  end
54
54
 
55
+ def clear
56
+ @backend.del({:key => @name}) if @backend.exist?({key: @name})
57
+ end
58
+
55
59
  def purge(retention)
56
60
  retention = {} if retention.nil?
57
61
  if retention.include? :hours then
@@ -25,12 +25,17 @@ module Splash
25
25
  list[name][:definition].each do |step|
26
26
  log.info "STEP : #{step[:step]}",session
27
27
  if step[:on_host].nil? then
28
- command = CommandWrapper::new(step[:command].to_s)
28
+ if get_config.commands.select{|cmd| cmd[:name] == step[:command]}.count > 0 then
29
+ command = CommandWrapper::new(step[:command].to_s)
29
30
  step[:callback] = true if step[:callback].nil?
30
31
  step[:trace] = true if step[:trace].nil?
31
32
  step[:notify] = true if step[:notify].nil?
32
33
  step[:session] = session
33
34
  acase = command.call_and_notify step
35
+ else
36
+ log.error "Commmand #{step[:command]} not found, for STEP : #{step[:step]}", session
37
+ acase = splash_return :not_found
38
+ end
34
39
  else
35
40
  log.info "Remote execution of #{step[:command]} on #{step[:on_host]}", session
36
41
  begin
@@ -16,7 +16,7 @@ WebAdminApp.get '/api/commands/show/:name.?:format?' do
16
16
  log = get_logger
17
17
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
18
18
  log.call "API : commands, verb : GET, route : show, item : #{params[:name]} , format : #{format}"
19
- commands_recordset = get_config.commands[params[:name].to_sym]
19
+ commands_recordset = get_config.commands.select {|command| command[:name] == params[:name].to_sym}.first
20
20
  unless commands_recordset.nil? then
21
21
  obj = splash_return case: :quiet_exit
22
22
  obj[:data] = commands_recordset
@@ -26,3 +26,15 @@ WebAdminApp.get '/api/commands/show/:name.?:format?' do
26
26
  content_type format
27
27
  format_response(obj, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
28
28
  end
29
+
30
+ WebAdminApp.get '/api/commands/history/:name.?:format?' do
31
+ log = get_logger
32
+ format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
33
+ log.call "API : commands, verb : GET, route : history, format : #{format}"
34
+ record = Splash::Commands::CmdRecords::new(params[:name]).get_all_records
35
+ history = splash_return case: :quiet_exit, :more => "command monitoring history"
36
+ history[:data] = record
37
+ content_type format
38
+ status 201
39
+ format_response(history, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
40
+ end
@@ -27,35 +27,122 @@ WebAdminApp.post '/api/config/addlog.?:format?' do
27
27
  addlog = {}
28
28
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
29
29
  log.call "API : config, verb : POST, route : addlog, format : #{format}"
30
- res = get_config.add_log :record => YAML::load(request.body.read), :type => :logs, :clean => true
30
+ res = get_config.add_record :record => YAML::load(request.body.read), :key => :label, :type => :logs, :clean => true
31
31
  case res[:status]
32
32
  when :success
33
- addlog = splash_return case: :quiet_exit, :more => "add logs"
33
+ rehash_daemon
34
+ addlog = splash_return case: :quiet_exit, :more => "add log done"
34
35
  when :already_exist
35
- addlog = splash_return case: :already_exist, :more => "add logs"
36
+ addlog = splash_return case: :already_exist, :more => "add log twice nto allowed"
36
37
  when :failure
37
- addlog = splash_return case: :configuration_error, :more => "add logs"
38
+ addlog = splash_return case: :configuration_error, :more => "add log failed"
38
39
  addlog[:data] = res
39
40
  end
40
41
  content_type format
41
42
  format_response(addlog, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
42
43
  end
43
44
 
45
+ WebAdminApp.post '/api/config/addprocess.?:format?' do
46
+ log = get_logger
47
+ addprocess = {}
48
+ format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
49
+ log.call "API : config, verb : POST, route : addprocess, format : #{format}"
50
+ res = get_config.add_record :record => YAML::load(request.body.read), :type => :processes, :key => :process, :clean => true
51
+ case res[:status]
52
+ when :success
53
+ rehash_daemon
54
+ addprocess = splash_return case: :quiet_exit, :more => "add process done"
55
+ when :already_exist
56
+ addprocess = splash_return case: :already_exist, :more => "add process twice not allowed"
57
+ when :failure
58
+ addprocess = splash_return case: :configuration_error, :more => "add process failed"
59
+ addprocess[:data] = res
60
+ end
61
+ content_type format
62
+ format_response(addprocess, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
63
+ end
64
+
65
+ WebAdminApp.post '/api/config/addcommand.?:format?' do
66
+ log = get_logger
67
+ addcommand = {}
68
+ format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
69
+ log.call "API : config, verb : POST, route : addcommand, format : #{format}"
70
+ res = get_config.add_record :record => YAML::load(request.body.read), :type => :commands, :key => :name, :clean => true
71
+ case res[:status]
72
+ when :success
73
+ rehash_daemon
74
+ addcommand = splash_return case: :quiet_exit, :more => "add command done"
75
+ when :already_exist
76
+ addcommand = splash_return case: :already_exist, :more => "add command twice not allowed"
77
+ when :failure
78
+ addpraddcommandocess = splash_return case: :configuration_error, :more => "add command failed"
79
+ addcommand[:data] = res
80
+ end
81
+ content_type format
82
+ format_response(addcommand, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
83
+ end
84
+
85
+
44
86
 
45
87
  WebAdminApp.delete '/api/config/deletelog/:label.?:format?' do
46
88
  log = get_logger
47
89
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
48
90
  log.call "API : config, verb : DELETE, route : deletelog, format : #{format}"
49
- res = get_config.delete_log label: params[:label].to_sym
50
91
  deletelog = {}
92
+ logsrec = Splash::Logs::LogsRecords::new params[:label].to_sym
93
+ logsrec.clear
94
+ res = get_config.delete_record :type => :logs, key: :label, label: params[:label].to_sym
51
95
  case res[:status]
52
96
  when :success
53
- deletelog = splash_return case: :quiet_exit, :more => "delete logs"
97
+ rehash_daemon
98
+ deletelog = splash_return case: :quiet_exit, :more => "delete log done"
54
99
  when :not_found
55
- deletelog = splash_return case: :not_found, :more => "delete logs"
100
+ deletelog = splash_return case: :not_found, :more => "nothing done for logs"
56
101
  else
57
- deletelog = splash_return case: :configuration_error, :more => "delete logs"
102
+ deletelog = splash_return case: :configuration_error, :more => "delete log failed"
58
103
  end
59
104
  content_type format
60
105
  format_response(deletelog, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
61
106
  end
107
+
108
+ WebAdminApp.delete '/api/config/deleteprocess/:process.?:format?' do
109
+ log = get_logger
110
+ format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
111
+ log.call "API : config, verb : DELETE, route : deleteprocess, format : #{format}"
112
+ deleteprocess = {}
113
+ procrec = Splash::Processes::ProcessRecords::new params[:process].to_sym
114
+ procrec.clear
115
+ res = get_config.delete_record :type => :processes, :key => :process, process: params[:process].to_sym
116
+ case res[:status]
117
+ when :success
118
+ rehash_daemon
119
+ deleteprocess = splash_return case: :quiet_exit, :more => "delete process done"
120
+ when :not_found
121
+ deleteprocess = splash_return case: :not_found, :more => "nothing done for processes"
122
+ else
123
+ deleteprocess = splash_return case: :configuration_error, :more => "delete process failed"
124
+ end
125
+ content_type format
126
+ format_response(deleteprocess, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
127
+ end
128
+
129
+ WebAdminApp.delete '/api/config/deletecommand/:command.?:format?' do
130
+ log = get_logger
131
+ format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
132
+ log.call "API : config, verb : DELETE, route : deletecommand, format : #{format}"
133
+ deletecommand = {}
134
+ cmdrec = Splash::Commands::CmdRecords::new params[:command].to_sym
135
+ cmdrec.clear
136
+ res = get_config.delete_record :type => :commands, :key => :name, name: params[:command].to_sym
137
+ case res[:status]
138
+ when :success
139
+ rehash_daemon
140
+ deletecommand = splash_return case: :quiet_exit, :more => "delete command done"
141
+ when :not_found
142
+ deletecommand = splash_return case: :not_found, :more => "nothing done for commands"
143
+ else
144
+ deletecommand = splash_return case: :configuration_error, :more => "delete command failed"
145
+ end
146
+ content_type format
147
+ format_response(deletecommand, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
148
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- WebAdminApp.get '/api/process/list.?:format?' do
5
+ WebAdminApp.get '/api/processes/list.?:format?' do
6
6
  log = get_logger
7
7
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
8
- log.call "API : process, verb : GET, route : list, format : #{format}"
8
+ log.call "API : processes, verb : GET, route : list, format : #{format}"
9
9
  process_recordset = get_config.processes
10
10
  obj = splash_return case: :quiet_exit, :more => "Processes list"
11
11
  obj[:data] = process_recordset
@@ -13,11 +13,11 @@ WebAdminApp.get '/api/process/list.?:format?' do
13
13
  format_response(obj, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
14
14
  end
15
15
 
16
- WebAdminApp.get '/api/process/show/:name.?:format?' do
16
+ WebAdminApp.get '/api/processes/show/:name.?:format?' do
17
17
  log = get_logger
18
18
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
19
- log.call "API : process, verb : GET, route : show, item : #{params[:name]} , format : #{format}"
20
- process_recordset = get_config.processes.select{|item| item[:process] == params[:name] }
19
+ log.call "API : processes, verb : GET, route : show, item : #{params[:name]} , format : #{format}"
20
+ process_recordset = get_config.processes.select{|item| item[:process] == params[:name].to_sym }
21
21
  unless process_recordset.empty? then
22
22
  record = process_recordset.first
23
23
  obj = splash_return case: :quiet_exit
@@ -29,10 +29,10 @@ WebAdminApp.get '/api/process/show/:name.?:format?' do
29
29
  format_response(obj, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
30
30
  end
31
31
 
32
- WebAdminApp.post '/api/process/analyse.?:format?' do
32
+ WebAdminApp.post '/api/processes/analyse.?:format?' do
33
33
  log = get_logger
34
34
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
35
- log.call "API : process, verb : POST, route : analyse, format : #{format}"
35
+ log.call "API : processes, verb : POST, route : analyse, format : #{format}"
36
36
  results = Splash::Processes::ProcessScanner::new
37
37
  results.analyse
38
38
  res = results.output
@@ -43,10 +43,10 @@ WebAdminApp.post '/api/process/analyse.?:format?' do
43
43
  format_response(obj, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
44
44
  end
45
45
 
46
- WebAdminApp.post '/api/process/monitor.?:format?' do
46
+ WebAdminApp.post '/api/processes/monitor.?:format?' do
47
47
  log = get_logger
48
48
  format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
49
- log.call "API : process, verb : POST, route : monitor, format : #{format}"
49
+ log.call "API : processes, verb : POST, route : monitor, format : #{format}"
50
50
  results = Splash::Processes::ProcessScanner::new
51
51
  results.analyse
52
52
  res = splash_return results.notify
@@ -58,3 +58,15 @@ WebAdminApp.post '/api/process/monitor.?:format?' do
58
58
  content_type format
59
59
  format_response(res, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
60
60
  end
61
+
62
+ WebAdminApp.get '/api/processes/history/:process.?:format?' do
63
+ log = get_logger
64
+ format = (params[:format])? format_by_extensions(params[:format]) : format_by_extensions('json')
65
+ log.call "API : processes, verb : GET, route : history, format : #{format}"
66
+ record = Splash::Processes::ProcessRecords::new(params[:process]).get_all_records
67
+ history = splash_return case: :quiet_exit, :more => "Proces monitoring history"
68
+ history[:data] = record
69
+ content_type format
70
+ status 201
71
+ format_response(history, (params[:format])? format_by_extensions(params[:format]): request.accept.first)
72
+ end
@@ -7,6 +7,9 @@ class WebAdminApp < Sinatra::Base
7
7
  include Splash::Exiter
8
8
  include Splash::Loggers
9
9
  include Splash::Daemon::Controller
10
+ include Splash::Logs
11
+ include Splash::Processes
12
+ include Splash::Transports
10
13
 
11
14
  set :server, 'thin'
12
15
  set :port, get_config.webadmin_port
@@ -19,7 +22,18 @@ class WebAdminApp < Sinatra::Base
19
22
  rehash_config
20
23
  end
21
24
 
22
-
25
+ def rehash_daemon
26
+ status = get_processes({ :pattern => get_config.daemon_process_name}).empty?
27
+ if status == false then
28
+ transport = get_default_client
29
+ unless transport.class == Hash and transport.include? :case then
30
+ transport.publish queue: "splash.#{Socket.gethostname}.input",
31
+ message: { :verb => :reset,
32
+ :return_to => :ignore,
33
+ :queue => "splash.#{Socket.gethostname}.input" }.to_yaml
34
+ end
35
+ end
36
+ end
23
37
 
24
38
  end
25
39
 
@@ -1,9 +1,107 @@
1
- WebAdminApp.get '/commands' do
1
+ WebAdminApp.get '/commands/?:status?/?:command?' do
2
2
  get_menu 2
3
3
  log = get_logger
4
4
  log.call "WEB : commands, verb : GET, controller : /commands"
5
5
  url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/commands/list.yml"
6
6
  raw = RestClient::Request.execute(method: 'GET', url: url,timeout: 10)
7
7
  @data = YAML::load(raw)[:data]
8
+ @command_failed = params[:command] if params[:status] == 'failure'
9
+ @command_saved = params[:command] if params[:status] == 'success'
8
10
  slim :commands, :format => :html
9
11
  end
12
+
13
+ WebAdminApp.get '/get_command_history/:command' do
14
+ get_menu 2
15
+ log = get_logger
16
+ log.call "WEB : commands, verb : GET, controller : /get_command_history/:command"
17
+ @data = {}
18
+ url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/commands/history/#{params[:command].to_s}.yml"
19
+ raw = RestClient::Request.execute(method: 'GET', url: url,timeout: 10)
20
+ res = YAML::load(raw)
21
+ @data = res[:data] if res[:status] == :success
22
+ @command = params[:command].to_s
23
+ slim :command_history, :format => :html
24
+ end
25
+
26
+ WebAdminApp.get '/add_modify_command/?:command?' do
27
+ get_menu 2
28
+ log = get_logger
29
+ log.call "WEB : commands, verb : GET, controller : /add_modify_command/?:command?"
30
+ @data = {}
31
+ if params[:command] then
32
+ url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/commands/show/#{params[:command].to_s}.yml"
33
+ raw = RestClient::Request.execute(method: 'GET', url: url,timeout: 10)
34
+ res = YAML::load(raw)
35
+ @data = res[:data] if res[:status] == :success
36
+ if @data[:retention].class == Hash then
37
+ prov = @data[:retention].flatten.reverse.join(' ')
38
+ @data[:retention] = prov
39
+ end
40
+ if @data[:schedule].class == Hash then
41
+ prov = @data[:schedule].flatten.join(' ')
42
+ @data[:schedule] = prov
43
+ end
44
+ if @data[:delegate_to].class == Hash then
45
+ prov = "#{@data[:delegate_to][:remote_command]}@#{@data[:delegate_to][:host]}"
46
+ @data[:delegate_to] = prov
47
+ end
48
+ @data[:old_command] = params[:command].to_s
49
+ end
50
+ slim :command_form, :format => :html
51
+ end
52
+
53
+
54
+ WebAdminApp.post '/save_command' do
55
+ get_menu 2
56
+ log = get_logger
57
+ log.call "WEB : commands, verb : POST, controller : /save_command"
58
+ data = {}
59
+ unless params[:retention].blank?
60
+ value, key = params[:retention].split(' ')
61
+ key = (key.nil?)? :days : key.to_sym
62
+ value = value.to_i
63
+ key = :days if key == :day
64
+ key = :hours if key == :hour
65
+ if [:hours,:days].include? key then
66
+ data[:retention] = {key => value}
67
+ end
68
+ end
69
+
70
+ unless params[:schedule].blank?
71
+ key, value = params[:schedule].split(' ')
72
+ key = key.to_sym unless key.nil?
73
+ value = '' if value.nil?
74
+ if [:in,:every,:at].include? key and value.match(/\d+[m,d,s,h]/) then
75
+ data[:schedule] = {key => value }
76
+ end
77
+ end
78
+
79
+ unless params[:delegate_to].blank?
80
+ key, value = params[:delegate_to].split('@')
81
+ unless key.blank? or value.blank? then
82
+ data[:delegate_to] = {:remote_command => key.to_sym, :host => value.to_sym }
83
+ end
84
+ end
85
+
86
+ data[:desc] = params[:desc]
87
+ data[:command] = params[:command] unless params[:command].blank?
88
+ data[:on_failure] = params[:on_failure].to_sym unless params[:on_failure].blank?
89
+ data[:on_success] = params[:on_success].to_sym unless params[:on_success].blank?
90
+ data[:user] = params[:user] unless params[:user].blank?
91
+ data[:name] = params[:name].split(' ').first.to_sym
92
+ puts params.to_yaml
93
+ puts data.to_yaml
94
+ redirect "/command/failure/#{params[:name].to_s}" if data[:command].blank? and data[:delegate_to].blank?
95
+ if params[:update] then
96
+ url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/config/deletecommand/#{params[:old_command]}"
97
+ raw = RestClient::Request.execute(method: 'DELETE', url: url,timeout: 10)
98
+ end
99
+ url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/config/addcommand.yml"
100
+ raw = RestClient::Request.execute(method: 'POST', url: url,timeout: 10, payload: data.to_yaml)
101
+ res = YAML::load(raw)
102
+ if res[:status] == :success then
103
+ redirect "/commands/success/#{params[:name].to_s}"
104
+ else
105
+ redirect "/commands/failure/#{params[:name].to_s}"
106
+ end
107
+ end
@@ -21,7 +21,7 @@ end
21
21
  WebAdminApp.get '/add_modify_log/?:label?' do
22
22
  get_menu 0
23
23
  log = get_logger
24
- log.call "WEB : logs, verb : POST, controller : /add_modify_log/?:label?"
24
+ log.call "WEB : logs, verb : GET, controller : /add_modify_log/?:label?"
25
25
  @data = {}
26
26
  if params[:label] then
27
27
  url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/logs/show/#{params[:label].to_s}.yml"
@@ -29,19 +29,46 @@ WebAdminApp.get '/add_modify_log/?:label?' do
29
29
  res = YAML::load(raw)
30
30
  @data = res[:data] if res[:status] == :success
31
31
  @data[:old_label] = params[:label].to_s
32
+ if @data[:retention].class == Hash then
33
+ prov = @data[:retention].flatten.reverse.join(' ')
34
+ @data[:retention] = prov
35
+ end
32
36
  end
33
- slim :logs_form, :format => :html
37
+ slim :log_form, :format => :html
34
38
  end
35
39
 
36
40
 
41
+ WebAdminApp.get '/get_log_history/:label' do
42
+ get_menu 0
43
+ log = get_logger
44
+ log.call "WEB : logs, verb : GET, controller : /get_log_history/:label"
45
+ @data = {}
46
+ url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/logs/history/#{params[:label].to_s}.yml"
47
+ raw = RestClient::Request.execute(method: 'GET', url: url,timeout: 10)
48
+ res = YAML::load(raw)
49
+ @data = res[:data] if res[:status] == :success
50
+ @label = params[:label].to_s
51
+ slim :log_history, :format => :html
52
+ end
53
+
37
54
  WebAdminApp.post '/save_log' do
38
55
  get_menu 0
39
56
  log = get_logger
40
- log.call "WEB : logs, verb : POST, controller : /save_log/?:label?"
57
+ log.call "WEB : logs, verb : POST, controller : /save_log "
41
58
  data = {}
59
+ unless params[:retention].blank?
60
+ value, key = params[:retention].split(' ')
61
+ key = (key.nil?)? :days : key.to_sym
62
+ value = value.to_i
63
+ key = :days if key == :day
64
+ key = :hours if key == :hour
65
+ if [:hours,:days].include? key then
66
+ data[:retention] = {key => value}
67
+ end
68
+ end
42
69
  data[:log] = params[:log]
43
70
  data[:pattern] = params[:pattern]
44
- data[:label] = params[:label].to_sym
71
+ data[:label] = params[:label].split(' ').first.to_sym
45
72
  if params[:update] then
46
73
  url = "http://#{get_config.webadmin_ip}:#{get_config.webadmin_port}/api/config/deletelog/#{params[:old_label]}"
47
74
  raw = RestClient::Request.execute(method: 'DELETE', url: url,timeout: 10)