plunk 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b0870feaf4598dab6fc0dd14cfe797021d15e22
4
- data.tar.gz: d65d9025b1384cd446da54d75091a8c072eb2986
3
+ metadata.gz: c74090ae720297508b3052f062ce3376ecde58d3
4
+ data.tar.gz: 1d61ecb3d0d944391f80ea30be02470fad915c08
5
5
  SHA512:
6
- metadata.gz: a12882302f751b913ff4bab7157d26603ad8433ac2858a5de85dec4f9afe6d8a56d5308658e013cb1957effa9dee63f0640147b903e3fb5913befb5f42516d94
7
- data.tar.gz: a8fe3b9d113537ed09113f3e69570381254e0c7dc3d21f7813576807a7311063eefb6a7adf2e7d5f07307eec968e4e2e045e2c81d794f1bce3beea4e44a9b541
6
+ metadata.gz: 5ab3dadd247100ca75f8cc39661adc5a80e3f586d1599a3c10f81a964ee04beffa01cfa13a516c707decde2f37bce0259df252f758156264fcd063c22f93118f
7
+ data.tar.gz: 33b135c700a1a800e0d7b4a7f0a96f67af97cf5345bd4b285d0239ba08771976febd035f6668fb5e2e0f8a24814616afc62511a47865ea26b501972fbadc214f
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plunk (0.3.8)
4
+ plunk (0.3.11)
5
5
  activesupport (~> 4.0, >= 4.0.0)
6
6
  chronic (~> 0.10, >= 0.10.0)
7
7
  elasticsearch (~> 1.0, >= 1.0.0)
@@ -11,7 +11,7 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (4.1.0)
14
+ activesupport (4.1.4)
15
15
  i18n (~> 0.6, >= 0.6.9)
16
16
  json (~> 1.7, >= 1.7.7)
17
17
  minitest (~> 5.1)
@@ -20,34 +20,38 @@ GEM
20
20
  blankslate (2.1.2.4)
21
21
  chronic (0.10.2)
22
22
  diff-lcs (1.2.5)
23
- elasticsearch (1.0.1)
24
- elasticsearch-api (= 1.0.1)
25
- elasticsearch-transport (= 1.0.1)
26
- elasticsearch-api (1.0.1)
23
+ elasticsearch (1.0.4)
24
+ elasticsearch-api (= 1.0.4)
25
+ elasticsearch-transport (= 1.0.4)
26
+ elasticsearch-api (1.0.4)
27
27
  multi_json
28
- elasticsearch-transport (1.0.1)
28
+ elasticsearch-transport (1.0.4)
29
29
  faraday
30
30
  multi_json
31
31
  faraday (0.9.0)
32
32
  multipart-post (>= 1.2, < 3)
33
- i18n (0.6.9)
33
+ i18n (0.6.11)
34
34
  json (1.8.1)
35
- minitest (5.3.2)
36
- multi_json (1.9.2)
35
+ minitest (5.4.0)
36
+ multi_json (1.10.1)
37
37
  multipart-post (2.0.0)
38
- parslet (1.5.0)
38
+ parslet (1.6.1)
39
39
  blankslate (~> 2.0)
40
- rspec (2.14.1)
41
- rspec-core (~> 2.14.0)
42
- rspec-expectations (~> 2.14.0)
43
- rspec-mocks (~> 2.14.0)
44
- rspec-core (2.14.8)
45
- rspec-expectations (2.14.5)
46
- diff-lcs (>= 1.1.3, < 2.0)
47
- rspec-mocks (2.14.6)
48
- thread_safe (0.3.3)
40
+ rspec (3.1.0)
41
+ rspec-core (~> 3.1.0)
42
+ rspec-expectations (~> 3.1.0)
43
+ rspec-mocks (~> 3.1.0)
44
+ rspec-core (3.1.3)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-expectations (3.1.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.1.0)
49
+ rspec-mocks (3.1.0)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-support (3.1.0)
52
+ thread_safe (0.3.4)
49
53
  timecop (0.7.1)
50
- tzinfo (1.1.0)
54
+ tzinfo (1.2.1)
51
55
  thread_safe (~> 0.1)
52
56
 
53
57
  PLATFORMS
@@ -55,5 +59,5 @@ PLATFORMS
55
59
 
56
60
  DEPENDENCIES
57
61
  plunk!
58
- rspec (~> 2.0, >= 2.14.1)
62
+ rspec (~> 3.1, >= 3.1.0)
59
63
  timecop (~> 0.7, >= 0.7.1)
data/README.md CHANGED
@@ -1,116 +1 @@
1
- Plunk
2
- =====
3
-
4
- Human-friendly query language for Elasticsearch
5
-
6
- ## About
7
-
8
- Plunk is a ruby gem to take a human-friendly, one-line search command and
9
- translate it to full-fledged JSON to send to Elasticsearch. Currently it only
10
- supports a few commands, but the goal is to support a large subset of what
11
- Elasticsearch offers.
12
-
13
- ## Installation
14
- ```
15
- gem install plunk
16
- ```
17
-
18
- Plunk uses [Parslet](https://github.com/kschiess/parslet) to first parse your
19
- query, and then [Elasticsearch's official ruby library](https://github.com/elasticsearch/elasticsearch-ruby)
20
- to send it to Elasticsearch.
21
-
22
- ## Usage
23
- ```ruby
24
- require 'plunk'
25
-
26
- #
27
- # Configuration is required before using Plunk
28
- #
29
- # Elasticsearch_options accepts the same params as Elasticsearch::Client
30
- # from the elasticsearch-ruby library
31
- Plunk.configure do |config|
32
- config.elasticsearch_options = { host: 'localhost' }
33
- end
34
-
35
- # Restrict timeframe to last 1 week and match documents with _type=syslog
36
- # s = seconds
37
- # m = minutes
38
- # h = hours
39
- # d = days
40
- # w = weeks
41
- # All times in Plunk are converted to UTC
42
- Plunk.search 'last 1w AND _type = syslog'
43
-
44
- # The ```window``` command can also be used to filter by time
45
- Plunk.search 'window -2d to -1d'
46
-
47
- # Plunk tries to parse the date with Chronic, so this works too. Note the
48
- # double quotes around the time string. This is needed if it contains a space.
49
- Plunk.search 'window "last monday" to "last thursday"'
50
-
51
- # Of course, absolute dates are supported as well. Date format is American style
52
- # e.g. MM/DD/YY
53
- Plunk.search 'window 3/14/12 to 3/15/12'
54
-
55
- # Use double quotes to wrap space-containing strings
56
- Plunk.search 'http.header = "UserAgent: Mozilla/5.0"'
57
-
58
- # Commands are joined using parenthesized booleans
59
- Plunk.search '(last 1h AND severity = 5) OR (last 1w AND severity = 3)'
60
-
61
- # "AND" is aliased to "and" and "&". Similarly, "OR" is aliased to "or" and "|".
62
- # The following queries are identical to one above
63
- Plunk.search '(last 1h and severity = 5) or (last 1w and severity = 3)'
64
- Plunk.search '(last 1h & severity = 5) | (last 1w & severity = 3)'
65
-
66
- # Use the NOT keyword to negate the following command or boolean chain
67
- Plunk.search 'NOT message = Error'
68
-
69
- # Like AND and OR, "NOT" is aliased to "not" and "~"
70
- Plunk.search 'not message = Error'
71
- Plunk.search '~ message = Error'
72
-
73
- # Regexp is supported as well
74
- Plunk.search 'http.headers = /.*User-Agent: Mozilla.*/ OR http.headers = /.*application\/json.*/'
75
- ```
76
-
77
-
78
- ## Translation
79
-
80
- Under the hood, Plunk takes your query and translates it to
81
- Elasticsearch-compatible JSON. For example,
82
-
83
- ```last 24h & _type=syslog```
84
-
85
- gets translated to:
86
-
87
- ```json
88
- {
89
- "query": {
90
- "filtered": {
91
- "filter": {
92
- "and": [
93
- {
94
- "range": {
95
- "timestamp": {
96
- "gte": "2013-08-23T05:43:13.770Z",
97
- "lte": "2013-08-24T05:43:13.770Z"
98
- }
99
- }
100
- },
101
- {
102
- "query": {
103
- "query_string": {
104
- "query": "_type:syslog"
105
- }
106
- }
107
- }
108
- ]
109
- }
110
- }
111
- }
112
- }
113
- ```
114
-
115
- In general, commands are combined into a single filter using Elasticsearch's,
116
- ```and```, ```or```, and ```not``` filters.
1
+ This gem has been renamed to <a href="https://github.com/elbii/peruse">Peruse</a>.
data/bin/plunk CHANGED
@@ -3,6 +3,8 @@ $LOAD_PATH << './lib'
3
3
  require 'plunk'
4
4
  require 'optparse'
5
5
 
6
+ warn "[DEPRECATION] This gem has been renamed to peruse and will no longer be supported. Please switch to peruse as soon as possible."
7
+
6
8
  options = {}
7
9
  OptionParser.new do |opts|
8
10
  opts.banner = "Usage: plunk [options]"
@@ -13,29 +15,62 @@ OptionParser.new do |opts|
13
15
  "-h",
14
16
  "--host HOST",
15
17
  "comma-separated list of Elasticsearch hosts to use"
16
- ) do |h|
17
-
18
- options[:host] = h
18
+ ) do |option|
19
+ options[:host] = option
19
20
  end
20
21
 
21
22
  opts.on(
22
23
  "-p",
23
24
  "--parse-only",
24
25
  "parse but don't execute query, returning ES-compatible JSON"
25
- ) do |p|
26
+ ) do |option|
27
+ options[:parse_only] = option
28
+ end
26
29
 
27
- options[:parse_only] = p
30
+ opts.on(
31
+ "-s",
32
+ "--size SIZE",
33
+ "max number of hits to return"
34
+ ) do |option|
35
+ options[:size] = option
36
+ end
37
+
38
+ opts.on(
39
+ "-r",
40
+ "--randomize-hosts",
41
+ "randomize hosts used for each search"
42
+ ) do |option|
43
+ options[:randomize_hosts] = option
28
44
  end
29
45
 
46
+ opts.on(
47
+ "-t",
48
+ "--timestamp-field FIELD",
49
+ "timestamp field to use for timerange searches"
50
+ ) do |option|
51
+ options[:timestamp_field] = option
52
+ end
53
+
54
+ opts.on(
55
+ "-d",
56
+ "--debug",
57
+ "turn on debugging output"
58
+ ) do |option|
59
+ options[:debug] = option
60
+ end
30
61
 
31
62
  end.parse!
32
63
 
33
64
  Plunk.configure do |c|
34
65
  c.parse_only = options[:parse_only]
66
+ c.max_number_of_hits = options[:size].to_i if options[:size]
67
+ c.timestamp_field =
68
+ options[:timestamp_field].strip if options[:timstamp_field]
69
+ c.logger = Logger.new(STDOUT) if options[:debug]
35
70
 
36
71
  c.elasticsearch_client = Elasticsearch::Client.new(
37
- host: options[:host].split(','),
38
- randomize_hosts: true
72
+ host: options[:host].split(',').collect! { |h| h.strip },
73
+ randomize_hosts: options[:randomize_hosts]
39
74
  ) unless c.parse_only
40
75
  end
41
76
 
@@ -1,3 +1,3 @@
1
1
  module Plunk
2
- VERSION = "0.3.11"
2
+ VERSION = "0.3.12"
3
3
  end
@@ -4,19 +4,24 @@ require File.expand_path('../lib/plunk/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "plunk"
6
6
  s.version = Plunk::VERSION
7
+ s.required_ruby_version = ">= 1.9.3"
7
8
  s.add_runtime_dependency "json", "~> 1.8", ">= 1.8.0"
8
9
  s.add_runtime_dependency "parslet", "~> 1.5", ">= 1.5.0"
9
10
  s.add_runtime_dependency "elasticsearch", "~> 1.0", ">= 1.0.0"
10
11
  s.add_runtime_dependency "activesupport", "~> 4.0", ">= 4.0.0"
11
12
  s.add_runtime_dependency "chronic", "~> 0.10", ">= 0.10.0"
12
- s.add_development_dependency "rspec", "~> 2.0", ">= 2.14.1"
13
+ s.add_development_dependency "rspec", "~> 3.1", ">= 3.1.0"
13
14
  s.add_development_dependency "timecop", "~> 0.7", ">= 0.7.1"
14
15
  s.executables << "plunk"
15
16
  s.summary = "Elasticsearch query language"
16
17
  s.description = "Human-friendly query language for Elasticsearch"
17
- s.authors = ["Ram Mehta", "Jamil Bou Kheir", "Roman Heinrich"]
18
- s.email = ["ram.mehta@gmail.com", "jamil@elbii.com", "roman.heinrich@gmail.com"]
18
+ s.authors = ["Ram Mehta", "Jamil Bou Kheir"]
19
+ s.email = ["ram.mehta@gmail.com", "jamil@elbii.com"]
19
20
  s.files = `git ls-files`.split("\n")
20
21
  s.homepage = "https://github.com/elbii/plunk"
21
22
  s.license = "MIT"
23
+ s.post_install_message = <<-MESSAGE
24
+ ! The 'plunk' gem has been deprecated and replaced by 'peruse'. Please switch to the new gem as soon as possible.
25
+ ! See more at https://github.com/elbii/plunk
26
+ MESSAGE
22
27
  end
@@ -19,21 +19,21 @@ describe 'basic searches' do
19
19
 
20
20
  it 'should parse bar' do
21
21
  result = Plunk.search 'bar'
22
- result.should eq(basic_builder('bar'))
22
+ expect(result).to eq(basic_builder('bar'))
23
23
  end
24
24
 
25
25
  it 'should parse bar ' do
26
26
  result = Plunk.search 'bar '
27
- result.should eq(basic_builder('bar'))
27
+ expect(result).to eq(basic_builder('bar'))
28
28
  end
29
29
 
30
30
  it 'should parse (bar) ' do
31
31
  result = Plunk.search '(bar) '
32
- result.should eq(basic_builder('bar'))
32
+ expect(result).to eq(basic_builder('bar'))
33
33
  end
34
34
 
35
35
  it 'should parse bar ' do
36
36
  result = Plunk.search ' bar '
37
- result.should eq(basic_builder('bar'))
37
+ expect(result).to eq(basic_builder('bar'))
38
38
  end
39
39
  end
@@ -0,0 +1,33 @@
1
+ require 'open3'
2
+
3
+ describe 'binstub' do
4
+ it 'should execute a valid query from stdin' do
5
+ result = ""
6
+
7
+ Open3.popen3(
8
+ "bin/plunk",
9
+ "-h localhost,127.0.0.1",
10
+ "-s 1",
11
+ "-r",
12
+ "-d",
13
+ "-t timestamp"
14
+ ) do |stdin, stdout, stderr|
15
+ stdin.puts "last 1w"
16
+ stdin.close
17
+ result = stdout.read.chomp
18
+ end
19
+
20
+ expect(result).to be_present
21
+ end
22
+
23
+ it 'should not allow invalid options' do
24
+ exit_status = -1
25
+
26
+ Open3.popen3("bin/plunk", "-z") do |stdin, stdout, stderr, thread|
27
+ exit_status = thread.value.exitstatus
28
+ end
29
+
30
+
31
+ expect(exit_status).to eq 1
32
+ end
33
+ end
@@ -13,17 +13,17 @@ describe 'nested searches' do
13
13
  arr: [ 0, 1, 2, 3 ],
14
14
  :timestamp => @time.utc.to_datetime.iso8601(3)
15
15
  }.to_json
16
- Plunk::ResultSet.any_instance.stub(:eval).and_return(fake_results)
16
+ allow_any_instance_of(Plunk::ResultSet).to receive(:eval).and_return(fake_results)
17
17
  end
18
18
 
19
- pending 'should transform' do
19
+ skip 'should transform' do
20
20
  results = @transformer.apply @parser.parse('foo=`bar=baz|baz,fass,fdsd`')
21
21
  expect(results.query).to eq({query:{filtered:{query:{query_string:{
22
22
  query: 'foo:(5)'
23
23
  }}}}})
24
24
  end
25
25
 
26
- pending 'should parse a nested basic search' do
26
+ skip 'should parse a nested basic search' do
27
27
  @parsed = @parser.parse 'tshark.len = ` 226 | tshark.frame.time_epoch,tshark.ip.src`'
28
28
  expect(@parsed[:field].to_s).to eq 'tshark.len'
29
29
  expect(@parsed[:op].to_s).to eq '='
@@ -31,7 +31,7 @@ describe 'nested searches' do
31
31
  expect(@parsed[:value][:extractors].to_s).to eq 'tshark.frame.time_epoch,tshark.ip.src'
32
32
  end
33
33
 
34
- pending 'should parse a nested regexp' do
34
+ skip 'should parse a nested regexp' do
35
35
  @parsed = @parser.parse 'tshark.len = ` cif.malicious_ips=/foo/ | tshark.frame.time_epoch,tshark.ip.src`'
36
36
  expect(@parsed[:field].to_s).to eq 'tshark.len'
37
37
  expect(@parsed[:op].to_s).to eq '='
@@ -41,7 +41,7 @@ describe 'nested searches' do
41
41
  expect(@parsed[:value][:extractors].to_s).to eq 'tshark.frame.time_epoch,tshark.ip.src'
42
42
  end
43
43
 
44
- pending 'should parse a nested basic boolean' do
44
+ skip 'should parse a nested basic boolean' do
45
45
  @parsed = @parser.parse 'tshark.len = `(foo OR bar) | tshark.frame.time_epoch,tshark.ip.src`'
46
46
  expect(@parsed[:field].to_s).to eq 'tshark.len'
47
47
  expect(@parsed[:op].to_s).to eq '='
@@ -49,7 +49,7 @@ describe 'nested searches' do
49
49
  expect(@parsed[:value][:extractors].to_s).to eq 'tshark.frame.time_epoch,tshark.ip.src'
50
50
  end
51
51
 
52
- pending 'should parse a nested field / value boolean' do
52
+ skip 'should parse a nested field / value boolean' do
53
53
  @parsed = @parser.parse 'tshark.len = `baz=(foo OR bar AND (bar OR fez)) | tshark.frame.time_epoch,tshark.ip.src`'
54
54
  expect(@parsed[:field].to_s).to eq 'tshark.len'
55
55
  expect(@parsed[:op].to_s).to eq '='
@@ -59,7 +59,7 @@ describe 'nested searches' do
59
59
  expect(@parsed[:value][:extractors].to_s).to eq 'tshark.frame.time_epoch,tshark.ip.src'
60
60
  end
61
61
 
62
- pending 'should parse a nested last standalone timerange' do
62
+ skip 'should parse a nested last standalone timerange' do
63
63
  @parsed = @parser.parse 'tshark.len = `last 24h | tshark.frame.time_epoch,tshark.ip.src`'
64
64
  expect(@parsed[:field].to_s).to eq 'tshark.len'
65
65
  expect(@parsed[:op].to_s).to eq '='
@@ -68,7 +68,7 @@ describe 'nested searches' do
68
68
  expect(@parsed[:value][:extractors].to_s).to eq 'tshark.frame.time_epoch,tshark.ip.src'
69
69
  end
70
70
 
71
- pending 'should parse a nested last timerange and field / value pair' do
71
+ skip 'should parse a nested last timerange and field / value pair' do
72
72
  @parsed = @parser.parse 'tshark.len = `last 24h foo=bar | tshark.frame.time_epoch,tshark.ip.src`'
73
73
  expect(@parsed[:field].to_s).to eq 'tshark.len'
74
74
  expect(@parsed[:op].to_s).to eq '='
@@ -1,5 +1,5 @@
1
1
  shared_context "plunk stubs" do
2
2
  before :each do
3
- Plunk.stub(:timestamp_field).and_return(:@timestamp)
3
+ allow(Plunk).to receive(:timestamp_field).and_return(:@timestamp)
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ram Mehta
8
8
  - Jamil Bou Kheir
9
- - Roman Heinrich
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-05-13 00:00:00.000000000 Z
12
+ date: 2014-10-28 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: json
@@ -118,20 +117,20 @@ dependencies:
118
117
  requirements:
119
118
  - - "~>"
120
119
  - !ruby/object:Gem::Version
121
- version: '2.0'
120
+ version: '3.1'
122
121
  - - ">="
123
122
  - !ruby/object:Gem::Version
124
- version: 2.14.1
123
+ version: 3.1.0
125
124
  type: :development
126
125
  prerelease: false
127
126
  version_requirements: !ruby/object:Gem::Requirement
128
127
  requirements:
129
128
  - - "~>"
130
129
  - !ruby/object:Gem::Version
131
- version: '2.0'
130
+ version: '3.1'
132
131
  - - ">="
133
132
  - !ruby/object:Gem::Version
134
- version: 2.14.1
133
+ version: 3.1.0
135
134
  - !ruby/object:Gem::Dependency
136
135
  name: timecop
137
136
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +155,6 @@ description: Human-friendly query language for Elasticsearch
156
155
  email:
157
156
  - ram.mehta@gmail.com
158
157
  - jamil@elbii.com
159
- - roman.heinrich@gmail.com
160
158
  executables:
161
159
  - plunk
162
160
  extensions: []
@@ -182,6 +180,7 @@ files:
182
180
  - lib/plunk/version.rb
183
181
  - plunk.gemspec
184
182
  - spec/basic_spec.rb
183
+ - spec/binstub_spec.rb
185
184
  - spec/boolean_spec.rb
186
185
  - spec/chained_search_spec.rb
187
186
  - spec/field_value_spec.rb
@@ -199,7 +198,9 @@ homepage: https://github.com/elbii/plunk
199
198
  licenses:
200
199
  - MIT
201
200
  metadata: {}
202
- post_install_message:
201
+ post_install_message: |2
202
+ ! The 'plunk' gem has been deprecated and replaced by 'peruse'. Please switch to the new gem as soon as possible.
203
+ ! See more at https://github.com/elbii/plunk
203
204
  rdoc_options: []
204
205
  require_paths:
205
206
  - lib
@@ -207,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
208
  requirements:
208
209
  - - ">="
209
210
  - !ruby/object:Gem::Version
210
- version: '0'
211
+ version: 1.9.3
211
212
  required_rubygems_version: !ruby/object:Gem::Requirement
212
213
  requirements:
213
214
  - - ">="
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  version: '0'
216
217
  requirements: []
217
218
  rubyforge_project:
218
- rubygems_version: 2.2.2
219
+ rubygems_version: 2.4.2
219
220
  signing_key:
220
221
  specification_version: 4
221
222
  summary: Elasticsearch query language