Giter Club home page Giter Club logo

stash-query's Introduction

stash-query

A CLI Tool for Querying Logstash/Elasticsearch and Exporting the results. Uses the Lucene query syntax that Kibana utilizes, but provides the option for exporting.

Usage:

    -c, --connect_host [HOST]        Elasticsearch host to run query on (defaults to: localhost)
    -p, --port [PORT]                Elasticsearch port (defaults to: 9200)
        --ssl                        Elasticsearch port (defaults to no ssl)
    -T, --timefield [FIELDNAME]      Time-field name (defaults to: @timestamp)
        --scroll-size [number of records]
                                     Scroll Size (defaults to: 10).
        --scroll-time [time units]   Scroll Size (defaults to: 30m).
    -i, --index-prefix [PREFIX]      Index name prefix(es). Defaults to 'logstash-'. Comma delimited
    -w, --write [FILE]               Write output file location (defaults to nil)
    -d, --debug                      Debug mode
    -s, --start [DATE]               Start date. Format: YYYY-MM-DDThh:mm:ss.SSSZ. Ex: 2013-12-01T12:00:00.000Z
    -e, --end [DATE]                 End date. Format: YYYY-MM-DDThh:mm:ss.SSSZ
    -q, --query [QUERY]              Query string
    -t, --tags [TAGS]                Tags to query. Comma delimited
    -f, --write-fields [FIELDS]      Comma delimited list of Logstash fields to write to output file. Defaults to "message"
    -l, --delimiter [DELIMITER]      Delimiter to use in output file. Defaults to ","
    -S, --silent                     Run silently
    -m, --max [INTEGER]              Maximum number of results to return. Non-integer arguments default to 0.

Examples:

stash-query -s 2013-12-01T00:00:00.000Z -e 2013-12-02T00:00:00.000Z -t my_tag -q 'message:hello_world' -w /tmp/my_query.txt

To install locally

gem build stash-query.gemspec
 
gem install stash-query-<version>.gem

stash-query's People

Contributors

antonmos avatar robbydyer avatar smcdon avatar wjimenez5271 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

stash-query's Issues

Write fields doesn't have a nice way to get nested data

Hi,

Thanks for writing this tool. I just wanted to flag that getting at specific nested fields is not supported. It's possible to select the parent field for writing and I guess it will to_s the contents.

It'd be nice if I could specify nested fields with a dot notation or something like that.

Cheers,
Tom

./stash-query:146:in `<main>': undefined method `<<' for nil:NilClass (NoMethodError)

I have installed all the required gems:

terminator@helium:~/workspace/stash-query/bin $ [master] ./stash-query -c logstash01.example.com -q 'host:examplehost01' -w /tmp/testit
You have not specified a start and/or end timestamp for your query
I will default to search all existing indices. This will cause
the query to be extremely slow. Shall I continue? (y/n)
y
./stash-query:146:in <main>': undefined method<<' for nil:NilClass (NoMethodError)

I'm not a ruby user btw, Any idea? What is blocking here?
Sorry, if this is a dumb question.

Error writing file

Not entirely sure what's happening here, but:

jantman@phoenix:pts/22:~/tmp$ stash-query -c elsvipprd1.ddtc.cmgdigital.com -s 2014-12-20T00:00:00.000Z -e 2014-12-20T17:00:00.000Z -f '@timestamp,message' -q 'message:"Task medley.ellington_overrides.search.tasks.Solr4HaystackUpdateTaskAWS"'
Found 2247627 results
jantman@phoenix:pts/22:~/tmp$ stash-query -c elsvipprd1.ddtc.cmgdigital.com -s 2014-12-20T00:00:00.000Z -e 2014-12-20T17:00:00.000Z -f '@timestamp,message' -q 'message:"Task medley.ellington_overrides.search.tasks.Solr4HaystackUpdateTaskAWS"' -w solr4_aws_update.csv
Found 2247627 results
[#                                                                                                                                                                                                              ] [    501/2247627] [  0.02%] [00:01] [01:33:45] [    399.45/s]Error writing to file.
/home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:115:in `generate_output': undefined method `each' for #<String:0x00000003eed178> (NoMethodError)
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:90:in `block in flush_to_file'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:88:in `open'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:88:in `flush_to_file'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:228:in `block in run_query'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:224:in `each'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:224:in `run_query'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/lib/stash-query/query.rb:66:in `initialize'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/bin/stash-query:71:in `new'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/gems/stash-query-0.1.2/bin/stash-query:71:in `<top (required)>'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/bin/stash-query:23:in `load'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/bin/stash-query:23:in `<main>'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `eval'
        from /home/jantman/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `<main>'

Exception occurred when found 0 results

root@es# stash-query -s 2013-12-01T00:00:00.000Z -e 2013-12-02T00:00:00.000Z -t my_tag -q 'message:hello_world' -w /tmp/my_query.txt
Found 0 results
/var/lib/gems/1.9.1/gems/progress_bar-1.0.3/lib/progress_bar.rb:18:in `initialize': Max must be a positive integer (ProgressBar::ArgumentError)
        from /var/lib/gems/1.9.1/gems/stash-query-0.1.3/lib/stash-query/query.rb:223:in `new'
        from /var/lib/gems/1.9.1/gems/stash-query-0.1.3/lib/stash-query/query.rb:223:in `run_query'
        from /var/lib/gems/1.9.1/gems/stash-query-0.1.3/lib/stash-query/query.rb:66:in `initialize'
        from /var/lib/gems/1.9.1/gems/stash-query-0.1.3/bin/stash-query:71:in `new'
        from /var/lib/gems/1.9.1/gems/stash-query-0.1.3/bin/stash-query:71:in `<top (required)>'
        from /usr/local/bin/stash-query:23:in `load'
        from /usr/local/bin/stash-query:23:in `<main>'

No search type for [scan]

Encounterd the following error when using with elasticsearch 5.x:

/usr/lib/ruby/gems/2.3.0/gems/elasticsearch-transport-5.0.3/lib/elasticsearch/transport/transport/base.rb:201:in `__raise_transport_error': [400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"No search type for [scan]"}],"type":"illegal_argument_exception","reason":"No search type for [scan]"},"status":400} (Elasticsearch::Transport::Transport::Errors::BadRequest)
        from /usr/lib/ruby/gems/2.3.0/gems/elasticsearch-transport-5.0.3/lib/elasticsearch/transport/transport/base.rb:318:in `perform_request'
        from /usr/lib/ruby/gems/2.3.0/gems/elasticsearch-transport-5.0.3/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
        from /usr/lib/ruby/gems/2.3.0/gems/elasticsearch-transport-5.0.3/lib/elasticsearch/transport/client.rb:131:in `perform_request'
        from /usr/lib/ruby/gems/2.3.0/gems/elasticsearch-api-5.0.3/lib/elasticsearch/api/actions/search.rb:179:in `search'
        from /usr/lib/ruby/gems/2.3.0/gems/stash-query-0.1.3/lib/stash-query/query.rb:213:in `run_query'
        from /usr/lib/ruby/gems/2.3.0/gems/stash-query-0.1.3/lib/stash-query/query.rb:66:in `initialize'
        from /usr/lib/ruby/gems/2.3.0/gems/stash-query-0.1.3/bin/stash-query:71:in `new'
        from /usr/lib/ruby/gems/2.3.0/gems/stash-query-0.1.3/bin/stash-query:71:in `'
        from /usr/bin/stash-query:23:in `load'
        from /usr/bin/stash-query:23:in `'

Scan was removed from search types in favor of scroll with {"sort": ["_doc"]}.

5.x Search type changes

not picking up -i option

the -i option is not taking effect. line 63 appears to be the culprit.
:index_prefixes => [ "logstash-", "logstash-cdr-", "logstash-haproxy-" ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.