quixoten-puppetdb-terminus 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet/reports/puppetdb.rb +44 -50
- data/lib/puppet/util/puppetdb/config.rb +7 -19
- data/lib/puppetdb/terminus/version.rb +1 -1
- metadata +1 -2
- data/lib/puppet/util/puppetdb/blacklist.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6b5726f3765b6180cffb3d740bbc869c6962ac
|
4
|
+
data.tar.gz: 6bea52dcfb2b1d02124dd87f033cae351f63ebe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc1bfbbb55221f0f35409e1c89fa2958936921ef36d8b2358db9c18df3531c2f04d2fd4cea0ed03c45e4e02206bbdc32bec17ab4cb3d30af9df1a5d5052679a
|
7
|
+
data.tar.gz: 16f1f3ce051a31dfda521d7d89b3d99e242c497ae55a040e7b46272819302c33d128c6ba84f0797c3349f5cd1d0f2c3f6ff1d384ecda0d40ff41849146951063
|
@@ -19,7 +19,7 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
19
19
|
# @return [void]
|
20
20
|
def process
|
21
21
|
profile("report#process", [:puppetdb, :report, :process]) do
|
22
|
-
submit_command(self.host, report_to_hash, CommandStoreReport,
|
22
|
+
submit_command(self.host, report_to_hash, CommandStoreReport, 6)
|
23
23
|
end
|
24
24
|
|
25
25
|
nil
|
@@ -37,8 +37,8 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
37
37
|
raise Puppet::Error, "Environment is nil, unable to submit report. This may be due a bug with Puppet. Ensure you are running the latest revision, see PUP-2508 for more details."
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
is_noop =
|
40
|
+
resources = build_resources_list
|
41
|
+
is_noop = resources.any? { |rs| has_noop_event?(rs) } and resources.none? { |rs| has_failed_event?(rs) }
|
42
42
|
|
43
43
|
{
|
44
44
|
"certname" => host,
|
@@ -48,31 +48,40 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
48
48
|
"producer_timestamp" => Puppet::Util::Puppetdb.to_wire_time(Time.now),
|
49
49
|
"start_time" => Puppet::Util::Puppetdb.to_wire_time(time),
|
50
50
|
"end_time" => Puppet::Util::Puppetdb.to_wire_time(time + run_duration),
|
51
|
-
"resource_events" => resource_events,
|
52
51
|
"environment" => environment,
|
53
52
|
"transaction_uuid" => transaction_uuid,
|
54
53
|
"status" => status,
|
55
54
|
"noop" => is_noop,
|
56
55
|
"logs" => build_logs_list,
|
57
56
|
"metrics" => build_metrics_list,
|
57
|
+
"resources" => resources,
|
58
58
|
}
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# @return TrueClass
|
63
|
+
# @api private
|
64
|
+
def has_noop_event?(resource)
|
65
|
+
resource["events"].any? { |event| event["status"] == 'noop' }
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return TrueClass
|
69
|
+
# @api private
|
70
|
+
def has_failed_event?(resource)
|
71
|
+
resource["events"].any? { |event| event["status"] == 'failed' }
|
72
|
+
end
|
73
|
+
|
62
74
|
# @return Array[Hash]
|
63
75
|
# @api private
|
64
|
-
def
|
65
|
-
profile("Build
|
66
|
-
[:puppetdb, :
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
events
|
75
|
-
end)
|
76
|
+
def build_resources_list
|
77
|
+
profile("Build resources list (count: #{resource_statuses.count})",
|
78
|
+
[:puppetdb, :resources_list, :build]) do
|
79
|
+
resources = resource_statuses.values.map { |resource| resource_status_to_hash(resource) }
|
80
|
+
if ! config.include_unchanged_resources?
|
81
|
+
resources.select{ |resource| (! resource["events"].empty?) or resource["skipped"] }
|
82
|
+
else
|
83
|
+
resources
|
84
|
+
end
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
@@ -134,57 +143,42 @@ Puppet::Reports.register_report(:puppetdb) do
|
|
134
143
|
#
|
135
144
|
# @return Hash[<String, Object>]
|
136
145
|
# @api private
|
137
|
-
def event_to_hash(
|
146
|
+
def event_to_hash(event)
|
138
147
|
{
|
139
148
|
"status" => event.status,
|
140
149
|
"timestamp" => Puppet::Util::Puppetdb.to_wire_time(event.time),
|
141
|
-
"resource_type" => resource_status.resource_type,
|
142
|
-
"resource_title" => resource_status.title.to_s,
|
143
150
|
"property" => event.property,
|
144
151
|
"new_value" => event.desired_value,
|
145
152
|
"old_value" => event.previous_value,
|
146
153
|
"message" => event.message,
|
147
|
-
"file" => resource_status.file,
|
148
|
-
"line" => resource_status.line,
|
149
|
-
"containment_path" => resource_status.containment_path,
|
150
154
|
}
|
151
155
|
end
|
152
156
|
|
153
|
-
|
154
|
-
|
155
|
-
|
157
|
+
def build_events_list(events)
|
158
|
+
profile("Build events list (count: #{events.count})",
|
159
|
+
[:puppetdb, :events_list, :build]) do
|
160
|
+
events.map { |event| event_to_hash(event) }
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Convert an instance of `Puppet::Resource::Status` to a hash
|
165
|
+
# suitable for sending over the wire to PuppetDB
|
156
166
|
#
|
167
|
+
# @return Hash[<String, Object>]
|
157
168
|
# @api private
|
158
|
-
def
|
169
|
+
def resource_status_to_hash(resource_status)
|
159
170
|
{
|
160
|
-
"
|
161
|
-
"timestamp"
|
162
|
-
"resource_type"
|
163
|
-
"resource_title"
|
164
|
-
"
|
165
|
-
"
|
166
|
-
"old_value" => nil,
|
167
|
-
"message" => nil,
|
168
|
-
"file" => resource_status.file,
|
169
|
-
"line" => resource_status.line,
|
171
|
+
"skipped" => resource_status.skipped,
|
172
|
+
"timestamp" => Puppet::Util::Puppetdb.to_wire_time(resource_status.time),
|
173
|
+
"resource_type" => resource_status.resource_type,
|
174
|
+
"resource_title" => resource_status.title.to_s,
|
175
|
+
"file" => resource_status.file,
|
176
|
+
"line" => resource_status.line,
|
170
177
|
"containment_path" => resource_status.containment_path,
|
178
|
+
"events" => build_events_list(resource_status.events),
|
171
179
|
}
|
172
180
|
end
|
173
181
|
|
174
|
-
# Filter out blacklisted events, if we're configured to do so
|
175
|
-
#
|
176
|
-
# @api private
|
177
|
-
def filter_events(events)
|
178
|
-
if config.ignore_blacklisted_events?
|
179
|
-
profile("Filter blacklisted events",
|
180
|
-
[:puppetdb, :events, :filter_blacklisted]) do
|
181
|
-
events.select { |e| ! config.is_event_blacklisted?(e) }
|
182
|
-
end
|
183
|
-
else
|
184
|
-
events
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
182
|
# Helper method for accessing the puppetdb configuration
|
189
183
|
#
|
190
184
|
# @api private
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'puppet/util/puppetdb/command_names'
|
2
|
-
require 'puppet/util/puppetdb/blacklist'
|
3
2
|
require 'uri'
|
4
3
|
|
5
4
|
module Puppet::Util::Puppetdb
|
@@ -13,8 +12,8 @@ module Puppet::Util::Puppetdb
|
|
13
12
|
:server => "puppetdb",
|
14
13
|
:port => 8081,
|
15
14
|
:soft_write_failure => false,
|
16
|
-
:
|
17
|
-
:
|
15
|
+
:server_url_timeout => 30,
|
16
|
+
:include_unchanged_resources => false,
|
18
17
|
}
|
19
18
|
|
20
19
|
config_file ||= File.join(Puppet[:confdir], "puppetdb.conf")
|
@@ -57,6 +56,7 @@ module Puppet::Util::Puppetdb
|
|
57
56
|
!([:server,
|
58
57
|
:port,
|
59
58
|
:ignore_blacklisted_events,
|
59
|
+
:include_unchanged_resources,
|
60
60
|
:soft_write_failure,
|
61
61
|
:server_urls,
|
62
62
|
:server_url_timeout].include?(k))
|
@@ -70,9 +70,9 @@ module Puppet::Util::Puppetdb
|
|
70
70
|
config_hash[:server_urls] = ["https://#{config_hash[:server].strip}:#{config_hash[:port].to_s}"]
|
71
71
|
end
|
72
72
|
config_hash[:server_urls] = convert_and_validate_urls(config_hash[:server_urls])
|
73
|
-
|
73
|
+
|
74
74
|
config_hash[:server_url_timeout] = config_hash[:server_url_timeout].to_i
|
75
|
-
config_hash[:
|
75
|
+
config_hash[:include_unchanged_resources] = Puppet::Util::Puppetdb.to_bool(config_hash[:include_unchanged_resources])
|
76
76
|
config_hash[:soft_write_failure] = Puppet::Util::Puppetdb.to_bool(config_hash[:soft_write_failure])
|
77
77
|
|
78
78
|
self.new(config_hash, uses_server_urls)
|
@@ -86,7 +86,6 @@ module Puppet::Util::Puppetdb
|
|
86
86
|
|
87
87
|
def initialize(config_hash = {}, uses_server_urls=nil)
|
88
88
|
@config = config_hash
|
89
|
-
initialize_blacklisted_events()
|
90
89
|
if !uses_server_urls
|
91
90
|
Puppet.warning("Specification of server and port in puppetdb.conf is deprecated. Use the setting server_urls.")
|
92
91
|
end
|
@@ -110,12 +109,8 @@ module Puppet::Util::Puppetdb
|
|
110
109
|
config[:server_url_timeout]
|
111
110
|
end
|
112
111
|
|
113
|
-
def
|
114
|
-
config[:
|
115
|
-
end
|
116
|
-
|
117
|
-
def is_event_blacklisted?(event)
|
118
|
-
@blacklist.is_event_blacklisted? event
|
112
|
+
def include_unchanged_resources?
|
113
|
+
config[:include_unchanged_resources]
|
119
114
|
end
|
120
115
|
|
121
116
|
def soft_write_failure
|
@@ -128,13 +123,7 @@ module Puppet::Util::Puppetdb
|
|
128
123
|
# @api private
|
129
124
|
attr_reader :config
|
130
125
|
|
131
|
-
Blacklist = Puppet::Util::Puppetdb::Blacklist
|
132
|
-
|
133
126
|
# @api private
|
134
|
-
def initialize_blacklisted_events(events = Blacklist::BlacklistedEvents)
|
135
|
-
@blacklist = Blacklist.new(events)
|
136
|
-
end
|
137
|
-
|
138
127
|
def self.convert_and_validate_urls(uri_strings)
|
139
128
|
uri_strings.map do |uri_string|
|
140
129
|
|
@@ -152,7 +141,6 @@ module Puppet::Util::Puppetdb
|
|
152
141
|
raise "PuppetDB 'server_urls' cannot contain URL paths, found '#{uri_string}'"
|
153
142
|
end
|
154
143
|
uri.path = ''
|
155
|
-
|
156
144
|
uri
|
157
145
|
end
|
158
146
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quixoten-puppetdb-terminus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devin Christensen
|
@@ -61,7 +61,6 @@ files:
|
|
61
61
|
- lib/puppet/indirector/resource/puppetdb.rb
|
62
62
|
- lib/puppet/reports/puppetdb.rb
|
63
63
|
- lib/puppet/util/puppetdb.rb
|
64
|
-
- lib/puppet/util/puppetdb/blacklist.rb
|
65
64
|
- lib/puppet/util/puppetdb/char_encoding.rb
|
66
65
|
- lib/puppet/util/puppetdb/command.rb
|
67
66
|
- lib/puppet/util/puppetdb/command_names.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Puppet::Util::Puppetdb
|
2
|
-
class Blacklist
|
3
|
-
|
4
|
-
BlacklistedEvent = Struct.new(:resource_type, :resource_title, :status, :property)
|
5
|
-
|
6
|
-
# Initialize our blacklist of events to filter out of reports. This is needed
|
7
|
-
# because older versions of puppet always generate a swath of (meaningless)
|
8
|
-
# 'skipped' Schedule events on every agent run. As of puppet 3.3, these
|
9
|
-
# events should no longer be generated, but this is here for backward compat.
|
10
|
-
BlacklistedEvents =
|
11
|
-
[BlacklistedEvent.new("Schedule", "never", "skipped", nil),
|
12
|
-
BlacklistedEvent.new("Schedule", "puppet", "skipped", nil),
|
13
|
-
BlacklistedEvent.new("Schedule", "hourly", "skipped", nil),
|
14
|
-
BlacklistedEvent.new("Schedule", "daily", "skipped", nil),
|
15
|
-
BlacklistedEvent.new("Schedule", "weekly", "skipped", nil),
|
16
|
-
BlacklistedEvent.new("Schedule", "monthly", "skipped", nil)]
|
17
|
-
|
18
|
-
def initialize(events)
|
19
|
-
@events = events.inject({}) do |m, e|
|
20
|
-
m[e.resource_type] ||= {}
|
21
|
-
m[e.resource_type][e.resource_title] ||= {}
|
22
|
-
m[e.resource_type][e.resource_title][e.status] ||= {}
|
23
|
-
m[e.resource_type][e.resource_title][e.status][e.property] = true
|
24
|
-
m
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def is_event_blacklisted?(event)
|
29
|
-
@events.fetch(event["resource_type"], {}).
|
30
|
-
fetch(event["resource_title"], {}).
|
31
|
-
fetch(event["status"], {}).
|
32
|
-
fetch(event["property"], false)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|