foreman_monitoring 0.1.2 → 0.1.3
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/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/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: 4006edcbe7c896898b2b9a2d68c23e0649925364efbc0f18d5bc09311d183cc7
|
4
|
+
data.tar.gz: 033ebafd117fdbab220bc2d64f9afdd844997c8f7af106f5df8f0bf53d48811b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1eb8d83ffb58a6e7e7ee2cd6fcf048662029256dcb15738c5b9cfec6f675e67a00f10f8fcbf9601a80efdef6d9db3b8e4926cfadcec49f2b00972d10de6e762
|
7
|
+
data.tar.gz: bf7116a3092e7226a1513b6a83dde8f1cd51bfc05aac48c9c87cfd5890d6fb5b066ca96bc603d78b37edb061a3eb6e853361658408eda5b4a87fde2b7f0f2985
|
@@ -58,10 +58,10 @@ module ForemanMonitoring
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
61
|
+
def monitoring_datetime_f(f, attr, options = {})
|
62
62
|
field(f, attr, options) do
|
63
63
|
addClass options, 'form-control'
|
64
|
-
f.
|
64
|
+
f.datetime_field attr, options
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -66,7 +66,7 @@ module ForemanMonitoring
|
|
66
66
|
:compute_resource => compute_resource.try(:to_label),
|
67
67
|
:hostgroup => hostgroup.try(:to_label),
|
68
68
|
:organization => organization.try(:name),
|
69
|
-
:location =>
|
69
|
+
:location => location.try(:name),
|
70
70
|
:comment => comment,
|
71
71
|
:environment => environment.try(:to_s),
|
72
72
|
:owner_name => owner.try(:name)
|
@@ -3,6 +3,7 @@ class MonitoringResult < ActiveRecord::Base
|
|
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 < ActiveRecord::Base
|
|
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 < ActiveRecord::Base
|
|
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 %>
|
@@ -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: 0.1.
|
4
|
+
version: 0.1.3
|
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: rubocop
|
@@ -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
|