foreman_monitoring 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/app/controllers/api/v2/monitoring_results_controller.rb +2 -3
- data/app/helpers/concerns/foreman_monitoring/hosts_helper_ext.rb +2 -2
- data/app/models/concerns/foreman_monitoring/host_extensions.rb +1 -1
- data/app/models/monitoring_result.rb +5 -1
- data/app/views/hosts/_downtime_fields.html.erb +2 -2
- data/app/views/monitoring_results/_host_tab_pane.html.erb +1 -1
- data/lib/foreman_monitoring/version.rb +1 -1
- data/test/unit/monitoring_result_test.rb +73 -0
- metadata +10 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: eca113371402bd1f2251f09d5fd35ef5fce8ef9719299517e37cd56856ee9bbc
         | 
| 4 | 
            +
              data.tar.gz: 1d03b4a53865238e521074bf22f9f247e0b74413b1265790995ca6269be923cf
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9f6bb65a07d9a823f9ebad01708ce60b5a8058b6d86b2d67af1016c5361927de85a7e5ce2868bd4b8ec886236949f755d2a04e8b78698d07ed0de9b208b0e830
         | 
| 7 | 
            +
              data.tar.gz: f1a7ae4199d026bbcf8feb054f783aca7d0eb86096129b3d54d6e051d2be6174648086280ca4b3e1c4c3545cc41d8f4aa921cdd8fa720ea52ef7f1b177e444ac
         | 
    
        data/README.md
    CHANGED
    
    | @@ -42,15 +42,15 @@ the `monitoring` feature has to be assigned. This can be done during | |
| 42 42 | 
             
            provisioning or as a bulk action from the host overview.
         | 
| 43 43 |  | 
| 44 44 | 
             
            You can configure the default action which will be done during host
         | 
| 45 | 
            -
            provisioning and  | 
| 46 | 
            -
            object or take no action while  | 
| 47 | 
            -
            object, set a downtime or take no action. For rebuild it will by default
         | 
| 45 | 
            +
            provisioning and de-provisioning. Provisioning allows to create a monitoring
         | 
| 46 | 
            +
            object or take no action while de-provisoning allows deleting the monitoring
         | 
| 47 | 
            +
            object, set a downtime or take no action. For rebuild, it will by default
         | 
| 48 48 | 
             
            set a downtime.
         | 
| 49 49 |  | 
| 50 50 | 
             
            The plugin will show you the monitoring status as a sub-status and a detail
         | 
| 51 51 | 
             
            panel. You can configure if the sub-status should affect the global status.
         | 
| 52 52 |  | 
| 53 | 
            -
            Furthermore it allows to individually set a downtime at the host detail view
         | 
| 53 | 
            +
            Furthermore, it allows to individually set a downtime at the host detail view
         | 
| 54 54 | 
             
            or as a bulk action from the host overview.
         | 
| 55 55 |  | 
| 56 56 | 
             
            # Troubleshooting
         | 
| @@ -58,8 +58,8 @@ or as a bulk action from the host overview. | |
| 58 58 | 
             
            Logging entries relevant to the plug-in will be located in the Foreman's log
         | 
| 59 59 | 
             
            which is by default `/var/log/foreman/production.log`.
         | 
| 60 60 |  | 
| 61 | 
            -
            Also check the troubleshooting section of the Smart Proxy plug-in if problems
         | 
| 62 | 
            -
             | 
| 61 | 
            +
            Also, check the troubleshooting section of the Smart Proxy plug-in if problems
         | 
| 62 | 
            +
            occur in the underlying communication.
         | 
| 63 63 |  | 
| 64 64 | 
             
            ## Contributing
         | 
| 65 65 |  | 
| @@ -17,10 +17,9 @@ module Api | |
| 17 17 |  | 
| 18 18 | 
             
                  def create
         | 
| 19 19 | 
             
                    begin
         | 
| 20 | 
            -
                      MonitoringResult.import(monitoring_result_params.with_indifferent_access)
         | 
| 20 | 
            +
                      MonitoringResult.import(monitoring_result_params.to_h.with_indifferent_access)
         | 
| 21 21 | 
             
                    rescue StandardError => e
         | 
| 22 | 
            -
                       | 
| 23 | 
            -
                      logger.debug e.backtrace.join("\n")
         | 
| 22 | 
            +
                      Foreman::Logging.exception('Failed to import monitoring result', e)
         | 
| 24 23 | 
             
                      render :json => { 'message' => e.message }, :status => :unprocessable_entity
         | 
| 25 24 | 
             
                      return
         | 
| 26 25 | 
             
                    end
         | 
| @@ -53,10 +53,10 @@ module ForemanMonitoring | |
| 53 53 | 
             
                  end
         | 
| 54 54 | 
             
                end
         | 
| 55 55 |  | 
| 56 | 
            -
                def  | 
| 56 | 
            +
                def monitoring_datetime_f(f, attr, options = {})
         | 
| 57 57 | 
             
                  field(f, attr, options) do
         | 
| 58 58 | 
             
                    addClass options, 'form-control'
         | 
| 59 | 
            -
                    f. | 
| 59 | 
            +
                    f.datetime_field attr, options
         | 
| 60 60 | 
             
                  end
         | 
| 61 61 | 
             
                end
         | 
| 62 62 | 
             
              end
         | 
| @@ -64,7 +64,7 @@ module ForemanMonitoring | |
| 64 64 | 
             
                    :compute_resource => compute_resource.try(:to_label),
         | 
| 65 65 | 
             
                    :hostgroup => hostgroup.try(:to_label),
         | 
| 66 66 | 
             
                    :organization => organization.try(:name),
         | 
| 67 | 
            -
                    :location =>  | 
| 67 | 
            +
                    :location => location.try(:name),
         | 
| 68 68 | 
             
                    :comment => comment,
         | 
| 69 69 | 
             
                    :environment => environment.try(:to_s),
         | 
| 70 70 | 
             
                    :owner_name => owner.try(:name)
         | 
| @@ -3,6 +3,7 @@ class MonitoringResult < ApplicationRecord | |
| 3 3 |  | 
| 4 4 | 
             
              belongs_to_host
         | 
| 5 5 |  | 
| 6 | 
            +
              # rubocop:disable Metrics/AbcSize
         | 
| 6 7 | 
             
              def self.import(result)
         | 
| 7 8 | 
             
                host = Host.find_by(name: result[:host])
         | 
| 8 9 |  | 
| @@ -27,7 +28,8 @@ class MonitoringResult < ApplicationRecord | |
| 27 28 | 
             
                end
         | 
| 28 29 |  | 
| 29 30 | 
             
                created = MonitoringResult.where(:host => host, :service => result[:service]).first_or_create
         | 
| 30 | 
            -
                 | 
| 31 | 
            +
                # rubocop:disable Rails/Date
         | 
| 32 | 
            +
                if created.timestamp.blank? || updates[:timestamp].blank? || (created.timestamp.to_time - updates[:timestamp].to_time) < 2
         | 
| 31 33 | 
             
                  created.update_attributes(updates)
         | 
| 32 34 |  | 
| 33 35 | 
             
                  if created.persisted?
         | 
| @@ -37,7 +39,9 @@ class MonitoringResult < ApplicationRecord | |
| 37 39 | 
             
                else
         | 
| 38 40 | 
             
                  logger.debug "Skipping monitoring result import for #{host} as it is older than what we have."
         | 
| 39 41 | 
             
                end
         | 
| 42 | 
            +
                # rubocop:enable Rails/Date
         | 
| 40 43 | 
             
              end
         | 
| 44 | 
            +
              # rubocop:enable Metrics/AbcSize
         | 
| 41 45 |  | 
| 42 46 | 
             
              def status
         | 
| 43 47 | 
             
                return :ok if downtime
         | 
| @@ -1,3 +1,3 @@ | |
| 1 1 | 
             
            <%= text_f f, :comment, :size => "col-md-5", :label => _('Comment'), :help_inline => _('Short description that explains why the downtime was set.'), :required => true %>
         | 
| 2 | 
            -
            <%=  | 
| 3 | 
            -
            <%=  | 
| 2 | 
            +
            <%= monitoring_datetime_f f, :starttime, :size => "col-md-5", :label => _('Starttime'), :help_inline => _('Time when the downtime should start.'), :min => DateTime.now, :value => Time.current, :required => true %>
         | 
| 3 | 
            +
            <%= monitoring_datetime_f f, :endtime, :size => "col-md-5", :label => _('Endtime'), :help_inline => _('Time when the downtime should end.'), :value => Time.current.advance(:hours => 2), :required => true %>
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            <%- if authorized_for(:permission => 'view_monitoring_results', :auth_object => @host) && @host.monitored? -%>
         | 
| 2 2 | 
             
            <div class="tab-pane" id="monitoring">
         | 
| 3 3 | 
             
            <% if @host.monitoring_results.any? %>
         | 
| 4 | 
            -
              <table class=" | 
| 4 | 
            +
              <table class="<%= table_css_classes %>">
         | 
| 5 5 | 
             
                <thead
         | 
| 6 6 | 
             
                  <tr>
         | 
| 7 7 | 
             
                    <th colspan="2">Monitoring</th>
         | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            require 'test_plugin_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class MonitoringResultTest < ActiveSupport::TestCase
         | 
| 4 | 
            +
              setup do
         | 
| 5 | 
            +
                User.current = FactoryBot.build(:user, :admin)
         | 
| 6 | 
            +
                setup_settings
         | 
| 7 | 
            +
                disable_orchestration
         | 
| 8 | 
            +
                disable_monitoring_orchestration
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              context '#import' do
         | 
| 12 | 
            +
                let(:host) { FactoryBot.create(:host, :managed, :with_monitoring) }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                let(:initial) do
         | 
| 15 | 
            +
                  {
         | 
| 16 | 
            +
                    host: host.name,
         | 
| 17 | 
            +
                    service: 'cpu metrics',
         | 
| 18 | 
            +
                    timestamp: 1_516_365_380.8834700584,
         | 
| 19 | 
            +
                    result: 1,
         | 
| 20 | 
            +
                    acknowledged: true
         | 
| 21 | 
            +
                  }
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                let(:acknowledegment_cleared) do
         | 
| 25 | 
            +
                  {
         | 
| 26 | 
            +
                    host: host.name,
         | 
| 27 | 
            +
                    service: 'cpu metrics',
         | 
| 28 | 
            +
                    timestamp: 1_516_365_971.2455039024,
         | 
| 29 | 
            +
                    acknowledged: false
         | 
| 30 | 
            +
                  }
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                let(:state_change) do
         | 
| 34 | 
            +
                  {
         | 
| 35 | 
            +
                    host: host.name,
         | 
| 36 | 
            +
                    service: 'cpu metrics',
         | 
| 37 | 
            +
                    timestamp: 1_516_365_971.2461779118,
         | 
| 38 | 
            +
                    result: 0
         | 
| 39 | 
            +
                  }
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                test 'imports a monitoring result' do
         | 
| 43 | 
            +
                  MonitoringResult.import(initial)
         | 
| 44 | 
            +
                  imported = host.monitoring_results.last
         | 
| 45 | 
            +
                  assert_equal true, imported.acknowledged?
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                test 'handles ack and state change in correct order' do
         | 
| 49 | 
            +
                  MonitoringResult.import(initial)
         | 
| 50 | 
            +
                  MonitoringResult.import(acknowledegment_cleared)
         | 
| 51 | 
            +
                  MonitoringResult.import(state_change)
         | 
| 52 | 
            +
                  imported = host.monitoring_results.last
         | 
| 53 | 
            +
                  assert_equal :ok, imported.status
         | 
| 54 | 
            +
                  assert_equal false, imported.acknowledged?
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                test 'handles ack and state change in reverse order' do
         | 
| 58 | 
            +
                  MonitoringResult.import(initial)
         | 
| 59 | 
            +
                  MonitoringResult.import(state_change)
         | 
| 60 | 
            +
                  MonitoringResult.import(acknowledegment_cleared)
         | 
| 61 | 
            +
                  imported = host.monitoring_results.last
         | 
| 62 | 
            +
                  assert_equal :ok, imported.status
         | 
| 63 | 
            +
                  assert_equal false, imported.acknowledged?
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                test 'ignores old data' do
         | 
| 67 | 
            +
                  MonitoringResult.import(state_change)
         | 
| 68 | 
            +
                  MonitoringResult.import(initial)
         | 
| 69 | 
            +
                  imported = host.monitoring_results.last
         | 
| 70 | 
            +
                  assert_equal false, imported.acknowledged?
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: foreman_monitoring
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Timo Goebel
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018- | 
| 11 | 
            +
            date: 2018-03-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rdoc
         | 
| @@ -104,6 +104,7 @@ files: | |
| 104 104 | 
             
            - test/test_plugin_helper.rb
         | 
| 105 105 | 
             
            - test/unit/host_status/monitoring_status_test.rb
         | 
| 106 106 | 
             
            - test/unit/host_test.rb
         | 
| 107 | 
            +
            - test/unit/monitoring_result_test.rb
         | 
| 107 108 | 
             
            - test/unit/monitoring_test.rb
         | 
| 108 109 | 
             
            homepage: http://www.github.com/theforeman/foreman_monitoring
         | 
| 109 110 | 
             
            licenses:
         | 
| @@ -130,13 +131,14 @@ signing_key: | |
| 130 131 | 
             
            specification_version: 4
         | 
| 131 132 | 
             
            summary: Foreman plugin for monitoring system integration.
         | 
| 132 133 | 
             
            test_files:
         | 
| 134 | 
            +
            - test/unit/host_test.rb
         | 
| 135 | 
            +
            - test/unit/monitoring_result_test.rb
         | 
| 136 | 
            +
            - test/unit/host_status/monitoring_status_test.rb
         | 
| 137 | 
            +
            - test/unit/monitoring_test.rb
         | 
| 138 | 
            +
            - test/factories/smart_proxy.rb
         | 
| 139 | 
            +
            - test/factories/monitoring_results.rb
         | 
| 133 140 | 
             
            - test/factories/feature.rb
         | 
| 134 141 | 
             
            - test/factories/host.rb
         | 
| 135 | 
            -
            - test/factories/monitoring_results.rb
         | 
| 136 | 
            -
            - test/factories/smart_proxy.rb
         | 
| 137 | 
            -
            - test/functional/hosts_controller_test.rb
         | 
| 138 142 | 
             
            - test/lib/proxy_api/monitoring_test.rb
         | 
| 139 143 | 
             
            - test/test_plugin_helper.rb
         | 
| 140 | 
            -
            - test/ | 
| 141 | 
            -
            - test/unit/host_test.rb
         | 
| 142 | 
            -
            - test/unit/monitoring_test.rb
         | 
| 144 | 
            +
            - test/functional/hosts_controller_test.rb
         |