Skip to content

Instantly share code, notes, and snippets.

@teknofire
Last active November 9, 2018 17:07
Show Gist options
  • Save teknofire/1d30e85ee31dfab864666a3ffcbb71e4 to your computer and use it in GitHub Desktop.
Save teknofire/1d30e85ee31dfab864666a3ffcbb71e4 to your computer and use it in GitHub Desktop.
#!/opt/delivery/embedded/bin/ruby
require 'json'
require 'pp'
days = ARGV.first
days ||= 3
STDERR.puts "Fetching #{days} days of compliance indices"
all_indices = JSON.parse(`curl -s -k -XGET 'localhost:9200/_cat/indices?format=json'`)
indices = all_indices.select{ |i| i['index'].include?('compliance-2') }.map{ |i| i['index'] }.sort.reverse[0...days.to_i]
STDERR.puts "Found the following indices: #{indices.inspect}"
STDERR.puts "Fetching data from ES"
data = `curl -s -k -XGET 'localhost:9200/#{indices.join(',')}/_search?size=10000'`
json = JSON.parse(data)
STDERR.puts "Parsing ES results"
node_list = json['hits']['hits'].inject({}) do |collector, node|
source = node['_source']
uuid = source['node_uuid']
if !uuid.nil?
collector[uuid] ||= []
node_info = { name: source['node_name'] }
collector[uuid] << node_info unless collector[uuid].include?(node_info)
end
collector
end
node_list.reject! { |id,nodes| nodes.count <= 1 }
if node_list.keys.count > 0
STDERR.puts "Here are the nodes with duplicate data collector UUIDs"
node_list.values.flatten.each do |node|
puts node[:name]
end
else
STDERR.puts "No nodes with duplicate data collector uuids were where found"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment