From 98d0d0c07a337b8ee0d7570d41d66228f61d85fd Mon Sep 17 00:00:00 2001 From: Nick Shortway Date: Tue, 6 Nov 2012 23:09:50 +0000 Subject: [PATCH 1/7] remove sortable from blank column --- Gemfile | 5 +---- Gemfile.lock | 8 ++++++-- app/assets/javascripts/events.js.coffee | 4 ++-- config/database.yml | 10 ++++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 4f01d2f..cd03204 100644 --- a/Gemfile +++ b/Gemfile @@ -5,10 +5,7 @@ gem 'rails', '3.2.12' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' -gem 'sqlite3' - -# bundle --without mysql if using sqlite -gem 'mysql2', "~> 0.3.11", :group => :mysql +gem 'pg' #Authentication Gems gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 18efc5b..c4138cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,7 @@ GEM multi_json (1.6.1) mysql2 (0.3.11) orm_adapter (0.4.0) + pg (0.14.1) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) @@ -127,7 +128,6 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.6) therubyracer (0.10.2) libv8 (~> 3.3.10) thin (1.5.0) @@ -169,13 +169,17 @@ DEPENDENCIES jquery-datatables-rails jquery-rails json +<<<<<<< HEAD minitest-rails mysql2 (~> 0.3.11) rails (= 3.2.12) +======= + pg + rails (= 3.2.8) +>>>>>>> remove sortable from blank column rest-client rolify (= 3.1) sass-rails (~> 3.2.3) - sqlite3 therubyracer thin uglifier (>= 1.0.3) diff --git a/app/assets/javascripts/events.js.coffee b/app/assets/javascripts/events.js.coffee index 5514be5..f38db44 100644 --- a/app/assets/javascripts/events.js.coffee +++ b/app/assets/javascripts/events.js.coffee @@ -94,9 +94,9 @@ $ -> use_environments = $("#use_environments").attr("rel") if use_environments == "true" - aocolumns = [{bVisible: false}, null, null, null, null, null, null, null, null] + aocolumns = [{bVisible: false}, null, null, null, null, null, null, null, {bSortable: false}] else - aocolumns = [{bVisible: false}, null, null, null, null, null, null, null] + aocolumns = [{bVisible: false}, null, null, null, null, null, null, {bSortable: false}] dtable = $('#primary_events_table').dataTable bAutoWidth: false diff --git a/config/database.yml b/config/database.yml index 51a4dd4..55c7762 100644 --- a/config/database.yml +++ b/config/database.yml @@ -4,8 +4,9 @@ # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: - adapter: sqlite3 - database: db/development.sqlite3 + adapter: postgresql + database: sensu + username: postgres pool: 5 timeout: 5000 @@ -19,7 +20,8 @@ test: timeout: 5000 production: - adapter: sqlite3 - database: db/production.sqlite3 + adapter: postgresql + database: sensu + username: postgres pool: 5 timeout: 5000 From 87978aec0f322a15874e4533db9e5157dce81998 Mon Sep 17 00:00:00 2001 From: Nick Shortway Date: Sat, 13 Apr 2013 00:51:10 +0000 Subject: [PATCH 2/7] do not truncate text (IG) --- app/views/events/_output.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/events/_output.html.haml b/app/views/events/_output.html.haml index f4b8d95..3fbe71d 100644 --- a/app/views/events/_output.html.haml +++ b/app/views/events/_output.html.haml @@ -1 +1 @@ -= format_output(event.output, 240) += event.output From 06078a1d8583c4958b6d985f988e31a1911138e0 Mon Sep 17 00:00:00 2001 From: Nick Shortway Date: Sat, 13 Apr 2013 00:56:53 +0000 Subject: [PATCH 3/7] client and event ajax modals, event performance increase, new stashes api fixes, optional min description length, etc. --- Gemfile.lock | 28 +++---- app/assets/javascripts/clients.js.coffee | 30 +++++-- app/assets/javascripts/events.js.coffee | 79 +++++++++++-------- .../bootstrap_and_overrides.css.scss | 35 +++++--- app/controllers/clients_controller.rb | 18 ++++- app/controllers/events_controller.rb | 47 +++++++++-- app/helpers/events_helper.rb | 10 +-- app/models/downtime.rb | 6 +- app/models/event.rb | 12 +-- app/models/setting.rb | 6 ++ app/models/stash.rb | 10 +-- app/views/clients/_modal.html.haml | 9 +++ app/views/clients/index.html.haml | 19 ++--- app/views/events/_actions.html.haml | 16 ++-- app/views/events/_modal_data.html.haml | 4 +- app/views/events/_modal_silence.html.haml | 25 ++++++ app/views/events/_modals.html.haml | 21 ++--- app/views/events/_table.html.haml | 3 +- app/views/stashes/_stash_row_legacy.html.haml | 2 +- app/views/stashes/index.html.haml | 2 +- config/routes.rb | 8 +- db/seeds.rb | 3 + 22 files changed, 249 insertions(+), 144 deletions(-) create mode 100644 app/views/clients/_modal.html.haml create mode 100644 app/views/events/_modal_silence.html.haml diff --git a/Gemfile.lock b/Gemfile.lock index c4138cf..c3162d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,7 +35,7 @@ GEM will_paginate builder (3.0.4) cancan (1.6.8) - chronic (0.6.7) + chronic (0.9.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -44,13 +44,13 @@ GEM execjs coffee-script-source (1.4.0) daemons (1.1.9) - devise (2.1.2) + devise (2.2.1) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) railties (~> 3.1) warden (~> 1.2.1) erubis (2.7.0) - eventmachine (1.0.0) + eventmachine (1.0.3) execjs (1.4.0) multi_json (~> 1.0) font-awesome-sass-rails (2.0.0.0) @@ -67,14 +67,14 @@ GEM hike (1.2.1) i18n (0.6.4) journey (1.0.4) - jquery-datatables-rails (1.11.1) + jquery-datatables-rails (1.11.2) jquery-rails jquery-rails (2.1.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) json (1.7.7) kgio (2.7.4) - libv8 (3.3.10.4) + libv8 (3.11.8.13) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -115,11 +115,12 @@ GEM rake (10.0.3) rdoc (3.12.2) json (~> 1.4) + ref (1.0.2) rest-client (1.6.7) mime-types (>= 1.16) rolify (3.1.0) - sass (3.2.1) - sass-rails (3.2.5) + sass (3.2.5) + sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) @@ -143,16 +144,16 @@ GEM uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) - unicorn (4.4.0) + unicorn (4.5.0) kgio (~> 2.6) rack raindrops (~> 0.7) warden (1.2.1) rack (>= 1.0) - whenever (0.7.3) + whenever (0.8.2) activesupport (>= 2.3.4) - chronic (~> 0.6.3) - will_paginate (3.0.3) + chronic (>= 0.6.3) + will_paginate (3.0.4) PLATFORMS ruby @@ -169,14 +170,9 @@ DEPENDENCIES jquery-datatables-rails jquery-rails json -<<<<<<< HEAD minitest-rails mysql2 (~> 0.3.11) rails (= 3.2.12) -======= - pg - rails (= 3.2.8) ->>>>>>> remove sortable from blank column rest-client rolify (= 3.1) sass-rails (~> 3.2.3) diff --git a/app/assets/javascripts/clients.js.coffee b/app/assets/javascripts/clients.js.coffee index 0a6bb91..d3be359 100644 --- a/app/assets/javascripts/clients.js.coffee +++ b/app/assets/javascripts/clients.js.coffee @@ -3,21 +3,35 @@ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ $ -> $('.subpopover').popover({'placement': 'bottom'}) + $('td.moreinfo').click -> - $($(this).closest('tr').attr("rel")).modal("show") + $(this).closest('tr').attr("rel") + $.get "/clients/modal_data", { 'client_query': $(this).closest('tr').attr("rel") }, + (data) -> + if data.code == 0 + $('#client-data-modal').html(data['data']) + $('#client-data-modal').modal("show") + else + alert(data.msg) + $('a.delete-client').click -> self = $(this) if (confirm('Are you sure?')) - $.ajax $(this).attr("rel"), - type: 'DELETE' - success: (data) -> + $.post "/clients/delete_client", { 'key': $(this).attr('key') }, + (data) -> if data $("#client_row_" + $(self).attr('key')).hide() else alert("Could not delete client") + use_environments = $("#use_environments").attr("rel") + if use_environments == "true" + aocolumns = [null, null, null, null, null, null, {bSortable: false}, {bSortable: false}] + else + aocolumns = [null, null, null, null, null, {bSortable: false}, {bSortable: false}] + dtable = $('#clients_table').dataTable - bAutoWidth: false - bSort: true - aoColumns: [null, null, null, null, null, null, {bSortable: false}, {bSortable: false}] - bPaginate: false + bAutoWidth: false + bSort: true + aoColumns: aocolumns + bPaginate: false diff --git a/app/assets/javascripts/events.js.coffee b/app/assets/javascripts/events.js.coffee index f38db44..0d24f3a 100644 --- a/app/assets/javascripts/events.js.coffee +++ b/app/assets/javascripts/events.js.coffee @@ -12,23 +12,18 @@ $ -> $('#primary_events_table').dataTable().fnReloadAjax() setTimeout (() -> $('#updating_event_list').hide()), 2500 - runPermanentHooks = ()-> + setPickers = ()-> $('.timepicker').timepicker({ 'step': 15, 'showDuration': true, 'timeFormat': 'g:ia', 'scrollDefaultNow': true }) $('.datepicker').datepicker({ 'autoclose': true, 'dateFormat': 'm/d/yy', 'format': 'mm/dd/yyyy' }) + runPermanentHooks = ()-> $(document).on 'keydown', '.silence-input', -> - self = $(this) - misc = $(self).attr("misc") - $('#no_input_' + $(self).attr("misc")).hide() - if $(self).val().length > 12 - $('[control="silence_grey_submit_' + misc + '"]').hide() - $('[control="silence_submit_' + misc + '"]').show() + misc = $(this).attr("misc") + $('#no_input_' + $(this).attr("misc")).hide() + if $(this).val().length >= $(this).data("min") + $('[control="silence_submit_' + misc + '"]').addClass('btn-success').removeClass('btn-inverse') else - $('[control="silence_grey_submit_' + misc + '"]').show() - $('[control="silence_submit_' + misc + '"]').hide() - - $(document).on 'click', '[control^=silence_grey_submit_]', -> - $('#no_input_' + $(this).attr("misc")).show() + $('[control="silence_submit_' + misc + '"]').addClass('btn-inverse').removeClass('btn-success') $(document).on 'click', 'div.moreinfo', -> $.get "/events/modal_data", { 'event_query': $(this).attr('misc'), 'i': $(this).attr('index_id') }, @@ -52,45 +47,61 @@ $ -> $(self).text("Failed to resolve") $(self).css("color", "red") - $(document).on 'click', '.silence-event', -> - self = $(this) + $(document).on 'click', '.silence-client', -> + $("#event-data-modal").modal("hide") + $.get "/events/modal_silence", { 'event_query': $(this).attr('misc'), 'i': $(this).attr('index_id'), 't':'client' }, + (data) -> + if data + $('#event-data-modal').html(data['data']) + $('#event-data-modal').modal("show") + setPickers() + else + alert("Could not get modal info") + + $(document).on 'click', '.silence-check', -> $("#event-data-modal").modal("hide") - $("#modal_" + $(self).attr("misc")).modal("show") + $.get "/events/modal_silence", { 'event_query': $(this).attr('misc'), 'i': $(this).attr('index_id'), 't':'check' }, + (data) -> + if data + $('#event-data-modal').html(data['data']) + $('#event-data-modal').modal("show") + setPickers() + else + alert("Could not get modal info") $(document).on 'click', '.silence-submit-event', -> - self = $(this) - misc = $(self).attr("misc") + misc = $(this).attr("misc") + if $('#text_input_' + misc).val().length < $('#text_input_' + misc).data("min") + alert('Comment must be at least ' + $('#text_input_' + misc).data("min") + ' characters long') + return false $.post $(this).attr("rel"), { 'expire_at_time': $('#silence_expire_at_time_' + misc).val(), 'expire_at_date': $('#silence_expire_at_date_' + misc).val(), 'description': $('#text_input_' + misc).val()}, (data) -> - if data - $("#modal_" + misc).modal("hide") + if data.code == 0 + $("#event-data-modal").modal("hide") + $('i[event="' + misc + '"]').removeClass("icon-volume-up").addClass("icon-volume-off") updateEventTable() else - alert("Failed to silence...") + alert(data) $(document).on 'click', '.unsilence-submit-event', -> - self = $(this) - misc = $(self).attr("misc") + misc = $(this).attr("misc") $.post $(this).attr("rel"), (data) -> if data - $('[control="unsilence_' + misc + '"]').hide() - $('[control="silence_' + misc + '"]').show() $('td[rel="' + misc + '_popup_info"]').attr('data-content', "No") $('td[rel="' + misc + '_column_silenced"]').text("No") + $('i[event="' + misc + '"]').removeClass("icon-volume-off").addClass("icon-volume-up") else alert("Failed to unsilence...") - $(document).on 'click', '.delete-client', -> - self = $(this) - if (confirm('Are you sure?')) - $.ajax $(this).attr("rel"), - type: 'DELETE' - success: (data) -> - if data - updateEventTable() - else - alert("Could not delete client") + $(document).on 'click', 'a.delete-client', -> + if (confirm('Are you sure?')) + $.post "/clients/delete_client", { 'key': $(this).attr('key') }, + (data) -> + if data + $("td:contains('" + this.data.split("=")[1] + "')").parent().hide() + else + alert("Could not delete client") use_environments = $("#use_environments").attr("rel") if use_environments == "true" diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.scss b/app/assets/stylesheets/bootstrap_and_overrides.css.scss index 8e5d94c..e71d03d 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.scss +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.scss @@ -18,32 +18,42 @@ body { top: 3%; right: 3%; left: 3%; - bottom: 3%; width: auto; - margin: 0; + margin: 0 auto; } .small-modal { - height: 60%; - width: 60%; + width: 30%; left: 8%; - top: 5%; + top: 20%; } .large-modal { - height: 65%; - width: 75%; - left: 8%; - top: 5%; + width: 50%; + left: 8%; + top: 5%; +} + +.silence-reason { + float: left; +} + +.silence-time { + float: left; + padding-left: 50px; } div.modal-body { - max-height: 60%; + padding-bottom: 80px; + max-height: 500px; max-width: 95%; } div.modal-footer { - min-height: 20%; + position: absolute; + bottom: 0px; + right: 0px; + width: 100%; } table.events_table { @@ -86,7 +96,8 @@ only screen and (max-width: 480px) { .modal-footer { min-height: 45px; } - + + /* Force table to not be like tables anymore */ .events_table thead,.events_table tbody,.events_table th,.events_table td,.events_table tr { display: block; diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 078ef8d..efc80f2 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -5,12 +5,22 @@ def index @clients = Client.all_with_cache end - def destroy - resp = Client.destroy(params[:id]) + def modal_data + client = Client.find(params[:client_query]) + if client + render :json => {:code => 0, :data => render_to_string(:action => "_modal", :layout => false, :locals => {:client => client})} + else + render :json => {:code => 1, :msg => "Could not find client #{params[:client_query]}"} + end + end + + def delete_client + resp = Client.destroy(params[:key]) Client.refresh_cache + Event.refresh_cache respond_to do |format| - format.json { render :json => {:data => (resp == 202).to_s}.to_json } - format.mobile { render :json => {:data => (resp == 202).to_s}.to_json } + format.json { render :json => {:data => (resp.code == 202).to_s}.to_json } + format.mobile { render :json => {:data => (resp.code == 202).to_s}.to_json } end end end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 8ab897c..d6d48ad 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -8,6 +8,8 @@ def index def events_table events_datatable = [] @events.each_with_index do |event, i| + client_silenced = event.client_silenced + check_silenced = event.check_silenced if Setting.use_environments? events_datatable << [ event.sort_val, @@ -16,7 +18,7 @@ def events_table event.client, event.check, render_to_string(:action => "_output", :formats => [:html], :layout => false, :locals => { :event => event }), - render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i}), + render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i, :client_silenced => client_silenced, :check_silenced => check_silenced}), render_to_string(:action => "_issued", :formats => [:html], :layout => false, :locals => { :event => event }), "
" ] @@ -27,7 +29,7 @@ def events_table event.client, event.check, render_to_string(:action => "_output", :formats => [:html], :layout => false, :locals => { :event => event }), - render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i}), + render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i, :client_silenced => client_silenced, :check_silenced => check_silenced}), render_to_string(:action => "_issued", :formats => [:html], :layout => false, :locals => { :event => event }), "
" ] @@ -42,7 +44,16 @@ def events_table def modal_data event = Event.single(params[:event_query]) - render :json => {:data => render_to_string(:action => "_modal_data", :layout => false, :locals => {:event => event, :i => params[:i]})} + if event + render :json => {:data => render_to_string(:action => "_modal_data", :layout => false, :locals => {:event => event, :i => params[:i]})} + else + render :json => {:data => false } + end + end + + def modal_silence + event = Event.single(params[:event_query]) + render :json => {:data => render_to_string(:action => "_modal_silence", :layout => false, :locals => {:event => event, :i => params[:i], :type => params[:t]})} end def resolve @@ -54,7 +65,22 @@ def resolve end end + def check_min_desc(description) + min_length = Setting.min_desc_length.to_i || 0 + if description.length < min_length + respond_to do |format| + format.json { render :json => {:code => 1, :msg => "Your comment must be at least #{min_length} characters long"} } + format.mobile { render :json => {:code => 1, :msg => "Your comment must be at least #{min_length} characters long"} } + end + return false + end + return true + end + def silence_client + unless check_min_desc(params[:description]) + return + end expire_at = nil if !params[:expire_at_time].blank? && !params[:expire_at_date].blank? expire_at = Time.parse("#{params[:expire_at_date]} #{params[:expire_at_time]}") @@ -62,13 +88,17 @@ def silence_client params[:description] = "No reason given" if params[:description].empty? resp = Event.silence_client(params[:client], params[:description], current_user, expire_at) Stash.refresh_cache + respond_to do |format| - format.json { render :json => (resp.code == 201).to_s } + format.json { render :json => (resp.code == 201) ? {'code' => 0} : {'code' => resp.code, 'msg' => 'Error silencing client'} } format.mobile { render :json => (resp.code == 201).to_s } end end def silence_check + unless check_min_desc(params[:description]) + return + end expire_at = nil if !params[:expire_at_time].blank? && !params[:expire_at_date].blank? expire_at = Time.parse("#{params[:expire_at_date]} #{params[:expire_at_time]}") @@ -77,6 +107,7 @@ def silence_check resp = Event.silence_check(params[:client], params[:check], params[:description], current_user, expire_at) Stash.refresh_cache respond_to do |format| + format.json { render :json => (resp.code == 201) ? {'code' => 0} : {'code' => resp.code, 'msg' => 'Error silencing check'} } format.json { render :json => (resp.code == 201).to_s } format.mobile { render :json => (resp.code == 201).to_s } end @@ -86,8 +117,8 @@ def unsilence_client resp = Event.unsilence_client(params[:client], current_user) Stash.refresh_cache respond_to do |format| - format.json { render :json => (resp.code == 202).to_s } - format.mobile { render :json => (resp.code == 202).to_s } + format.json { render :json => (resp.code == 204).to_s } + format.mobile { render :json => (resp.code == 204).to_s } end end @@ -95,8 +126,8 @@ def unsilence_check resp = Event.unsilence_check(params[:client], params[:check], current_user) Stash.refresh_cache respond_to do |format| - format.json { render :json => (resp.code == 202).to_s } - format.mobile { render :json => (resp.code == 202).to_s } + format.json { render :json => (resp.code == 204).to_s } + format.mobile { render :json => (resp.code == 204).to_s } end end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 9f94dba..e348fc6 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -4,17 +4,17 @@ def silenced_output(check, client) # TODO: This should be all haml_tag's output = "" output << "Check silenced by:
" unless check.nil? - output << "#{check['description']} - #{check['owner']} - #{check['timestamp']}
" unless check.nil? + output << "#{check['content']['description']} - #{check['content']['owner']} - #{check['content']['timestamp']}
" unless check.nil? output << "Client silenced by:
" unless client.nil? - output << "#{client['description']} - #{client['owner']} - #{client['timestamp']}
" unless client.nil? + output << "#{client['content']['description']} - #{client['content']['owner']} - #{client['content']['timestamp']}
" unless client.nil? output << "Not Silenced" if client.nil? && check.nil? output end - def display_silenced(event, i) + def display_silenced(event, i, client_silenced, check_silenced) # If client_silenced is nil, that means its not silenced - voldisp = ((event.client_silenced.nil? && event.check_silenced.nil?) ? "up" : "off") - haml_tag(:i, {:class => "icon-volume-#{voldisp}", :rel => "icon_silenced_#{i}", :style => "color: #2c2c2c; text-shadow: none;"}) + voldisp = ((client_silenced.nil? && check_silenced.nil?) ? "up" : "off") + haml_tag(:i, {:class => "icon-volume-#{voldisp}", :event => "#{event.client}_#{event.check}", :rel => "icon_silenced_#{i}"}) end def is_nil?(obj) diff --git a/app/models/downtime.rb b/app/models/downtime.rb index e3edaba..14714d1 100644 --- a/app/models/downtime.rb +++ b/app/models/downtime.rb @@ -56,11 +56,11 @@ def self.process_downtimes def self.force_complete(id) downtime = Downtime.find(id) - Stash.stashes.each do |k,v| + Stash.stashes.each do |v| unless v['downtime_id'].nil? if v['downtime_id'].to_i == id.to_i - puts "Force completing downtime (#{downtime.name}, #{downtime.id}) - Deleting stash #{k}" - Stash.delete_stash(k) + puts "Force completing downtime (#{downtime.name}, #{downtime.id}) - Deleting stash #{v['path']}" + Stash.delete_stash(v['path']) end end end diff --git a/app/models/event.rb b/app/models/event.rb index a6c08a8..32f406a 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -21,20 +21,12 @@ def self.single(query) def client_silenced stashes = Stash.stashes - if stashes.include?("silence/#{self.client}") - stashes["silence/#{self.client}"] - else - nil - end + stashes.detect {|stash| stash['path'] == "silence/#{self.client}"} end def check_silenced stashes = Stash.stashes - if stashes.include?("silence/#{self.client}/#{self.check}") - stashes["silence/#{self.client}/#{self.check}"] - else - nil - end + stashes.detect {|stash| stash['path'] == "silence/#{self.client}/#{self.check}"} end def self.manual_resolve(client, check, user) diff --git a/app/models/setting.rb b/app/models/setting.rb index fb3a18e..215bab9 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -13,6 +13,12 @@ def self.use_environments? find_by_name("use_environments").value == "true" end end + + def self.min_desc_length + Rails.cache.fetch("min_desc_length", :expires_in => 15.minutes, :race_condition_ttl => 10) do + find_by_name("min_desc_length").value + end + end def self.configure_server? Rails.cache.fetch("configure_server", :expires_in => 15.minutes, :race_condition_ttl => 10) do diff --git a/app/models/stash.rb b/app/models/stash.rb index 8bde839..97c965d 100644 --- a/app/models/stash.rb +++ b/app/models/stash.rb @@ -61,18 +61,18 @@ def self.delete_stash(key) end def self.delete_all_stashes - Stash.all.each do |key| - destroy(key) + Stash.all.each do |v| + destroy(v['path']) end true end def self.clear_expired_stashes - Stash.stashes.each do |k,v| + Stash.stashes.each do |v| unless v['expire_at'].nil? if Time.parse(v['expire_at']) < Time.now - puts "Clearing stash #{k} due to expiration." - destroy(k) + puts "Clearing stash #{v['path']} due to expiration." + destroy(v['path']) end end end and true diff --git a/app/views/clients/_modal.html.haml b/app/views/clients/_modal.html.haml new file mode 100644 index 0000000..a39ef1f --- /dev/null +++ b/app/views/clients/_modal.html.haml @@ -0,0 +1,9 @@ +%div.modal-header + %h3== Client: #{client.name} +%div.modal-body + %table.table.table-striped.table-bordered + %tbody + - client.attributes.each do |k,v| + %tr + %td= k + %td= v diff --git a/app/views/clients/index.html.haml b/app/views/clients/index.html.haml index 541deaf..85a9fcf 100644 --- a/app/views/clients/index.html.haml +++ b/app/views/clients/index.html.haml @@ -1,14 +1,5 @@ -- @clients.each do |client| - %div{:class => "modal hide", :id => "client_modal_#{client.name}"} - %div.modal-header - %h3== Client: #{client.name} - %div.modal-body - %table.table.table-striped.table-bordered - %tbody - - client.attributes.each do |k,v| - %tr - %td= k - %td= v +%div{:class => "modal small-modal hide", :id => "client-data-modal"} +%div{:style => "display: none;", :id => "use_environments", :rel => "#{use_environments?}"} %table.table-striped.dataTable.clients_table.table{:id => "clients_table"} %thead @@ -17,13 +8,13 @@ %th Name %th Address %th Subscriptions - %th Last checkin - %th + %th Role + %th Last Checkin %th %tbody - @clients.each do |client| - %tr{:id => "client_row_#{client.name}", :rel => "#client_modal_#{client.name}"} + %tr{:id => "client_row_#{client.name}", :rel => client.name} - if use_environments? %td.moreinfo= client.environment %td.moreinfo= client.name diff --git a/app/views/events/_actions.html.haml b/app/views/events/_actions.html.haml index 8e5eded..e6d9f17 100644 --- a/app/views/events/_actions.html.haml +++ b/app/views/events/_actions.html.haml @@ -1,25 +1,25 @@ -%td{:rel => "#{event.client}_popup_info", :title => "Check Silence", 'data-content' => silenced_output(event.check_silenced, event.client_silenced)} +%td{:rel => "#{event.client}_popup_info", :title => "Check Silence", 'data-content' => silenced_output(check_silenced, client_silenced)} %div.btn-group %button.btn.btn-info.dropdown-toggle{'data-toggle' => 'dropdown'} %div{:style => "width: 25px"} %div{:style => "float: left;"} - - display_silenced(event, i) + - display_silenced(event, i, client_silenced, check_silenced) %div{:style => "float: right;"} %span.caret %ul.dropdown-menu - - if event.client_silenced.nil? + - if client_silenced.nil? %li - %a.silence-event{:index_id => "#{i}", :misc => "#{event.client}", :href => "#"} Silence Client + %a.silence-client{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :href => "#"} Silence Client - else %li - %a.unsilence-submit-event{:index_id => "#{i}", :misc => "#{event.client}", :rel => "/events/#{event.client}/unsilence", :href => "#"} UnSilence Client - - if event.check_silenced.nil? + %a.unsilence-submit-event{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/unsilence", :href => "#"} UnSilence Client + - if check_silenced.nil? %li - %a.silence-event{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :href => "#"} Silence Check + %a.silence-check{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :href => "#"} Silence Check - else %li %a.unsilence-submit-event{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/unsilence", :href => "#"} UnSilence Check %li %a.resolve-event{:misc => "#row-event-#{i}", :index_id => "#{i}", :rel => "/events/#{event.client}/#{event.check}/resolve"} Resolve %li - %a.delete-client{:misc => "#row-event-#{i}", :index_id => "#{i}", :rel => "/clients/#{event.client}"} Delete Client + %a.delete-client{:misc => "#row-event-#{i}", :index_id => "#{i}", :key => "#{event.client}"} Delete Client diff --git a/app/views/events/_modal_data.html.haml b/app/views/events/_modal_data.html.haml index 8fcc905..ed0351a 100644 --- a/app/views/events/_modal_data.html.haml +++ b/app/views/events/_modal_data.html.haml @@ -52,11 +52,11 @@ / TODO: This needs to be moved into partials probably and remove a disturbing number of attribs / - if event.check_silenced.nil? - %a.silence-event.btn.btn-primary{:control => "silence_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Silence Check + %a.silence-check.btn.btn-primary{:control => "silence_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Silence Check - else %a.unsilence-submit-event.btn.btn-primary{:control => "unsilence_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/unsilence"} Unsilence Check - if event.client_silenced.nil? - %a.silence-event.btn.btn-primary{:control => "silence_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}"} Silence Client + %a.silence-client.btn.btn-primary{:control => "silence_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Silence Client - else %a.unsilence-submit-event.btn.btn-primary{:control => "unsilence_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}", :rel => "/events/#{event.client}/unsilence"} Unsilence Client %a.resolve-event.btn.btn-success{:rel => "/events/#{event.client}/#{event.check}/resolve"} Resolve diff --git a/app/views/events/_modal_silence.html.haml b/app/views/events/_modal_silence.html.haml new file mode 100644 index 0000000..b954f51 --- /dev/null +++ b/app/views/events/_modal_silence.html.haml @@ -0,0 +1,25 @@ +- len = Setting.min_desc_length.to_i +- if type.match("client") + - header_title = "Silence client #{event.client}" + - suffix = "#{event.client}" +- else + - header_title = "Silence check #{event.check} on client #{event.client}" + - suffix = "#{event.client}_#{event.check}" +%div.modal-header + %h3= header_title +%div.modal-body + %div.pull-left Note: Your event handler must use sensu-plugin or hit the API to make use of silencing. + %div.silence-reason + %h4 Enter reason + %textarea.input-xlarge.silence-input{:id => "text_input_#{suffix}", :index_id => i, :data => {:min => len}, :misc => suffix, :rel => "Silence #{type}", :rows => "3", :type => "text", :placeholder => "Silence #{type} reason"} + %div.silence-time + %h4 Expire at (Optional): + %p Date: + %input.datepicker{:id => "silence_expire_at_date_#{suffix}"} + %p Time: + %input.timepicker{:id => "silence_expire_at_time_#{suffix}"} +%div.modal-footer + - if len > 0 + %a.silence-submit-event.btn.btn-inverse{:control => "silence_submit_#{suffix}", :index_id => i, :misc => suffix, :rel => "/events/#{suffix.sub("_","/")}/silence"} Submit + - else + %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{suffix}", :index_id => i, :misc => "#{suffix}", :rel => "/events/#{suffix.sub("_","/")}/silence"} Submit diff --git a/app/views/events/_modals.html.haml b/app/views/events/_modals.html.haml index dc50c17..dbfbb1e 100644 --- a/app/views/events/_modals.html.haml +++ b/app/views/events/_modals.html.haml @@ -2,6 +2,7 @@ - @events.each_with_index do |event,i| - processed_clients = [] + - len = Setting.min_desc_length.to_i %div{:class => "modal small-modal hide", :id => "modal_#{event.client}_#{event.check}"} %div.modal-header %h3== Silence check #{event.check} on client #{event.client} @@ -9,7 +10,7 @@ %p.pull-left Note: Your event handler must use sensu-plugin or hit the API to make use of silencing. %br %h3 Enter reason - %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Check Reason"} + %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}_#{event.check}", :index_id => "#{i}", :data => {:min => len}, :misc => "#{event.client}_#{event.check}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Check Reason"} %br %h3 Expire at (Optional): %div @@ -19,10 +20,11 @@ %p Time: %input.timepicker{:id => "silence_expire_at_time_#{event.client}_#{event.check}"} %div.modal-footer - %div.alert.alert-error{:id => "no_input_#{event.client}_#{event.check}", :style => "display: none; float: left;" } - %p You need to enter a reason over 12 chars before you can submit! - %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/silence", :style => "display: none;"} Submit - %a.silence-submit-event.btn.btn-inverse{:control => "silence_grey_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Submit + - if len > 0 + %a.silence-submit-event.btn.btn-inverse{:control => "silence_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/silence"} Submit + - else + %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/silence"} Submit + - unless processed_clients.include?(event.client) - processed_clients << event.client %div{:class => "small-modal modal hide", :id => "modal_#{event.client}"} @@ -32,7 +34,7 @@ %p.pull-left Note: Your event handler must use sensu-plugin or hit the API to make use of silencing. %br %h3 Enter reason - %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Client Reason"} + %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}", :index_id => "#{i}", :data => {:min => len}, :misc => "#{event.client}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Client Reason"} %br %h3 Expire at (Optional): %div @@ -42,7 +44,6 @@ %p Time: %input.timepicker{:id => "silence_expire_at_time_#{event.client}"} %div.modal-footer - %div.alert.alert-error{:id => "no_input_#{event.client}", :style => "float: left;"} - %p You need to enter a reason over 12 chars before you can submit! - %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}", :index_id => "#{i}", :style => "display: none;", :misc => "#{event.client}", :rel => "/events/#{event.client}/silence"} Submit - %a.silence-submit-event.btn.btn-inverse{:control => "silence_grey_submit_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}"} Submit + %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}", :rel => "/events/#{event.client}/silence"} Submit + - if len > 0 + %a.silence-submit-event.btn.btn-inverse{:control => "silence_grey_submit_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}"} Submit diff --git a/app/views/events/_table.html.haml b/app/views/events/_table.html.haml index 3ddde53..7b16b81 100644 --- a/app/views/events/_table.html.haml +++ b/app/views/events/_table.html.haml @@ -1,5 +1,4 @@ -= render 'modals' - +%div{:class => "modal large-modal hide", :id => "event-data-modal"} %div{:style => "display: none;", :id => "use_environments", :rel => "#{use_environments?}"} %table.span12.dataTable.events_table.table{'data-source' => '/events/events_table', :border => "0", :cellpadding => "0", :cellspacing => "0", :id => "primary_events_table", :style => "width: 100%;"} %thead diff --git a/app/views/stashes/_stash_row_legacy.html.haml b/app/views/stashes/_stash_row_legacy.html.haml index 76a1bd3..12a7f6f 100644 --- a/app/views/stashes/_stash_row_legacy.html.haml +++ b/app/views/stashes/_stash_row_legacy.html.haml @@ -2,7 +2,7 @@ %td.span5= k %td.span4= v['description'] unless v['description'].nil? %td= v['owner'] - - if v['expire_at'] + - if v['expire_at'] %td= distance_of_time_in_words(Time.now, Time.parse(v['expire_at'])) - else %td Never diff --git a/app/views/stashes/index.html.haml b/app/views/stashes/index.html.haml index 63ba99d..7dea47b 100644 --- a/app/views/stashes/index.html.haml +++ b/app/views/stashes/index.html.haml @@ -62,7 +62,7 @@ %tbody - if Gem::Version.new(@sensu_version) <= Gem::Version.new("0.9.11") - @stashes.each_with_index do |(k,v), i| - = render "stash_row_legacy" + = render "stash_row_legacy", :k => k, :v => v, :i => i - else - @stashes.each do |stash| - stash['content'].each_with_index do |content_item, i| diff --git a/config/routes.rb b/config/routes.rb index 2b81c20..e998b10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,8 @@ scope 'events' do match 'events_table' => 'events#events_table', :via => :get match 'modal_data' => 'events#modal_data', :via => :get - scope '/:client', :constraints => { :client => /[\w.]+/ } do + match 'modal_silence' => 'events#modal_silence', :via => :get + scope '/:client', :constraints => { :client => /[\w.-]+/ } do match '/silence' => 'events#silence_client', :via => :post match '/unsilence' => 'events#unsilence_client', :via => :post scope '/:check' do @@ -34,6 +35,11 @@ end match 'checks/:check/submit' => 'checks#submit_check', :via => :post + + scope 'clients' do + match '/delete_client' => 'clients#delete_client', :via => :post + match '/modal_data' => 'clients#modal_data', :via => :get + end namespace :api do match '/status' => 'api#status', :via => :get diff --git a/db/seeds.rb b/db/seeds.rb index 667b1ea..771bad6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -23,4 +23,7 @@ unless Setting.find_by_name("configure_server") Setting.create(:name => "configure_server", :value => "true") + +unless Setting.find_by_name("min_desc_length") + Setting.create(:name => "min_desc_length", :value => "0") end From bc3ea4a130cfb657da272de56411130e035d15ef Mon Sep 17 00:00:00 2001 From: Nick Shortway Date: Fri, 12 Apr 2013 18:49:23 -0700 Subject: [PATCH 4/7] more fixes for new stashes api --- app/views/events/_modal_data.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/events/_modal_data.html.haml b/app/views/events/_modal_data.html.haml index ed0351a..05db433 100644 --- a/app/views/events/_modal_data.html.haml +++ b/app/views/events/_modal_data.html.haml @@ -25,10 +25,10 @@ %td= event.flapping %tr %td Check Silenced - %td{:rel => "#{event.client}_#{event.check}_column_silenced"}= ((event.check_silenced.nil?) ? "No" : Time.at(event.check_silenced["timestamp"])) + %td{:rel => "#{event.client}_#{event.check}_column_silenced"}= ((event.check_silenced.nil?) ? "No" : Time.at(event.check_silenced["content"]["timestamp"])) %tr %td Client Silenced - %td{:rel => "#{event.client}_column_silenced"}= ((event.client_silenced.nil?) ? "No" : Time.at(event.client_silenced["timestamp"])) + %td{:rel => "#{event.client}_column_silenced"}= ((event.client_silenced.nil?) ? "No" : Time.at(event.client_silenced["content"]["timestamp"])) %br %br %h3 Check Attributes From 5c26a57cbf0933cea382bceffaedae3bad43ba10 Mon Sep 17 00:00:00 2001 From: Nick Shortway Date: Mon, 15 Apr 2013 12:25:12 -0700 Subject: [PATCH 5/7] more api fixes --- app/views/stashes/_stash_row.html.haml | 16 ++++++++-------- app/views/stashes/index.html.haml | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/views/stashes/_stash_row.html.haml b/app/views/stashes/_stash_row.html.haml index 81fe093..28effb0 100644 --- a/app/views/stashes/_stash_row.html.haml +++ b/app/views/stashes/_stash_row.html.haml @@ -1,15 +1,15 @@ -%tr{:id => "stash-#{i}"} +%tr{:id => "#{path}"} %td.span5= path - %td.span4= content_item['description'] || '' - %td= content_item['owner'] || '' - - if content_item['expire_at'] - %td= distance_of_time_in_words(Time.now, Time.parse(content_item['expire_at'])) + %td.span4= content['description'] || '' + %td= content['owner'] || '' + - if content['expire_at'] + %td= distance_of_time_in_words(Time.now, Time.parse(content['expire_at'])) - else %td Never %td - - if content_item['timestamp'].to_i - = time_ago_in_words(Time.at(content_item['timestamp'].to_i)) + " ago" + - if content['timestamp'].to_i + = time_ago_in_words(Time.at(content['timestamp'].to_i)) + " ago" - else = 'Not set' %td - %a.delete-stash{:key => path, :misc => "#stash-#{i}", :rel => "/stashes/delete_stash"} Delete + %a.delete-stash{:key => path, :misc => "##{path}", :rel => "/stashes/delete_stash"} Delete diff --git a/app/views/stashes/index.html.haml b/app/views/stashes/index.html.haml index 7dea47b..8a68e79 100644 --- a/app/views/stashes/index.html.haml +++ b/app/views/stashes/index.html.haml @@ -65,5 +65,4 @@ = render "stash_row_legacy", :k => k, :v => v, :i => i - else - @stashes.each do |stash| - - stash['content'].each_with_index do |content_item, i| - = render "stash_row", :path => stash['path'], :content_item => Hash[*content_item], :i => i + = render "stash_row", :path => stash['path'], :content => stash['content'] From 98d51690a42198b7d46f855403b6f6c1949cb6e3 Mon Sep 17 00:00:00 2001 From: Nick Shortway Date: Mon, 15 Apr 2013 16:29:54 -0700 Subject: [PATCH 6/7] add stashes api support for mobile --- app/views/stashes/_stash_row.mobile.haml | 20 ++++++++++++++++++ app/views/stashes/index.mobile.haml | 27 ++++++------------------ 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 app/views/stashes/_stash_row.mobile.haml diff --git a/app/views/stashes/_stash_row.mobile.haml b/app/views/stashes/_stash_row.mobile.haml new file mode 100644 index 0000000..d200e01 --- /dev/null +++ b/app/views/stashes/_stash_row.mobile.haml @@ -0,0 +1,20 @@ +%li{'data-theme' => 'a', :id => "stash_#{i}"} + %h2= k + %p== Description: #{v['description']} + %p== Owner: #{v['owner']} + - if v['expire_at'] + %p== Expires at: #{distance_of_time_in_words(Time.now, Time.parse(v['expire_at']))} + - else + %p Expires at: Never + %p== Set at: #{time_ago_in_words(Time.at(v['timestamp'].to_i))} ago + %ul + %li + %h2= k + %p== Attributes: + - v.each do |k,v| + %p== #{k} -> #{v} + %li{'data-theme' => 'b'} + %div{:id => "delete_#{i}"} + %button.delete-stash{:index => i, 'data-theme' => 'b', :key => k, :rel => "/stashes/delete_stash"} Delete Stash + %div{:id => "deleted_#{i}", :style => "display: none;"} + %button{'data-theme' => 'c'} Deleted! diff --git a/app/views/stashes/index.mobile.haml b/app/views/stashes/index.mobile.haml index 10a9d50..dd2b09b 100644 --- a/app/views/stashes/index.mobile.haml +++ b/app/views/stashes/index.mobile.haml @@ -6,24 +6,9 @@ %ul{'data-theme' => 'a', 'data-count-theme' => 'a', 'data-role' => 'listview', 'data-inset' => 'true'} - if @stashes.empty? %button{'data-theme' => 'c'} No Stashes - - @stashes.each_with_index do |(k,v), i| - %li{'data-theme' => 'a', :id => "stash_#{i}"} - %h2= k - %p== Description: #{v['description']} - %p== Owner: #{v['owner']} - - if v['expire_at'] - %p== Expires at: #{distance_of_time_in_words(Time.now, Time.parse(v['expire_at']))} - - else - %p Expires at: Never - %p== Set at: #{time_ago_in_words(Time.at(v['timestamp'].to_i))} ago - %ul - %li - %h2= k - %p== Attributes: - - v.each do |k,v| - %p== #{k} -> #{v} - %li{'data-theme' => 'b'} - %div{:id => "delete_#{i}"} - %button.delete-stash{:index => i, 'data-theme' => 'b', :key => k, :rel => "/stashes/delete_stash"} Delete Stash - %div{:id => "deleted_#{i}", :style => "display: none;"} - %button{'data-theme' => 'c'} Deleted! + - if Gem::Version.new(@sensu_version) <= Gem::Version.new("0.9.11") + - @stashes.each_with_index do |(k,v), i| + = render "stash_row", :k => k, :v => v, :i => i + - else + - @stashes.each_with_index do |stash, i| + = render "stash_row", :k => stash['path'], :v => stash['content'], :i => i From 54e72eb6bb4fc8550fffc7a66349246d6521e151 Mon Sep 17 00:00:00 2001 From: Alan Sebastian Date: Sun, 14 Jul 2013 16:44:32 -0700 Subject: [PATCH 7/7] Remove pg requirement --- Gemfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index cd03204..04f5586 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,9 @@ gem 'rails', '3.2.12' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' -gem 'pg' +gem 'sqlite3' +# bundle --without mysql if using sqlite +gem 'mysql2', "~> 0.3.11", :group => :mysql #Authentication Gems gem 'devise'