lib/perus/server/app.rb in perus-0.1.7 vs lib/perus/server/app.rb in perus-0.1.8
- old
+ new
@@ -195,29 +195,31 @@
redirect "#{url_prefix}systems/#{system.id}"
end
# create a new action
post '/systems/:id/actions' do
- action = Action.new
- action.system_id = params['id']
+ Action.add(params['id'], params)
+ redirect "#{url_prefix}systems/#{params['id']}#actions"
+ end
- if params['script_id']
- action.script_id = params['script_id']
- else
- command_config = CommandConfig.create_with_params(params)
- action.command_config_id = command_config.id
+ # create an action for all systems in a group
+ post '/groups/:id/systems/actions' do
+ group = Group.with_pk!(params['id'])
+ group.systems.each do |system|
+ Action.add(system.id, params)
end
- begin
- action.save
- rescue
- if action.command_config_id
- CommandConfig.with_pk!(action.command_config_id).destroy
- end
+ redirect "#{url_prefix}groups/#{params['id']}/systems"
+ end
+
+ # create an action for all systems
+ post '/systems/actions' do
+ System.each do |system|
+ Action.add(system.id, params)
end
- redirect "#{url_prefix}systems/#{params['id']}#actions"
+ redirect "#{url_prefix}systems"
end
# delete an action. deletion also clears any uploaded files.
delete '/systems/:system_id/actions/:id' do
action = Action.with_pk!(params['id'])
@@ -230,35 +232,30 @@
# frontend
#----------------------
# overview
get '/' do
systems = System.all
- alerts = Alert.all
- results = alerts.collect do |alert|
- begin
- alert.execute(systems)
- rescue => e
- "An error occurred running this alert: #{e.inspect}"
- end
- end
-
- @alerts = Hash[alerts.zip(results)]
+ @alerts = Alert.all.sort_by(&:severity_level).reverse
erb :index
end
# list of systems
get '/systems' do
@systems = System.all.group_by(&:orientation)
@title = 'All Systems'
+ @scripts = Script.all
+ @action_url = "systems/actions"
erb :systems
end
# list of systems by group
get '/groups/:id/systems' do
group = Group.with_pk!(params['id'])
@systems = group.systems.group_by(&:orientation)
@title = group.name
+ @scripts = Script.all
+ @action_url = "groups/#{params['id']}/systems/actions"
erb :systems
end
# info page for a system
get '/systems/:id' do
@@ -279,10 +276,10 @@
num_metrics = metrics.select(&:numeric?).map(&:name)
@num_metrics = num_metrics.group_by {|n| n.split('_')[0]}
# make links clickable
@links = @system.links.to_s.gsub("\n", "<br>")
- URI::extract(@links).each {|uri| @links.gsub!(uri, %Q{<a href="#{uri}">#{uri}</a>})}
+ URI::extract(@links).each {|uri| @links.gsub!(uri, %Q{<a href="#{uri}" target="_new">#{uri}</a>})}
# last updated is a timestamp, conver
if @system.last_updated
@last_updated = Time.at(@system.last_updated).ctime
else