Skip to content

Commit

Permalink
collective_fact option
Browse files Browse the repository at this point in the history
  • Loading branch information
reguero committed Jun 23, 2016
1 parent b715753 commit 957d958
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Other configuration settings that can be tuned depending our your PuppetDB insta
* discovery.puppetdb.port - The unencrpyted HTTP __or__ SSL port your PuppetDB server listens on. Defaults to 8080
* discovery.puppetdb.use_ssl - Enable using SSL. Defaults to false
* discovery.puppetdb.use_krb - Enable using Kerberos. Defaults to false
* discovery.puppetdb.collective_fact - Define a fact to filter all queries with the value of the collective thus avoiding to fetch all the nodes registered in puppetdb each time. Defaults to false

The following settings should only be configured if you are using SSL communications. They will all be disabled by default.

Expand Down Expand Up @@ -62,3 +63,9 @@ Connect to a remote PuppetDB server using Kerberos
plugin.discovery.puppetdb.ssl_cert = /etc/mcollective/puppetdb/host1.your.com.cert.pem
plugin.discovery.puppetdb.ssl_private_key = /etc/mcollective/puppetdb/host1.your.com.pem

Filter all queries using the hostgroup_0 fact

plugin.discovery.puppetdb.collective_fact = hostgroup_0

The effect would be equivalent to -F hostgroup_0=<collective> in the command line

7 changes: 7 additions & 0 deletions util/puppetdb_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ def initialize(config)
@config[:ssl_cert] = config.pluginconf.fetch('discovery.puppetdb.ssl_cert', nil)
@config[:ssl_key] = config.pluginconf.fetch('discovery.puppetdb.ssl_private_key', nil)
@config[:api_version] = config.pluginconf.fetch('discovery.puppetdb.api_version', '3')
@config[:collective_fact] = config.pluginconf.fetch('discovery.puppetdb.collective_fact', nil)
@http = create_http
end

def discover(filter)
found = []

unless @config[:collective_fact].nil?
unless filter.has_key?('fact')
filter['fact'] = Array.new
end
filter['fact'].push({:fact=>@config[:collective_fact], :value=>filter['collective'], :operator=>"="})
end
#if no filters are to be applied, we fetch all the nodes registered in puppetdb
if filter['fact'].empty? && filter['cf_class'].empty? && filter['identity'].empty?
found = node_search
Expand Down

0 comments on commit 957d958

Please sign in to comment.