7 def self.add_fact(prefix, key, value)
8 key = "#{prefix}_#{key}".to_sym
16 dir_prefix = '/etc/elasticsearch'
19 # only when the directory exists we need to process the stuff
20 if File.directory?(dir_prefix)
22 Dir.foreach(dir_prefix) { |dir|
24 if File.exists?("#{dir_prefix}/#{dir}/elasticsearch.yml")
25 config_data = YAML.load_file("#{dir_prefix}/#{dir}/elasticsearch.yml")
26 unless config_data['http'].nil?
27 next if config_data['http']['enabled'] == 'false'
28 if config_data['http']['port'].nil?
31 port = config_data['http']['port']
43 add_fact('elasticsearch', 'ports', ports.join(",") )
46 key_prefix = "elasticsearch_#{port}"
48 uri = URI("http://localhost:#{port}")
49 json_data = JSON.parse(Net::HTTP.get(uri))
50 next if json_data['status'] && json_data['status'] != 200
52 add_fact(key_prefix, 'name', json_data['name'])
53 add_fact(key_prefix, 'version', json_data['version']['number'])
55 uri2 = URI("http://localhost:#{port}/_nodes/#{json_data['name']}")
56 json_data_node = JSON.parse(Net::HTTP.get(uri2))
58 add_fact(key_prefix, 'cluster_name', json_data_node['cluster_name'])
59 node_data = json_data_node['nodes'].first
61 add_fact(key_prefix, 'node_id', node_data[0])
63 nodes_data = json_data_node['nodes'][node_data[0]]
65 process = nodes_data['process']
66 add_fact(key_prefix, 'mlockall', process['mlockall'])
68 plugins = nodes_data['plugins']
71 plugins.each do |plugin|
72 plugin_names << plugin['name']
74 plugin.each do |key, value|
75 prefix = "#{key_prefix}_plugin_#{plugin['name']}"
76 add_fact(prefix, key, value) unless key == 'name'
79 add_fact(key_prefix, 'plugins', plugin_names.join(","))