| 1 |
#!/usr/bin/python |
| 2 |
# |
| 3 |
# (c) 2011-2016 Dennis Kaarsemaker <[email protected]> |
| 4 |
# see COPYING for license details |
| 5 |
|
| 6 |
try: |
| 7 |
import ConfigParser |
| 8 |
except ImportError: |
| 9 |
import configparser as ConfigParser |
| 10 |
import optparse |
| 11 |
import elasticsearch |
| 12 |
from pprint import pprint |
| 13 |
import os |
| 14 |
|
| 15 |
def main(): |
| 16 |
usage = """%prog [options]""" |
| 17 |
p = optparse.OptionParser(usage=usage) |
| 18 |
p.add_option("-c", "--config", dest="config", default="~/.ilo.conf", |
| 19 |
help="File containing authentication and config details", metavar="FILE") |
| 20 |
|
| 21 |
opts, args = p.parse_args() |
| 22 |
|
| 23 |
if args: |
| 24 |
p.print_help() |
| 25 |
p.exit(1) |
| 26 |
|
| 27 |
es = None |
| 28 |
if os.path.exists(os.path.expanduser(opts.config)): |
| 29 |
config = ConfigParser.ConfigParser() |
| 30 |
config.read(os.path.expanduser(opts.config)) |
| 31 |
if config.has_option('elasticsearch', 'host'): |
| 32 |
es = elasticsearch.Elasticsearch(config.get('elasticsearch', 'host')) |
| 33 |
if not es: |
| 34 |
es = elasticsearch.Elasticsearch() |
| 35 |
|
| 36 |
request = {'query': {'match_all': {}}, 'size': 20000} |
| 37 |
ilos = es.search(index='hpilo', doc_type='hpilo', body=request) |
| 38 |
for ilo in ilos['hits']['hits']: |
| 39 |
pprint(ilo['_source']) |
| 40 |
|
| 41 |
if __name__ == '__main__': |
| 42 |
main() |