diff --git a/elasticRecheck.conf.sample b/elasticRecheck.conf.sample index 39ccdc37..9207940c 100644 --- a/elasticRecheck.conf.sample +++ b/elasticRecheck.conf.sample @@ -16,3 +16,4 @@ key=/home/mtreinish/.ssh/id_rsa es_url=http://logstash.openstack.org:80/elasticsearch ls_url=http://logstash.openstack.org db_uri=mysql+pymysql://query:query@logstash.openstack.org/subunit2sql +index_format=logstash-%Y.%m.%d \ No newline at end of file diff --git a/elastic_recheck/cmd/query.py b/elastic_recheck/cmd/query.py index ffaa0e98..20dcefa2 100755 --- a/elastic_recheck/cmd/query.py +++ b/elastic_recheck/cmd/query.py @@ -26,6 +26,7 @@ import elastic_recheck.results as er_results LOG = logging.getLogger('erquery') +DEFAULT_INDEX_FORMAT = 'logstash-%Y.%m.%d' DEFAULT_NUMBER_OF_DAYS = 10 DEFAULT_MAX_QUANTITY = 5 IGNORED_ATTRIBUTES = [ @@ -64,9 +65,10 @@ def analyze_attributes(attributes): def query(query_file_name, days=DEFAULT_NUMBER_OF_DAYS, es_url=er.ES_URL, - quantity=DEFAULT_MAX_QUANTITY, verbose=False): + quantity=DEFAULT_MAX_QUANTITY, verbose=False, + indexfmt=DEFAULT_INDEX_FORMAT): - es = er_results.SearchEngine(es_url) + es = er_results.SearchEngine(url=es_url, indexfmt=indexfmt) with open(query_file_name) as f: query_file = yaml.load(f.read()) @@ -119,15 +121,19 @@ def main(): # Start with defaults es_url = er.ES_URL + es_index_format = DEFAULT_INDEX_FORMAT if args.conf: - config = ConfigParser.ConfigParser({'es_url': er.ES_URL}) + config = ConfigParser.ConfigParser({ + 'es_url': er.ES_URL, + 'index_format': DEFAULT_INDEX_FORMAT}) config.read(args.conf) if config.has_section('data_source'): es_url = config.get('data_source', 'es_url') + es_index_format = config.get('data_source', 'index_format') query(args.query_file.name, days=args.days, quantity=args.quantity, - verbose=args.verbose, es_url=es_url) + verbose=args.verbose, es_url=es_url, indexfmt=es_index_format) if __name__ == "__main__": diff --git a/elastic_recheck/results.py b/elastic_recheck/results.py index bf5fc1c9..d43b2976 100644 --- a/elastic_recheck/results.py +++ b/elastic_recheck/results.py @@ -29,8 +29,9 @@ pp = pprint.PrettyPrinter() class SearchEngine(object): """Wrapper for pyelasticsearch so that it returns result sets.""" - def __init__(self, url): + def __init__(self, url, indexfmt='logstash-%Y.%m.%d'): self._url = url + self._indexfmt = indexfmt def search(self, query, size=1000, recent=False, days=0): """Search an elasticsearch server. @@ -56,7 +57,7 @@ class SearchEngine(object): args = {'size': size} if recent or days: # today's index - datefmt = 'logstash-%Y.%m.%d' + datefmt = self._indexfmt now = datetime.datetime.utcnow() indexes = [now.strftime(datefmt)] if recent: