@@ -133,4 +133,10 @@ span.not-applicable:after {
|
||
| 133 | 133 |
position: relative; |
| 134 | 134 |
width: 940px; |
| 135 | 135 |
height: 400px; |
| 136 |
-} |
|
| 136 |
+} |
|
| 137 |
+ |
|
| 138 |
+// Disabled |
|
| 139 |
+ |
|
| 140 |
+.agent-disabled {
|
|
| 141 |
+ opacity: 0.5; |
|
| 142 |
+} |
@@ -113,7 +113,13 @@ class AgentsController < ApplicationController |
||
| 113 | 113 |
|
| 114 | 114 |
respond_to do |format| |
| 115 | 115 |
if @agent.update_attributes(params[:agent]) |
| 116 |
- format.html { redirect_to agents_path, notice: 'Your Agent was successfully updated.' }
|
|
| 116 |
+ format.html {
|
|
| 117 |
+ if params[:return] == "show" |
|
| 118 |
+ redirect_to agent_path(@agent), notice: 'Your Agent was successfully updated.' |
|
| 119 |
+ else |
|
| 120 |
+ redirect_to agents_path, notice: 'Your Agent was successfully updated.' |
|
| 121 |
+ end |
|
| 122 |
+ } |
|
| 117 | 123 |
format.json { head :no_content }
|
| 118 | 124 |
else |
| 119 | 125 |
format.html { render action: "edit" }
|
@@ -8,10 +8,12 @@ module ApplicationHelper |
||
| 8 | 8 |
end |
| 9 | 9 |
|
| 10 | 10 |
def working(agent) |
| 11 |
- if agent.working? |
|
| 11 |
+ if agent.disabled? |
|
| 12 |
+ '<span class="label label-warning">Disabled</span>'.html_safe |
|
| 13 |
+ elsif agent.working? |
|
| 12 | 14 |
'<span class="label label-success">Yes</span>'.html_safe |
| 13 | 15 |
else |
| 14 |
- link_to '<span class="label label-warning">No</span>'.html_safe, agent_path(agent, :tab => (agent.recent_error_logs? ? 'logs' : 'details')) |
|
| 16 |
+ link_to '<span class="label btn-danger">No</span>'.html_safe, agent_path(agent, :tab => (agent.recent_error_logs? ? 'logs' : 'details')) |
|
| 15 | 17 |
end |
| 16 | 18 |
end |
| 17 | 19 |
end |
@@ -22,16 +22,20 @@ module DotHelper |
||
| 22 | 22 |
'"%s"' % string.gsub(/\\/, "\\\\\\\\").gsub(/"/, "\\\\\"") |
| 23 | 23 |
end |
| 24 | 24 |
|
| 25 |
+ def disabled_label(agent) |
|
| 26 |
+ agent.disabled? ? dot_id(agent.name + " (Disabled)") : dot_id(agent.name) |
|
| 27 |
+ end |
|
| 28 |
+ |
|
| 25 | 29 |
def agents_dot(agents, rich = false) |
| 26 | 30 |
"digraph foo {".tap { |dot|
|
| 27 | 31 |
agents.each.with_index do |agent, index| |
| 28 | 32 |
if rich |
| 29 |
- dot << '%s[URL=%s];' % [dot_id(agent.name), dot_id(agent_path(agent.id))] |
|
| 33 |
+ dot << '%s[URL=%s];' % [disabled_label(agent), dot_id(agent_path(agent.id))] |
|
| 30 | 34 |
else |
| 31 |
- dot << '%s;' % dot_id(agent.name) |
|
| 35 |
+ dot << '%s;' % disabled_label(agent) |
|
| 32 | 36 |
end |
| 33 | 37 |
agent.receivers.each do |receiver| |
| 34 |
- dot << "%s->%s;" % [dot_id(agent.name), dot_id(receiver.name)] |
|
| 38 |
+ dot << "%s->%s;" % [disabled_label(agent), disabled_label(receiver)] |
|
| 35 | 39 |
end |
| 36 | 40 |
end |
| 37 | 41 |
dot << "}" |
@@ -22,7 +22,7 @@ class Agent < ActiveRecord::Base |
||
| 22 | 22 |
|
| 23 | 23 |
EVENT_RETENTION_SCHEDULES = [["Forever", 0], ["1 day", 1], *([2, 3, 4, 5, 7, 14, 21, 30, 45, 90, 180, 365].map {|n| ["#{n} days", n] })]
|
| 24 | 24 |
|
| 25 |
- attr_accessible :options, :memory, :name, :type, :schedule, :source_ids, :keep_events_for, :propagate_immediately |
|
| 25 |
+ attr_accessible :options, :memory, :name, :type, :schedule, :disabled, :source_ids, :keep_events_for, :propagate_immediately |
|
| 26 | 26 |
|
| 27 | 27 |
json_serialize :options, :memory |
| 28 | 28 |
|
@@ -86,8 +86,8 @@ class Agent < ActiveRecord::Base |
||
| 86 | 86 |
|
| 87 | 87 |
def create_event(attrs) |
| 88 | 88 |
if can_create_events? |
| 89 |
- events.create!({
|
|
| 90 |
- :user => user, |
|
| 89 |
+ events.create!({
|
|
| 90 |
+ :user => user, |
|
| 91 | 91 |
:expires_at => new_event_expiration_date |
| 92 | 92 |
}.merge(attrs)) |
| 93 | 93 |
else |
@@ -117,7 +117,7 @@ class Agent < ActiveRecord::Base |
||
| 117 | 117 |
if keep_events_for == 0 |
| 118 | 118 |
events.update_all :expires_at => nil |
| 119 | 119 |
else |
| 120 |
- events.update_all "expires_at = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
|
|
| 120 |
+ events.update_all "expires_at = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
|
|
| 121 | 121 |
end |
| 122 | 122 |
end |
| 123 | 123 |
|
@@ -275,11 +275,11 @@ class Agent < ActiveRecord::Base |
||
| 275 | 275 |
joins("JOIN links ON (links.receiver_id = agents.id)").
|
| 276 | 276 |
joins("JOIN agents AS sources ON (links.source_id = sources.id)").
|
| 277 | 277 |
joins("JOIN events ON (events.agent_id = sources.id AND events.id > links.event_id_at_creation)").
|
| 278 |
- where("agents.last_checked_event_id IS NULL OR events.id > agents.last_checked_event_id")
|
|
| 278 |
+ where("NOT agents.disabled AND (agents.last_checked_event_id IS NULL OR events.id > agents.last_checked_event_id)")
|
|
| 279 | 279 |
if options[:only_receivers].present? |
| 280 | 280 |
scope = scope.where("agents.id in (?)", options[:only_receivers])
|
| 281 | 281 |
end |
| 282 |
- |
|
| 282 |
+ |
|
| 283 | 283 |
sql = scope.to_sql() |
| 284 | 284 |
|
| 285 | 285 |
agents_to_events = {}
|
@@ -310,6 +310,7 @@ class Agent < ActiveRecord::Base |
||
| 310 | 310 |
def async_receive(agent_id, event_ids) |
| 311 | 311 |
agent = Agent.find(agent_id) |
| 312 | 312 |
begin |
| 313 |
+ return if agent.disabled? |
|
| 313 | 314 |
agent.receive(Event.where(:id => event_ids)) |
| 314 | 315 |
agent.last_receive_at = Time.now |
| 315 | 316 |
agent.save! |
@@ -334,7 +335,7 @@ class Agent < ActiveRecord::Base |
||
| 334 | 335 |
# per type of agent, so you can override this to define custom bulk check behavior for your custom Agent type. |
| 335 | 336 |
def bulk_check(schedule) |
| 336 | 337 |
raise "Call #bulk_check on the appropriate subclass of Agent" if self == Agent |
| 337 |
- where(:schedule => schedule).pluck("agents.id").each do |agent_id|
|
|
| 338 |
+ where("agents.schedule = ? and disabled = false", schedule).pluck("agents.id").each do |agent_id|
|
|
| 338 | 339 |
async_check(agent_id) |
| 339 | 340 |
end |
| 340 | 341 |
end |
@@ -347,6 +348,7 @@ class Agent < ActiveRecord::Base |
||
| 347 | 348 |
def async_check(agent_id) |
| 348 | 349 |
agent = Agent.find(agent_id) |
| 349 | 350 |
begin |
| 351 |
+ return if agent.disabled? |
|
| 350 | 352 |
agent.check |
| 351 | 353 |
agent.last_check_at = Time.now |
| 352 | 354 |
agent.save! |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 |
<span class='cannot-receive-events text-info'>This type of Agent cannot receive events.</span> |
| 65 | 65 |
<span class="propagate-immediately"><br> |
| 66 | 66 |
<%= f.label :propagate_immediately, :class => 'control-label' do %>Propagate immediately |
| 67 |
- <%= f.check_box :propagate_immediately %> |
|
| 67 |
+ <%= f.check_box :propagate_immediately %> |
|
| 68 | 68 |
<% end %> |
| 69 | 69 |
</span> |
| 70 | 70 |
</div> |
@@ -18,7 +18,11 @@ |
||
| 18 | 18 |
</tr> |
| 19 | 19 |
|
| 20 | 20 |
<% @agents.each do |agent| %> |
| 21 |
- <tr> |
|
| 21 |
+ <% if agent.disabled? %> |
|
| 22 |
+ <tr class='agent-disabled'> |
|
| 23 |
+ <% else %> |
|
| 24 |
+ <tr> |
|
| 25 |
+ <% end %> |
|
| 22 | 26 |
<td> |
| 23 | 27 |
<%= agent.name %> |
| 24 | 28 |
<br/> |
@@ -62,13 +66,22 @@ |
||
| 62 | 66 |
<td><%= working(agent) %></td> |
| 63 | 67 |
<td> |
| 64 | 68 |
<div class="btn-group"> |
| 65 |
- <%= link_to 'Show', agent_path(agent), class: "btn btn-mini" %> |
|
| 66 |
- <%= link_to 'Edit', edit_agent_path(agent), class: "btn btn-mini" %> |
|
| 67 |
- <%= link_to 'Delete', agent_path(agent), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-mini" %>
|
|
| 68 |
- <% if agent.can_be_scheduled? %> |
|
| 69 |
- <%= link_to 'Run', run_agent_path(agent, :return => "index"), method: :post, class: "btn btn-mini" %> |
|
| 69 |
+ <%= link_to 'Show', agent_path(agent), class: "btn btn-mini btn-primary" %> |
|
| 70 |
+ |
|
| 71 |
+ <%= link_to 'Edit', edit_agent_path(agent), class: "btn btn-mini btn-primary" %> |
|
| 72 |
+ |
|
| 73 |
+ <% if agent.disabled? %> |
|
| 74 |
+ <%= link_to "Enable", agent_path(agent, :agent => { :disabled => false }), :method => :put, class: "btn btn-mini btn-success"%>
|
|
| 75 |
+ <% else %> |
|
| 76 |
+ <%= link_to "Disable", agent_path(agent, :agent => { :disabled => true }), :method => :put, class: "btn btn-mini btn-warning"%>
|
|
| 77 |
+ <% end %> |
|
| 78 |
+ |
|
| 79 |
+ <%= link_to 'Delete', agent_path(agent), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-mini btn-danger" %>
|
|
| 80 |
+ |
|
| 81 |
+ <% if agent.can_be_scheduled? && !agent.disabled? %> |
|
| 82 |
+ <%= link_to 'Run', run_agent_path(agent, :return => "index"), method: :post, class: "btn btn-mini btn-success" %> |
|
| 70 | 83 |
<% else %> |
| 71 |
- <%= link_to 'Run', "#", class: "btn btn-mini disabled" %> |
|
| 84 |
+ <span class='btn btn-mini disabled'>Run</span> |
|
| 72 | 85 |
<% end %> |
| 73 | 86 |
</div> |
| 74 | 87 |
</td> |
@@ -4,6 +4,7 @@ |
||
| 4 | 4 |
|
| 5 | 5 |
<div class="tabbable tabs-left"> |
| 6 | 6 |
<ul class="nav nav-tabs" id="show-tabs"> |
| 7 |
+ <li><%= link_to '<i class="icon-chevron-left"></i> Agents'.html_safe, agents_path %></li> |
|
| 7 | 8 |
<% if agent_show_view(@agent).present? %> |
| 8 | 9 |
<li class='active'><a href="#summary" data-toggle="tab"><i class='icon-picture'></i> Summary</a></li> |
| 9 | 10 |
<li><a href="#details" data-toggle="tab"><i class='icon-indent-left'></i> Details</a></li> |
@@ -15,29 +16,37 @@ |
||
| 15 | 16 |
|
| 16 | 17 |
<% if @agent.can_create_events? && @agent.events.count > 0 %> |
| 17 | 18 |
<li><%= link_to '<i class="icon-random"></i> Events'.html_safe, events_path(:agent => @agent.to_param) %></li> |
| 19 |
+ <% else %> |
|
| 20 |
+ <li class='disabled'><a><i class='icon-random'></i> Events</a></li> |
|
| 18 | 21 |
<% end %> |
| 19 |
- <li><%= link_to '<i class="icon-chevron-left"></i> Back'.html_safe, agents_path %></li> |
|
| 20 |
- <li><%= link_to '<i class="icon-pencil"></i> Edit'.html_safe, edit_agent_path(@agent) %></li> |
|
| 21 |
- <li><%= link_to '<i class="icon-plus"></i> Clone'.html_safe, new_agent_path(id: @agent) %></li> |
|
| 22 |
- |
|
| 23 |
- <% if @agent.can_be_scheduled? || @agent.events.count > 0 %> |
|
| 24 |
- <li class="dropdown"> |
|
| 25 |
- <a class="dropdown-toggle" data-toggle="dropdown" href="#">Actions <b class="caret"></b></a> |
|
| 26 |
- <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel"> |
|
| 27 |
- <% if @agent.can_be_scheduled? %> |
|
| 28 |
- <li> |
|
| 29 |
- <%= link_to '<i class="icon-refresh"></i> Run'.html_safe, run_agent_path(@agent, :return => "show"), method: :post, :tabindex => "-1" %> |
|
| 30 |
- </li> |
|
| 31 |
- <% end %> |
|
| 32 | 22 |
|
| 33 |
- <% if @agent.can_create_events? && @agent.events.count > 0 %> |
|
| 34 |
- <li> |
|
| 35 |
- <%= link_to '<i class="icon-trash"></i> Delete all events'.html_safe, remove_events_agent_path(@agent), method: :delete, data: {confirm: 'Are you sure you want to delete ALL events for this Agent?'}, :tabindex => "-1" %>
|
|
| 36 |
- </li> |
|
| 23 |
+ <li class="dropdown"> |
|
| 24 |
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-th-list"></i> Actions <b class="caret"></b></a> |
|
| 25 |
+ <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel"> |
|
| 26 |
+ <% if @agent.can_be_scheduled? && !@agent.disabled? %> |
|
| 27 |
+ <li> |
|
| 28 |
+ <%= link_to '<i class="icon-refresh"></i> Run'.html_safe, run_agent_path(@agent, :return => "show"), method: :post, :tabindex => "-1" %> |
|
| 29 |
+ </li> |
|
| 30 |
+ <% end %> |
|
| 31 |
+ |
|
| 32 |
+ <li><%= link_to '<i class="icon-pencil"></i> Edit'.html_safe, edit_agent_path(@agent) %></li> |
|
| 33 |
+ <li><%= link_to '<i class="icon-plus"></i> Clone'.html_safe, new_agent_path(id: @agent) %></li> |
|
| 34 |
+ |
|
| 35 |
+ <li> |
|
| 36 |
+ <% if !@agent.disabled? %> |
|
| 37 |
+ <%= link_to '<i class="icon-pause"></i> Disable agent'.html_safe, agent_path(@agent, :agent => { :disabled => true }, :return => "show"), :method => :put %>
|
|
| 38 |
+ <% else %> |
|
| 39 |
+ <%= link_to '<i class="icon-play"></i> Enable agent'.html_safe, agent_path(@agent, :agent => { :disabled => false }, :return => "show"), :method => :put %>
|
|
| 37 | 40 |
<% end %> |
| 38 |
- </ul> |
|
| 39 |
- </li> |
|
| 40 |
- <% end %> |
|
| 41 |
+ </li> |
|
| 42 |
+ |
|
| 43 |
+ <% if @agent.can_create_events? && @agent.events.count > 0 %> |
|
| 44 |
+ <li> |
|
| 45 |
+ <%= link_to '<i class="icon-trash"></i> Delete all events'.html_safe, remove_events_agent_path(@agent), method: :delete, data: {confirm: 'Are you sure you want to delete ALL events for this Agent?'}, :tabindex => "-1" %>
|
|
| 46 |
+ </li> |
|
| 47 |
+ <% end %> |
|
| 48 |
+ </ul> |
|
| 49 |
+ </li> |
|
| 41 | 50 |
</ul> |
| 42 | 51 |
|
| 43 | 52 |
<div class="tab-content"> |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 |
<div class="btn-group"> |
| 26 | 26 |
<%= link_to 'Show', event_path(event), class: "btn btn-mini" %> |
| 27 | 27 |
<%= link_to 'Re-emit', reemit_event_path(event), method: :post, data: { confirm: 'Are you sure you want to duplicate this event and emit the new one now?' }, class: "btn btn-mini" %>
|
| 28 |
- <%= link_to 'Delete', event_path(event), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-mini" %>
|
|
| 28 |
+ <%= link_to 'Delete', event_path(event), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-mini btn-danger" %>
|
|
| 29 | 29 |
</div> |
| 30 | 30 |
</td> |
| 31 | 31 |
</tr> |
@@ -0,0 +1,5 @@ |
||
| 1 |
+class AddDisabledToAgent < ActiveRecord::Migration |
|
| 2 |
+ def change |
|
| 3 |
+ add_column :agents, :disabled, :boolean, :default => false, :null => false |
|
| 4 |
+ end |
|
| 5 |
+end |
@@ -41,6 +41,7 @@ ActiveRecord::Schema.define(:version => 20140408150825) do |
||
| 41 | 41 |
t.datetime "last_event_at" |
| 42 | 42 |
t.datetime "last_error_log_at" |
| 43 | 43 |
t.boolean "propagate_immediately", :default => false, :null => false |
| 44 |
+ t.boolean "disabled", :default => false, :null => false |
|
| 44 | 45 |
end |
| 45 | 46 |
|
| 46 | 47 |
add_index "agents", ["schedule"], :name => "index_agents_on_schedule" |