ruby-puppetdb 1.2.0 → 1.3.0
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/Modulefile +1 -1
- data/README.md +5 -0
- data/lib/puppet/face/query.rb +75 -0
- data/lib/puppetdb/connection.rb +2 -2
- data/ruby-puppetdb.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93d81a43c0316b2d59fb966659c283014a4a4e03
|
4
|
+
data.tar.gz: 7b844189a53c57849db60e828f36146aa113c0f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5b8a134365df7df9ed82e8e31fa26e76ad5b46423d80f3981eeb692f40a7deb0021252faeab59155a4690b3b6d253f3b88eafdca0c09ef4ea2644ececd1c0c5
|
7
|
+
data.tar.gz: 8e3a55dc4c110c54305ae3d8dcb27ae9307801bf9350302bf57d881962b02d7e5cc16ea58c8839cbdafc7509da95c61d58be014df2a77262e2872ee2ea0f17a6
|
data/Modulefile
CHANGED
data/README.md
CHANGED
@@ -64,6 +64,11 @@ facts - a hash of facts per node
|
|
64
64
|
db_node_1 {"facterversion":"1.6.9","hostname":"controller",...........}
|
65
65
|
db_node_2 {"facterversion":"1.6.9","hostname":"controller",...........}
|
66
66
|
|
67
|
+
events - a list of events on the matched nodes
|
68
|
+
|
69
|
+
$ puppet query events '(Package["mysql-server"] and architecture=amd64)' --since='1 hour ago' --until=now --status=success
|
70
|
+
host.example.com: 2013-06-10T10:58:37.000Z: File[/foo/bar]/content ({md5}5711edf5f5c50bd7845465471d8d39f0 -> {md5}e485e731570b8370f19a2a40489cc24b): content changed '{md5}5711edf5f5c50bd7845465471d8d39f0' to '{md5}e485e731570b8370f19a2a40489cc24b'
|
71
|
+
|
67
72
|
Ruby
|
68
73
|
----
|
69
74
|
|
data/lib/puppet/face/query.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'puppet/application/query'
|
2
2
|
require 'puppet/face'
|
3
|
+
require 'puppet/util/colors'
|
4
|
+
|
3
5
|
Puppet::Face.define(:query, '1.0.0') do
|
4
6
|
require 'puppetdb/connection'
|
5
7
|
|
8
|
+
extend Puppet::Util::Colors
|
9
|
+
|
6
10
|
copyright "Puppet Labs & Erik Dalen", 2012..2013
|
7
11
|
license "Apache 2 license; see COPYING"
|
8
12
|
|
@@ -70,4 +74,75 @@ Puppet::Face.define(:query, '1.0.0') do
|
|
70
74
|
end
|
71
75
|
|
72
76
|
end
|
77
|
+
|
78
|
+
action :events do
|
79
|
+
summary 'Serves as an interface to puppetdb allowing a user to query for a list of events'
|
80
|
+
|
81
|
+
description <<-EOT
|
82
|
+
Get all avents for nodes matching the query specified.
|
83
|
+
EOT
|
84
|
+
|
85
|
+
arguments "<query>"
|
86
|
+
|
87
|
+
option '--since SINCE' do
|
88
|
+
summary 'Get events since this time'
|
89
|
+
description <<-EOT
|
90
|
+
Uses chronic to parse time, can be specified in many human readable formats.
|
91
|
+
EOT
|
92
|
+
default_to { '1 hour ago' }
|
93
|
+
end
|
94
|
+
|
95
|
+
option '--until UNTIL' do
|
96
|
+
summary 'Get events until this time'
|
97
|
+
description <<-EOT
|
98
|
+
Uses chronic to parse time, can be specified in many human readable formats.
|
99
|
+
EOT
|
100
|
+
default_to { 'now' }
|
101
|
+
end
|
102
|
+
|
103
|
+
option '--status STATUS' do
|
104
|
+
summary 'Only get events with specified status, skipped, success or failure'
|
105
|
+
description <<-EOT
|
106
|
+
Only get events of specified status, can be either all, skipped, success or failure.
|
107
|
+
EOT
|
108
|
+
default_to { 'all' }
|
109
|
+
end
|
110
|
+
|
111
|
+
when_invoked do |query, options|
|
112
|
+
require 'chronic'
|
113
|
+
|
114
|
+
puppetdb = PuppetDB::Connection.new options[:puppetdb_host], options[:puppetdb_port]
|
115
|
+
nodes = puppetdb.query(:nodes, puppetdb.parse_query(query, :nodes)).collect { |n| n['name']}
|
116
|
+
starttime = Chronic.parse(options[:since], :context => :past, :guess => false).first.getutc.strftime('%FT%T.%LZ')
|
117
|
+
endtime = Chronic.parse(options[:until], :context => :past, :guess => false).last.getutc.strftime('%FT%T.%LZ')
|
118
|
+
|
119
|
+
events = []
|
120
|
+
# Event API doesn't support subqueries at the moment and
|
121
|
+
# we can't do too big queries, so fetch events for some nodes at a time
|
122
|
+
nodes.each_slice(20) do |nodeslice|
|
123
|
+
eventquery = ['and', ['>', 'timestamp', starttime], ['<', 'timestamp', endtime], ['or', *nodeslice.collect { |n| ['=', 'certname', n]}]]
|
124
|
+
eventquery << ['=', 'status', options[:status]] if options[:status] != 'all'
|
125
|
+
events.concat puppetdb.query(:events, eventquery, nil, :experimental)
|
126
|
+
end
|
127
|
+
|
128
|
+
events.sort_by do |e|
|
129
|
+
"#{e['timestamp']}+#{e['resource-type']}+#{e['resource-title']}+#{e['property']}"
|
130
|
+
end.each do |e|
|
131
|
+
out="#{e['certname']}: #{e['timestamp']}: #{e['resource-type']}[#{e['resource-title']}]"
|
132
|
+
out+="/#{e['property']}" if e['property']
|
133
|
+
out+=" (#{e['old-value']} -> #{e['new-value']})" if e['old-value'] && e['new-value']
|
134
|
+
out+=": #{e['message']}" if e['message']
|
135
|
+
out.chomp!
|
136
|
+
case e['status']
|
137
|
+
when 'failure'
|
138
|
+
puts colorize(:hred, out)
|
139
|
+
when 'success'
|
140
|
+
puts colorize(:green, out)
|
141
|
+
when 'skipped'
|
142
|
+
puts colorize(:hyellow, out) unless e['resource-type'] == 'Schedule'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
nil
|
146
|
+
end
|
147
|
+
end
|
73
148
|
end
|
data/lib/puppetdb/connection.rb
CHANGED
@@ -50,14 +50,14 @@ class PuppetDB::Connection
|
|
50
50
|
# @param endpoint [Symbol] :resources, :facts or :nodes
|
51
51
|
# @param query [Array] query to execute
|
52
52
|
# @return [Array] the results of the query
|
53
|
-
def query(endpoint, query=nil, http=nil)
|
53
|
+
def query(endpoint, query=nil, http=nil, version=:v2)
|
54
54
|
unless http then
|
55
55
|
require 'puppet/network/http_pool'
|
56
56
|
http = Puppet::Network::HttpPool.http_instance(@host, @port, @use_ssl)
|
57
57
|
end
|
58
58
|
headers = { "Accept" => "application/json" }
|
59
59
|
|
60
|
-
uri = "
|
60
|
+
uri = "/#{version.to_s}/#{endpoint.to_s}"
|
61
61
|
uri += URI.escape "?query=#{query.to_json}" unless query.nil? or query.empty?
|
62
62
|
|
63
63
|
resp = http.get(uri, headers)
|
data/ruby-puppetdb.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.add_dependency('json')
|
18
|
+
s.add_dependency('chronic')
|
18
19
|
|
19
20
|
s.add_development_dependency 'rspec', '2.13'
|
20
21
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-puppetdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Bode
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: chronic
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rspec
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|