Class: PEClient::Resource::PuppetDB::QueryV4
- Defined in:
- lib/pe_client/resources/puppet_db/query.v4.rb,
lib/pe_client/resources/puppet_db/query.v4/nodes.rb,
lib/pe_client/resources/puppet_db/query.v4/reports.rb,
lib/pe_client/resources/puppet_db/query.v4/catalogs.rb,
lib/pe_client/resources/puppet_db/query.v4/factsets.rb
Overview
PuppetDB’s query API can retrieve data objects from PuppetDB for use in other applications.
Defined Under Namespace
Classes: Catalogs, Factsets, Nodes, Reports
Constant Summary collapse
Class Method Summary collapse
-
.query_paging(**kwargs) ⇒ Hash
private
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results.
Instance Method Summary collapse
-
#aggregate_event_counts(summarize_by:, count_by: nil, counts_filter: nil, distinct_resources: nil, query: nil) ⇒ Array<Hash>
The aggregate_event_counts endpoint is designated as experimental.
- #catalogs ⇒ QueryV4::Catalogs
-
#edges(query: nil, **kwargs) ⇒ Hash+
Catalog edges are relationships formed between two resources.
-
#environments(environment: nil, type: nil, query: nil, **kwargs) ⇒ Hash+
Environments are semi-isolated groups of nodes managed by Puppet.
-
#event_counts(summarize_by:, count_by: nil, counts_filter: nil, distinct_resources: nil, query: nil, **kwargs) ⇒ Hash+
The event_counts endpoint is designated as experimental.
-
#events(distinct_resources: nil, distinct_start_time: nil, distinct_end_time: nil, query: nil, **kwargs) ⇒ Hash+
Puppet agent nodes submit reports after their runs, and the Puppet Server forwards these to PuppetDB.
-
#fact_contents(query: nil, **kwargs) ⇒ Hash+
The fact_contents endpoint provides selective access to factset subtrees via fact paths.
-
#fact_names(query: nil, **kwargs) ⇒ Hash, Array<String>
The fact_names endpoint can be used to retrieve all known fact names.
-
#fact_paths(query: nil, **kwargs) ⇒ Hash, Array<String>
The fact_paths endpoint retrieves the set of all known fact paths for all known nodes, and is intended as a counterpart to the #fact_names endpoint, providing increased granularity around structured facts.
-
#facts(fact_name: nil, value: nil, query: nil, **kwargs) ⇒ Hash+
The facts endpoint provides access to a representation of node factsets where a result is returned for each top-level key in the node’s structured factset.
- #factsets ⇒ QueryV4::Factsets
-
#inventory(query: nil, **kwargs) ⇒ Hash+
The inventory endpoint provides an alternate and potentially more efficient way to access structured facts as compared to the #facts, #fact_contents, and #factsets endpoints.
- #nodes ⇒ QueryV4::Nodes
-
#package_inventory(certname: nil, query: nil, **kwargs) ⇒ Hash+
Returns all installed packages along with the certname of the nodes they are installed on or a specific node.
-
#packages(query: nil, **kwargs) ⇒ Hash+
Returns all installed packages, across all nodes.
-
#producers(producer: nil, type: nil, query: nil, **kwargs) ⇒ Hash+
Producers are the Puppet Servers that send reports, catalogs, and factsets to PuppetDB.
- #reports ⇒ QueryV4::Reports
-
#resources(type: nil, title: nil, query: nil, **kwargs) ⇒ Hash+
You can query resources by making an HTTP request to the resources endpoint.
-
#root(query:, timeout: nil, ast_only: nil, origin: nil, explain: nil, **kwargs) ⇒ Hash+
The root query endpoint can be used to retrieve any known entities from a single endpoint.
Methods inherited from Base
Constructor Details
This class inherits a constructor from PEClient::Resource::Base
Class Method Details
.query_paging(**kwargs) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
363 364 365 366 367 368 369 370 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 363 def self.query_paging(**kwargs) { order_by: kwargs[:order_by], limit: kwargs[:limit], include_total: kwargs[:include_total], offset: kwargs[:offset] } end |
Instance Method Details
#aggregate_event_counts(summarize_by:, count_by: nil, counts_filter: nil, distinct_resources: nil, query: nil) ⇒ Array<Hash>
The aggregate_event_counts endpoint is designated as experimental. It may be altered or removed in a future release. Puppet agent nodes submit reports after their runs, and the Puppet Server forwards these to PuppetDB. Each report includes:
-
Data about the entire run.
-
Metadata about the report.
-
Many events, describing what happened during the run.
After this information is stored in PuppetDB, it can be queried in various ways.
-
You can query data about the run and report metadata by making an HTTP request to the #reports endpoint.
-
You can query data about individual events by making an HTTP request to the #events endpoint.
-
You can query summaries of event data by making an HTTP request to the #event_counts or #aggregate_event_counts endpoints.
305 306 307 308 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 305 def aggregate_event_counts(summarize_by:, count_by: nil, counts_filter: nil, distinct_resources: nil, query: nil) @client.get "#{BASE_PATH}/aggregate-event-counts", params: {summarize_by:, count_by:, counts_filter: counts_filter&.to_json, distinct_resources:, query: query&.to_json}.compact end |
#catalogs ⇒ QueryV4::Catalogs
350 351 352 353 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 350 def catalogs require_relative "query.v4/catalogs" @catalogs ||= QueryV4::Catalogs.new(@client) end |
#edges(query: nil, **kwargs) ⇒ Hash+
Catalog edges are relationships formed between two resources. They represent the edges inside the catalog graph, whereas resources represent the nodes in the graph. You can query edges by making a request to the edges endpoint.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
222 223 224 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 222 def edges(query: nil, **kwargs) @client.get "#{BASE_PATH}/edges", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#environments(environment: nil, type: nil, query: nil, **kwargs) ⇒ Hash+
Environments are semi-isolated groups of nodes managed by Puppet. Nodes are assigned to environments by their own configuration, or by the Puppet Server’s external node classifier. When PuppetDB collects info about a node, it keeps track of the environment the node is assigned to. PuppetDB also keeps a list of environments it has seen. You can query this list by making an HTTP request to the environments endpoint.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
99 100 101 102 103 104 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 99 def environments(environment: nil, type: nil, query: nil, **kwargs) uri = "#{BASE_PATH}/environments" uri += "/#{environment}" if environment uri += "/#{type}" if environment && type @client.get uri, params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#event_counts(summarize_by:, count_by: nil, counts_filter: nil, distinct_resources: nil, query: nil, **kwargs) ⇒ Hash+
The event_counts endpoint is designated as experimental. It may be altered or removed in a future release. Puppet agent nodes submit reports after their runs, and the Puppet Server forwards these to PuppetDB. Each report includes:
-
Data about the entire run
-
Metadata about the report
-
Many events, describing what happened during the run
After this information is stored in PuppetDB, it can be queried in various ways.
-
You can query data about the run and report metadata by making an HTTP request to the #reports endpoint.
-
You can query data about individual events by making an HTTP request to the #events endpoint.
-
You can query summaries of event data by making an HTTP request to the #event_counts or #aggregate_event_counts endpoints.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
277 278 279 280 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 277 def event_counts(summarize_by:, count_by: nil, counts_filter: nil, distinct_resources: nil, query: nil, **kwargs) @client.get "#{BASE_PATH}/event-counts", params: {summarize_by:, count_by:, counts_filter: counts_filter&.to_json, distinct_resources:, query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#events(distinct_resources: nil, distinct_start_time: nil, distinct_end_time: nil, query: nil, **kwargs) ⇒ Hash+
Puppet agent nodes submit reports after their runs, and the Puppet Server forwards these to PuppetDB. Each report includes:
-
Data about the entire run
-
Metadata about the report
-
Many events, describing what happened during the run
After this information is stored in PuppetDB, it can be queried in various ways.
-
You can query data about the run and report metadata by making an HTTP request to the #reports endpoint.
-
You can query data about individual events by making an HTTP request to the #events endpoint.
-
You can query summaries of event data by making an HTTP request to the #event_counts or #aggregate_event_counts endpoints.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
248 249 250 251 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 248 def events(distinct_resources: nil, distinct_start_time: nil, distinct_end_time: nil, query: nil, **kwargs) @client.get "#{BASE_PATH}/events", params: {distinct_resources:, distinct_start_time:, distinct_end_time:, query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#fact_contents(query: nil, **kwargs) ⇒ Hash+
The fact_contents endpoint provides selective access to factset subtrees via fact paths. Note that the #inventory endpoint will often provide more flexible and efficient access to the same information.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
179 180 181 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 179 def fact_contents(query: nil, **kwargs) @client.get "#{BASE_PATH}/fact-contents", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#fact_names(query: nil, **kwargs) ⇒ Hash, Array<String>
The fact_names endpoint can be used to retrieve all known fact names.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
153 154 155 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 153 def fact_names(query: nil, **kwargs) @client.get "#{BASE_PATH}/fact-names", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#fact_paths(query: nil, **kwargs) ⇒ Hash, Array<String>
The fact_paths endpoint retrieves the set of all known fact paths for all known nodes, and is intended as a counterpart to the #fact_names endpoint, providing increased granularity around structured facts. The endpoint may be useful for building autocompletion in GUIs or for other applications that require a basic top-level view of fact paths.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
166 167 168 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 166 def fact_paths(query: nil, **kwargs) @client.get "#{BASE_PATH}/fact-paths", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#facts(fact_name: nil, value: nil, query: nil, **kwargs) ⇒ Hash+
The facts endpoint provides access to a representation of node factsets where a result is returned for each top-level key in the node’s structured factset. Note that the #inventory endpoint will often provide more flexible and efficient access to the same information.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
138 139 140 141 142 143 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 138 def facts(fact_name: nil, value: nil, query: nil, **kwargs) uri = "#{BASE_PATH}/facts" uri += "/#{fact_name}" if fact_name uri += "/#{value}" if fact_name && value @client.get uri, params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#factsets ⇒ QueryV4::Factsets
344 345 346 347 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 344 def factsets require_relative "query.v4/factsets" @factsets ||= QueryV4::Factsets.new(@client) end |
#inventory(query: nil, **kwargs) ⇒ Hash+
The inventory endpoint provides an alternate and potentially more efficient way to access structured facts as compared to the #facts, #fact_contents, and #factsets endpoints.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
191 192 193 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 191 def inventory(query: nil, **kwargs) @client.get "#{BASE_PATH}/inventory", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#nodes ⇒ QueryV4::Nodes
338 339 340 341 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 338 def nodes require_relative "query.v4/nodes" @nodes ||= QueryV4::Nodes.new(@client) end |
#package_inventory(certname: nil, query: nil, **kwargs) ⇒ Hash+
Returns all installed packages along with the certname of the nodes they are installed on or a specific node.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
332 333 334 335 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 332 def package_inventory(certname: nil, query: nil, **kwargs) @client.get certname ? "#{BASE_PATH}/package-inventory/#{certname}" : "#{BASE_PATH}/package-inventory", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#packages(query: nil, **kwargs) ⇒ Hash+
Returns all installed packages, across all nodes.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
318 319 320 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 318 def packages(query: nil, **kwargs) @client.get "#{BASE_PATH}/packages", params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#producers(producer: nil, type: nil, query: nil, **kwargs) ⇒ Hash+
Producers are the Puppet Servers that send reports, catalogs, and factsets to PuppetDB. When PuppetDB stores a report, catalog, or factset, it keeps track of the producer of the report/catalog/factset. PuppetDB also keeps a list of producers it has seen. You can query this list by making an HTTP request to the producers endpoint.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
119 120 121 122 123 124 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 119 def producers(producer: nil, type: nil, query: nil, **kwargs) uri = "#{BASE_PATH}/producers" uri += "/#{producer}" if producer uri += "/#{type}" if producer && type @client.get uri, params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#reports ⇒ QueryV4::Reports
356 357 358 359 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 356 def reports require_relative "query.v4/reports" @reports ||= QueryV4::Reports.new(@client) end |
#resources(type: nil, title: nil, query: nil, **kwargs) ⇒ Hash+
You can query resources by making an HTTP request to the resources endpoint.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
205 206 207 208 209 210 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 205 def resources(type: nil, title: nil, query: nil, **kwargs) uri = "#{BASE_PATH}/resources" uri += "/#{type}" if type uri += "/#{URI.encode_www_form_component(title)}" if type && title @client.get uri, params: {query: query&.to_json}.merge!(QueryV4.query_paging(**kwargs)).compact end |
#root(query:, timeout: nil, ast_only: nil, origin: nil, explain: nil, **kwargs) ⇒ Hash+
The root query endpoint can be used to retrieve any known entities from a single endpoint.
Most of PuppetDB’s query endpoints support a general set of HTTP URL parameters that can be used for paging results. PuppetDB also supports paging via query operators, as described in the AST documentation.
80 81 82 83 |
# File 'lib/pe_client/resources/puppet_db/query.v4.rb', line 80 def root(query:, timeout: nil, ast_only: nil, origin: nil, explain: nil, **kwargs) query = query.to_json if query.is_a?(Array) @client.get BASE_PATH, params: {query: query, timeout:, ast_only:, origin:, explain:}.merge!(QueryV4.query_paging(**kwargs)).compact end |