Skip to content

Instantly share code, notes, and snippets.

@mdfranz
Created July 18, 2015 20:16
Show Gist options
  • Save mdfranz/ca1f27541bb5dd74086a to your computer and use it in GitHub Desktop.
Save mdfranz/ca1f27541bb5dd74086a to your computer and use it in GitHub Desktop.
Simple ElasticSearch-DSL Python Example
if __name__ == "__main__":
c = Elasticsearch("http://192.168.2.218:9200")
f = open(sys.argv[1])
for line in f:
# Convert public_hostname to IPs because hostname lookups are failing in ES for some reason
if line.find("ec2") > -1:
host = socket.gethostbyname(line.rstrip().lstrip())
else:
host = line.rstrip().lstrip()
s = Search(using=c, index="_all").filter("term", ec2_public_ipv4=host)
r = s.execute()
for h in r.hits:
print line.rstrip(),host, h['instanceid'], h['facter']['ec2_instance_type'],h['facter']['ec2_placement_availability_zone'],h['os_packages']['tomcat7'],h['os_packages']['openjdk-6-jre-headless'],
dump_webapps(h['webapps'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment