diff --git a/.ruby-version b/.ruby-version index 3e3c2f1..0bee604 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.1 +2.3.3 diff --git a/Gemfile b/Gemfile index 0ec6715..70b2995 100644 --- a/Gemfile +++ b/Gemfile @@ -1,35 +1,37 @@ source 'https://rubygems.org' -gem 'rails', '3.2.18' - -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' - -db = ENV["DB"] || "pg" -gem db +gem 'syslogger', git: 'https://github.com/jbussdieker/syslogger.git', :branch => 'implement_log_formatter' +gem 'rails', '4.2.5' +gem 'mysql2', '0.3.18' gem 'puppet' gem 'mcollective-client' gem 'chartkick' gem 'groupdate' gem 'rails-bootstrap', '~> 3.0.0' gem 'kaminari' +gem 'unicorn' -# Gems used only for assets and not required -# in production environments by default. -group :assets do - gem 'sass-rails', '~> 3.2.3' - gem 'coffee-rails', '~> 3.2.1' +gem 'sass-rails', '~> 4.0.0' +gem 'coffee-rails', '~> 4.0.0' +gem 'uglifier', '>= 1.0.3' +gem 'jquery-rails' +gem 'awesome_print' - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - # gem 'therubyracer', :platforms => :ruby +# attr_accessible` is extracted out of Rails into a gem. +# Please use new recommended protection model for params(strong_parameters) +# or add `protected_attributes` to your Gemfile to use old one +gem 'protected_attributes' - gem 'uglifier', '>= 1.0.3' -end +gem 'responders', '~> 2.0' + +# See https://github.com/sstephenson/execjs#readme for more supported runtimes +# gem 'therubyracer', :platforms => :ruby group :development, :test do gem 'rspec-rails' gem 'factory_girl_rails' gem 'coveralls', require: false + gem 'web-console', '~> 2.0' end group :test do @@ -39,11 +41,6 @@ group :test do gem 'database_cleaner' end -gem 'jquery-rails' - -# To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' - # To use Jbuilder templates for JSON # gem 'jbuilder' diff --git a/Gemfile.lock b/Gemfile.lock index af6c860..0f9bd4c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,184 +1,239 @@ +GIT + remote: https://github.com/jbussdieker/syslogger.git + revision: e9749cdedee9d99e07eb20065dafd1f73e78affe + branch: implement_log_formatter + specs: + syslogger (1.6.0) + GEM remote: https://rubygems.org/ specs: CFPropertyList (2.2.8) - actionmailer (3.2.18) - actionpack (= 3.2.18) - mail (~> 2.5.4) - actionpack (3.2.18) - activemodel (= 3.2.18) - activesupport (= 3.2.18) - builder (~> 3.0.0) + actionmailer (4.2.5) + actionpack (= 4.2.5) + actionview (= 4.2.5) + activejob (= 4.2.5) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.5) + actionview (= 4.2.5) + activesupport (= 4.2.5) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.5) + activesupport (= 4.2.5) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.18) - activesupport (= 3.2.18) - builder (~> 3.0.0) - activerecord (3.2.18) - activemodel (= 3.2.18) - activesupport (= 3.2.18) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.18) - activemodel (= 3.2.18) - activesupport (= 3.2.18) - activesupport (3.2.18) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - arel (3.0.3) - builder (3.0.4) - capybara (2.2.1) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.5) + activesupport (= 4.2.5) + globalid (>= 0.3.0) + activemodel (4.2.5) + activesupport (= 4.2.5) + builder (~> 3.1) + activerecord (4.2.5) + activemodel (= 4.2.5) + activesupport (= 4.2.5) + arel (~> 6.0) + activesupport (4.2.5) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) + arel (6.0.4) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.3) + capybara (2.11.0) + addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - chartkick (1.2.4) - childprocess (0.5.3) + chartkick (2.2.2) + childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) - coffee-rails (3.2.2) + coffee-rails (4.0.1) coffee-script (>= 2.2.0) - railties (~> 3.2.0) - coffee-script (2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.7.0) - coveralls (0.7.0) - multi_json (~> 1.3) - rest-client - simplecov (>= 0.7) - term-ansicolor - thor - database_cleaner (1.2.0) + coffee-script-source (1.12.2) + coveralls (0.8.17) + json (>= 1.8, < 3) + simplecov (~> 0.12.0) + term-ansicolor (~> 1.3) + thor (~> 0.19.1) + tins (~> 1.6) + database_cleaner (1.5.3) + debug_inspector (0.0.2) diff-lcs (1.2.5) - docile (1.1.3) + docile (1.1.5) erubis (2.7.0) - execjs (2.0.2) - facter (2.0.1) + execjs (2.7.0) + facter (2.4.6) CFPropertyList (~> 2.2.6) - factory_girl (4.4.0) + factory_girl (4.8.0) activesupport (>= 3.0.0) - factory_girl_rails (4.4.1) - factory_girl (~> 4.4.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) railties (>= 3.0.0) - faker (1.3.0) + faker (1.7.3) i18n (~> 0.5) - ffi (1.9.3) - groupdate (2.1.0) - activerecord (>= 3.0.0) - hiera (1.3.2) - json_pure + ffi (1.9.17) + globalid (0.3.7) + activesupport (>= 4.1.0) + groupdate (3.2.0) + activesupport (>= 3) + hiera (3.3.1) hike (1.2.3) - i18n (0.6.9) - journey (1.0.4) - jquery-rails (3.1.0) - railties (>= 3.0, < 5.0) + i18n (0.8.1) + jquery-rails (4.2.2) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.1) - json_pure (1.8.1) - kaminari (0.15.1) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mcollective-client (2.5.1) + json (1.8.6) + json_pure (1.8.6) + kaminari (1.0.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.0.1) + kaminari-activerecord (= 1.0.1) + kaminari-core (= 1.0.1) + kaminari-actionview (1.0.1) + actionview + kaminari-core (= 1.0.1) + kaminari-activerecord (1.0.1) + activerecord + kaminari-core (= 1.0.1) + kaminari-core (1.0.1) + kgio (2.11.0) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + mcollective-client (2.10.2) json stomp systemu - mime-types (1.25.1) - mini_portile (0.5.3) - multi_json (1.10.0) - mysql2 (0.3.16) - nokogiri (1.6.2) - mini_portile (~> 0.5.2) - polyglot (0.3.4) - puppet (3.5.1) - facter (> 1.6, < 3) - hiera (~> 1.0) - json_pure - rgen (~> 0.6.5) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.4) - rack - rack-test (0.6.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.10.1) + multi_json (1.12.1) + mysql2 (0.3.18) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + protected_attributes (1.1.3) + activemodel (>= 4.0.1, < 5.0) + public_suffix (2.0.5) + puppet (4.8.1) + CFPropertyList (~> 2.2.6) + facter (> 2.0, < 4) + hiera (>= 2.0, < 4) + json_pure (~> 1.8) + rack (1.6.5) + rack-test (0.6.3) rack (>= 1.0) - rails (3.2.18) - actionmailer (= 3.2.18) - actionpack (= 3.2.18) - activerecord (= 3.2.18) - activeresource (= 3.2.18) - activesupport (= 3.2.18) - bundler (~> 1.0) - railties (= 3.2.18) + rails (4.2.5) + actionmailer (= 4.2.5) + actionpack (= 4.2.5) + actionview (= 4.2.5) + activejob (= 4.2.5) + activemodel (= 4.2.5) + activerecord (= 4.2.5) + activesupport (= 4.2.5) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.5) + sprockets-rails rails-bootstrap (3.0.0.4) - railties (3.2.18) - actionpack (= 3.2.18) - activesupport (= 3.2.18) - rack-ssl (~> 1.3.2) + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.8) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.5) + actionpack (= 4.2.5) + activesupport (= 4.2.5) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.3.1) - rdoc (3.12.2) - json (~> 1.4) - rest-client (1.6.7) - mime-types (>= 1.16) - rgen (0.6.6) - rspec-core (2.14.8) - rspec-expectations (2.14.5) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.6) - rspec-rails (2.14.2) + thor (>= 0.18.1, < 2.0) + raindrops (0.17.0) + rake (12.0.0) + responders (2.3.0) + railties (>= 4.2.0, < 5.1) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-rails (3.5.2) actionpack (>= 3.0) - activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rubyzip (1.1.3) - sass (3.3.7) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - selenium-webdriver (2.41.0) - childprocess (>= 0.5.0) - multi_json (~> 1.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + rubyzip (1.2.0) + sass (3.2.19) + sass-rails (4.0.5) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) + sprockets-rails (~> 2.0) + selenium-webdriver (3.0.5) + childprocess (~> 0.5) rubyzip (~> 1.0) - websocket (~> 1.0.4) - simplecov (0.8.2) + websocket (~> 1.0) + simplecov (0.12.0) docile (~> 1.1.0) - multi_json - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) - sprockets (2.2.2) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + sprockets (2.12.4) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - stomp (1.3.2) - systemu (2.6.4) - term-ansicolor (1.3.0) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + stomp (1.4.3) + systemu (2.6.5) + term-ansicolor (1.4.0) tins (~> 1.0) - thor (0.19.1) + thor (0.19.4) + thread_safe (0.3.5) tilt (1.4.1) - tins (1.2.0) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (0.3.39) - uglifier (2.5.0) - execjs (>= 0.3.0) - json (>= 1.8.0) - websocket (1.0.7) + tins (1.13.0) + tzinfo (0.3.52) + uglifier (3.0.4) + execjs (>= 0.3.0, < 3) + unicorn (5.2.0) + kgio (~> 2.6) + raindrops (~> 0.7) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) + websocket (1.2.4) xpath (2.0.0) nokogiri (~> 1.3) @@ -186,9 +241,10 @@ PLATFORMS ruby DEPENDENCIES + awesome_print capybara chartkick - coffee-rails (~> 3.2.1) + coffee-rails (~> 4.0.0) coveralls database_cleaner factory_girl_rails @@ -197,11 +253,19 @@ DEPENDENCIES jquery-rails kaminari mcollective-client - mysql2 + mysql2 (= 0.3.18) + protected_attributes puppet - rails (= 3.2.18) + rails (= 4.2.5) rails-bootstrap (~> 3.0.0) + responders (~> 2.0) rspec-rails - sass-rails (~> 3.2.3) + sass-rails (~> 4.0.0) selenium-webdriver + syslogger! uglifier (>= 1.0.3) + unicorn + web-console (~> 2.0) + +BUNDLED WITH + 1.13.6 diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..49d5957 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..9b63905 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,11 @@ +class HomeController < ApplicationController + def moov_check + if File.exists? File.join(Rails.root, "/public/moov_check.txt") + render json: { message: "OK" } + else + error_msg = "moov_check disabled by user. '/public/moov_check.txt' does not exist." + Rails.logger.error(error_msg) + render json: { message: error_msg }, status: 500 + end + end +end diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index f8b131c..fa03b58 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -4,11 +4,12 @@ class NodesController < ApplicationController def index @nodes = Node.order(sort_column + " " + sort_direction) - render_collection(@nodes) + render_collection(@nodes, 'index') end def show @reports = @node.reports.order("time DESC").page params[:page] + expires_in 5.minutes, :public => true respond_to do |format| format.html # show.html.erb @@ -86,7 +87,7 @@ def status_history def resource_times @report = @node.reports.order("time DESC").first if @report - @metrics = @report.metrics.where(:category => "Time") + @metrics = @report.metrics.where(:category => "Time").to_a @metrics.reject! {|n| n.name == "Total"} @metrics = @metrics.collect {|n| [n.name, n.value]} else diff --git a/app/controllers/parameters_controller.rb b/app/controllers/parameters_controller.rb index da2f72f..658d3ba 100644 --- a/app/controllers/parameters_controller.rb +++ b/app/controllers/parameters_controller.rb @@ -2,7 +2,7 @@ class ParametersController < ApplicationController helper_method :sort_column, :sort_direction def index - @parameters = Parameter.where(parameterable_id: nil).order(sort_column + " " + sort_direction) + @parameters = Parameter.where(parameterable_id: nil).order(sort_column + " " + sort_direction).to_a render_collection(@parameters) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8f0b166..e06ab59 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,4 +24,14 @@ def current_url(new_params) string = options.map{ |k,v| "#{k}=#{v}" }.join("&") request.fullpath.split("?")[0] + "?" + string end + + def link_to_function(name, *args, &block) + html_options = args.extract_options!.symbolize_keys + + function = block_given? ? update_page(&block) : args[0] || '' + onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" + href = html_options[:href] || '#' + + content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) + end end diff --git a/app/services/report_processing.rb b/app/services/report_processing.rb index a6401e0..95bb324 100644 --- a/app/services/report_processing.rb +++ b/app/services/report_processing.rb @@ -80,7 +80,7 @@ def parse_status def parse node_name = parsed.name - @report.node = Node.find_or_create_by_name(node_name) + @report.node = Node.find_or_create_by(name: node_name) @report.report_logs.create(parse_logs) @report.metrics.create(parse_metrics) @report.resource_statuses.create(parse_resource_statuses) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 613eaeb..518e781 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -29,6 +29,16 @@
  • <%= link_to "Parameters", parameters_path %>
  • <%= link_to "Reports", reports_path %>
  • + + diff --git a/app/views/node_classes/show.html.erb b/app/views/node_classes/show.html.erb index 7d0e8b4..a032d28 100644 --- a/app/views/node_classes/show.html.erb +++ b/app/views/node_classes/show.html.erb @@ -5,7 +5,7 @@
    <%= link_to "Back", node_classes_path, :class => 'btn btn-sm btn-default' %> <%= link_to "Edit", edit_node_class_path(@node_class), :class => 'btn btn-sm btn-primary' %> - <%= link_to "Delete", @node_class, :method => :delete, :confirm => "Are you sure?", :class => 'btn btn-sm btn-danger pull-right' %> + <%= link_to "Delete", @node_class, :method => :delete, :data => { :confirm => "Are you sure?" }, :class => 'btn btn-sm btn-danger pull-right' %>

    Nodes

    diff --git a/app/views/node_groups/show.html.erb b/app/views/node_groups/show.html.erb index 6fb4d34..528cbe8 100644 --- a/app/views/node_groups/show.html.erb +++ b/app/views/node_groups/show.html.erb @@ -5,7 +5,7 @@
    <%= link_to "Back", node_groups_path, :class => 'btn btn-sm btn-default' %> <%= link_to "Edit", edit_node_group_path(@node_group), :class => 'btn btn-sm btn-primary' %> - <%= link_to "Delete", @node_group, :method => :delete, :confirm => "Are you sure?", :class => 'btn btn-sm btn-danger pull-right' %> + <%= link_to "Delete", @node_group, :method => :delete, :data => { :confirm => "Are you sure?" }, :class => 'btn btn-sm btn-danger pull-right' %>

    Parameters

    diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index d54d7f3..a96adcd 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb @@ -17,7 +17,7 @@
    <%= puppet_agent_node_status(@node) %>
    - <%= link_to "Delete", @node, :method => :delete, :confirm => "Are you sure?", :class => 'btn btn-sm btn-danger pull-right' %> + <%= link_to "Delete", @node, :method => :delete, :data => { :confirm => "Are you sure?" }, :class => 'btn btn-sm btn-danger pull-right' %>

    Parameters

    diff --git a/app/views/reports/show.html.erb b/app/views/reports/show.html.erb index 639edd7..96cf41c 100644 --- a/app/views/reports/show.html.erb +++ b/app/views/reports/show.html.erb @@ -4,7 +4,7 @@
    <%= link_to "Back", @report.node ? node_path(@report.node) : reports_path, :class => 'btn btn-sm btn-default' %> - <%= link_to "Delete", @report, :method => :delete, :confirm => "Are you sure?", :class => 'btn btn-sm btn-danger pull-right' %> + <%= link_to "Delete", @report, :method => :delete, :data => { :confirm => "Are you sure?" }, :class => 'btn btn-sm btn-danger pull-right' %>

    diff --git a/config/application.rb b/config/application.rb index 38fdd57..39773ae 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,9 +4,7 @@ if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) + Bundler.require(:default, Rails.env) end module Enc @@ -42,21 +40,9 @@ class Application < Rails::Application # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true - # Use SQL instead of Active Record's schema dumper when creating the database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql - - # Enforce whitelist mode for mass assignment. - # This will create an empty whitelist of attributes available for mass-assignment for all models - # in your app. As such, your models will need to explicitly whitelist or blacklist accessible - # parameters by using an attr_accessible or attr_protected declaration. - config.active_record.whitelist_attributes = true - - # Enable the asset pipeline - config.assets.enabled = true - # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + + config.active_record.raise_in_transactional_callbacks = true end end diff --git a/config/database.yml b/config/database.yml index ff7fe08..dd5c7fd 100644 --- a/config/database.yml +++ b/config/database.yml @@ -18,15 +18,27 @@ postgresql: &pg defaults: &defaults pool: 16 timeout: 5000 - host: localhost - <<: *<%= ENV['DB'] || "pg" %> + <<: *<%= ENV['DB'] || "mysql2" %> development: - <<: *defaults + adapter: mysql2 + encoding: utf8 + host: enc-dashboard.c1phlpd5jvwq.us-west-2.rds.amazonaws.com + port: 3306 + database: dashboard_development + username: dashboard + password: d4aca968 test: <<: *defaults + host: localhost production: - <<: *defaults + # <<: *defaults # presumably, we'd erb-echo the production password from /etc/something here. + adapter: mysql2 + encoding: utf8 + host: enc-dashboard + database: dashboard_production + username: dashboard + password: d4aca968 diff --git a/config/environments/development.rb b/config/environments/development.rb index 0335c29..d602256 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,32 +6,28 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true + config.eager_load = false # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false + # Compress JavaScripts and CSS + config.assets.js_compressor = :uglifier + # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin - - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - config.active_record.auto_explain_threshold_in_seconds = 0.5 - - # Do not compress assets - config.assets.compress = false + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load # Expands the lines which load the assets config.assets.debug = true + + config.logger = Logger.new(STDOUT) + config.logger.level = :debug + config.log_level = :debug end diff --git a/config/environments/prod.rb b/config/environments/prod.rb new file mode 100644 index 0000000..59cfca2 --- /dev/null +++ b/config/environments/prod.rb @@ -0,0 +1,73 @@ +Enc::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + config.eager_load = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.serve_static_files = true + + # Compress JavaScripts and CSS + config.assets.js_compressor = :uglifier + + # Don't fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true + + # Defaults to nil and saved in location specified by config.assets.prefix + # config.assets.manifest = YOUR_PATH + + # Specifies the header that your server uses for sending files + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # See everything in the log (default is :info) + # config.log_level = :debug + + # Prepend all log lines with the following tags + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # config.assets.precompile += %w( search.js ) + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify + + config.serve_static_files = true + config.paths['config/database'] = '/etc/enc_dashboard/database.yml' if File.exists? '/etc/enc_dashboard/database.yml' + + # Setup custom logger to stdout and log level to debug + config.logger = Logger.new(STDOUT) + config.logger.level = :debug + config.log_level = :debug +end diff --git a/config/environments/production.rb b/config/environments/production.rb index 4c19acd..8ff1ada 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -4,15 +4,17 @@ # Code is not reloaded between requests config.cache_classes = true + config.eager_load = true + # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_files = true # Compress JavaScripts and CSS - config.assets.compress = true + config.assets.js_compressor = :uglifier # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false @@ -61,7 +63,8 @@ # Send deprecation notices to registered listeners config.active_support.deprecation = :notify - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Setup custom logger to stdout and log level to debug + config.logger = Logger.new(STDOUT) + config.logger.level = :debug + config.log_level = :debug end diff --git a/config/environments/stage.rb b/config/environments/stage.rb new file mode 100644 index 0000000..984f13f --- /dev/null +++ b/config/environments/stage.rb @@ -0,0 +1,29 @@ +Enc::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + config.eager_load = false + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + config.assets.js_compressor = :uglifier + + # Expands the lines which load the assets + config.assets.debug = true + + config.serve_static_files = true + config.assets.compile = false + config.paths['config/database'] = '/etc/enc_dashboard/database.yml' if File.exists? '/etc/enc_dashboard/database.yml' +end diff --git a/config/environments/test.rb b/config/environments/test.rb index b365299..11a3562 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,11 +8,10 @@ config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true + config.serve_static_files = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true + config.eager_load = false # Show full error reports and disable caching config.consider_all_requests_local = true @@ -29,9 +28,6 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end diff --git a/config/initializers/00_enc_settings.rb b/config/initializers/00_enc_settings.rb index 9f2629c..db4811f 100644 --- a/config/initializers/00_enc_settings.rb +++ b/config/initializers/00_enc_settings.rb @@ -1,5 +1,9 @@ if File.exists? "config/settings.yml" - ENC_CONFIG = YAML.load_file("#{Rails.root}/config/settings.yml")[Rails.env].with_indifferent_access + ENC_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/config/settings.yml"))[Rails.env]) + puts "=> Config file(settings.yml) loaded. \n ENC_CONFIG: #{ENC_CONFIG}" +elsif File.exists? "/etc/enc_dashboard/settings.yml" + ENC_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read("/etc/enc_dashboard/settings.yml"))[Rails.env]) + puts "=> Config file(settings.yml) loaded. \n ENC_CONFIG: #{ENC_CONFIG}" else puts "WARNING: No config/settings.yml file found" ENC_CONFIG = {} diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index be058f1..6cb96ce 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -2,6 +2,9 @@ # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! + # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Enc::Application.config.secret_token = '920e97b1d36c9c3f92c6fb9ba9c2ff72e3dccea603965445d2e8e1ce0e003e55ac084008a9841940bb3173ed6269e412ffecb23b20598c730e2fe85f8ac5ce60' +# You can use `rake secret` to generate a secure secret key. + +Enc::Application.config.secret_key_base = '5c82fd92241d77979577a72754fbe29de81e14a7343814aa9b9486147920bbdf2f71e7dc271e33c1a7037e8d1c1b487b7209ff4ba7820278069d6e02992ee38e' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 999df20..c2f744d 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -7,8 +7,3 @@ ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end - -# Disable root element in JSON by default. -ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false -end diff --git a/config/routes.rb b/config/routes.rb index 6d4f834..db6793e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,4 +32,8 @@ end resources :parameters, only: [:index, :new, :create] root :to => 'nodes#index' + + # Rails 4.0 requires that routes using match must specify the request method + # match 'moov_check' => "home#moov_check" + get 'moov_check' => 'home#moov_check' end diff --git a/config/settings.yml.sample b/config/settings.yml.sample deleted file mode 100644 index 355a6ed..0000000 --- a/config/settings.yml.sample +++ /dev/null @@ -1,10 +0,0 @@ -development: -# spool_path: /tmp/enc_spool - puppetdb: - host: hostname - port: port -production: -# spool_path: /tmp/enc_spool - puppetdb: - host: hostname - port: port diff --git a/db/migrate/20160503213802_add_index_to_node_group_memberships.rb b/db/migrate/20160503213802_add_index_to_node_group_memberships.rb new file mode 100644 index 0000000..e01ebea --- /dev/null +++ b/db/migrate/20160503213802_add_index_to_node_group_memberships.rb @@ -0,0 +1,5 @@ +class AddIndexToNodeGroupMemberships < ActiveRecord::Migration + def change + add_index :node_group_memberships, :node_group_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 8ccfa99..ab58670 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,108 +9,110 @@ # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # -# It's strongly recommended to check this file into your version control system. +# It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140509184854) do +ActiveRecord::Schema.define(version: 20160503213802) do - create_table "metrics", :force => true do |t| - t.integer "report_id", :null => false - t.string "category" - t.string "name" - t.decimal "value", :precision => 12, :scale => 6 - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "metrics", force: :cascade do |t| + t.integer "report_id", limit: 4, null: false + t.string "category", limit: 255 + t.string "name", limit: 255 + t.decimal "value", precision: 12, scale: 6 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "metrics", ["report_id"], :name => "index_metrics_on_report_id" + add_index "metrics", ["report_id"], name: "index_metrics_on_report_id", using: :btree - create_table "node_class_memberships", :force => true do |t| - t.integer "node_id" - t.integer "node_class_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "node_class_memberships", force: :cascade do |t| + t.integer "node_id", limit: 4 + t.integer "node_class_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "node_classes", :force => true do |t| - t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "node_classes", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "node_classes", ["name"], :name => "index_node_classes_on_name", :unique => true + add_index "node_classes", ["name"], name: "index_node_classes_on_name", unique: true, using: :btree - create_table "node_group_memberships", :force => true do |t| - t.integer "node_id" - t.integer "node_group_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "node_group_memberships", force: :cascade do |t| + t.integer "node_id", limit: 4 + t.integer "node_group_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "node_groups", :force => true do |t| - t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + add_index "node_group_memberships", ["node_group_id"], name: "index_node_group_memberships_on_node_group_id", using: :btree + + create_table "node_groups", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "node_groups", ["name"], :name => "index_node_groups_on_name", :unique => true + add_index "node_groups", ["name"], name: "index_node_groups_on_name", unique: true, using: :btree - create_table "nodes", :force => true do |t| - t.string "name", :null => false - t.text "description" + create_table "nodes", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.text "description", limit: 65535 t.datetime "reported_at" - t.integer "last_apply_report_id" - t.string "status" - t.boolean "hidden", :default => false - t.integer "last_inspect_report_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "environment" + t.integer "last_apply_report_id", limit: 4 + t.string "status", limit: 255 + t.boolean "hidden", default: false + t.integer "last_inspect_report_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "environment", limit: 255 end - add_index "nodes", ["name"], :name => "index_nodes_on_name", :unique => true + add_index "nodes", ["name"], name: "index_nodes_on_name", unique: true, using: :btree - create_table "parameters", :force => true do |t| - t.string "key" - t.text "value" - t.integer "parameterable_id" - t.string "parameterable_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + create_table "parameters", force: :cascade do |t| + t.string "key", limit: 255 + t.text "value", limit: 65535 + t.integer "parameterable_id", limit: 4 + t.string "parameterable_type", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "report_logs", :force => true do |t| - t.integer "report_id" - t.string "level" - t.text "message" + create_table "report_logs", force: :cascade do |t| + t.integer "report_id", limit: 4 + t.string "level", limit: 255 + t.text "message", limit: 65535 t.datetime "time" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "source" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "source", limit: 255 end - add_index "report_logs", ["report_id"], :name => "index_report_logs_on_report_id" + add_index "report_logs", ["report_id"], name: "index_report_logs_on_report_id", using: :btree - create_table "reports", :force => true do |t| - t.integer "node_id" - t.string "status" - t.string "environment" + create_table "reports", force: :cascade do |t| + t.integer "node_id", limit: 4 + t.string "status", limit: 255 + t.string "environment", limit: 255 t.datetime "time" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "reports", ["node_id"], :name => "index_reports_on_node_id" + add_index "reports", ["node_id"], name: "index_reports_on_node_id", using: :btree - create_table "resource_statuses", :force => true do |t| - t.integer "report_id" + create_table "resource_statuses", force: :cascade do |t| + t.integer "report_id", limit: 4 t.boolean "failed" t.boolean "skipped" t.boolean "is_changed" - t.text "title" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.text "title", limit: 65535 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "resource_statuses", ["report_id"], :name => "index_resource_statuses_on_report_id" + add_index "resource_statuses", ["report_id"], name: "index_resource_statuses_on_report_id", using: :btree end diff --git a/db/seeds.rb b/db/seeds.rb index 6c82759..fb5384d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,12 +5,12 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) -node1 = Node.find_or_create_by_name("node1") +node1 = Node.find_or_create_by(name: "node1") node1.status = "unchanged" node1.save -node2 = Node.find_or_create_by_name("node2") +node2 = Node.find_or_create_by(name: "node2") node2.status = "changed" node2.save -group1 = NodeGroup.find_or_create_by_name("group1") -group2 = NodeGroup.find_or_create_by_name("group2") -group3 = NodeGroup.find_or_create_by_name("group3") +group1 = NodeGroup.find_or_create_by(name: "group1") +group2 = NodeGroup.find_or_create_by(name: "group2") +group3 = NodeGroup.find_or_create_by(name: "group3") diff --git a/enc_dashboard.gemspec b/enc_dashboard.gemspec new file mode 100644 index 0000000..0ea8095 --- /dev/null +++ b/enc_dashboard.gemspec @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +require 'enc_dashboard/version' + +Gem::Specification.new do |gem| + gem.name = "enc_dashboard" + gem.version = EncDashboard::VERSION + gem.authors = ["Joshua B. Bussdieker"] + gem.email = ["josh.bussdieker@moovweb.com"] + gem.description = %q{Puppet dashboard replacement} + gem.summary = %q{Puppet dashboard replacement} + gem.homepage = "" + + gem.files = `git ls-files`.split($/) + gem.files << Dir[".bundle/**/*"] + gem.files << Dir["vendor/**/*"] + gem.files << Dir["public/**/*"] + gem.files << "JENKINS" + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.require_paths = ["lib"] +end diff --git a/lib/enc_dashboard/version.rb b/lib/enc_dashboard/version.rb new file mode 100644 index 0000000..870a31e --- /dev/null +++ b/lib/enc_dashboard/version.rb @@ -0,0 +1,10 @@ +module EncDashboard + VERSION = lambda { + version = File.read("VERSION").strip + if File.exists?("JENKINS") + version += "." + version += File.read("JENKINS").strip + end + version + }.yield +end diff --git a/public/moov_check.txt b/public/moov_check.txt new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/public/moov_check.txt @@ -0,0 +1 @@ +OK diff --git a/spec/factories/node.rb b/spec/factories/node.rb index 39405cb..b56326a 100644 --- a/spec/factories/node.rb +++ b/spec/factories/node.rb @@ -37,7 +37,7 @@ end factory :node_with_reports, parent: :node do - ignore do + ransient do report_count 5 end diff --git a/spec/factories/report.rb b/spec/factories/report.rb index 8f31bf2..0fde8a9 100644 --- a/spec/factories/report.rb +++ b/spec/factories/report.rb @@ -9,7 +9,7 @@ end factory :report_with_dependents, parent: :full_report do - ignore do + ransient do metric_count 5 report_log_count 5 resource_status_count 5 diff --git a/spec/lib/puppetdb_spec.rb b/spec/lib/puppetdb_spec.rb index 69c97c2..9392624 100644 --- a/spec/lib/puppetdb_spec.rb +++ b/spec/lib/puppetdb_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' describe PuppetDB do - its(:options) { should be_kind_of Hash } + it(:options) { should be_kind_of Hash } end diff --git a/vendor/assets/javascripts/.gitkeep b/vendor/assets/javascripts/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/assets/stylesheets/.gitkeep b/vendor/assets/stylesheets/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/plugins/.gitkeep b/vendor/plugins/.gitkeep deleted file mode 100644 index e69de29..0000000