grunk 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/bin/grunk +13 -9
  2. metadata +12 -9
data/bin/grunk CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- require 'splunk'
3
+ require 'splunk-sdk-ruby'
4
+ require 'json'
4
5
  require 'getopt/std'
5
6
 
6
7
  options = Hash.new
@@ -36,20 +37,23 @@ if opt["m"]
36
37
  options[:max_results] = opt["m"].to_i
37
38
  end
38
39
 
39
- config = YAML.load_file "#{ENV['HOME']}/.grunkrc"
40
+ rc_file = File.new(File.expand_path('~/.splunkrc'), "r")
41
+ $config = eval(rc_file.read)
42
+
43
+ service = Splunk::Service.new $config
44
+ service.login
45
+ stream = service.create_oneshot "search #{ARGV[0]}", max_results: options[:max_results], earliest_time: options[:earliest_time], latest_time: options['latest_time']
46
+ results = Splunk::ResultsReader.new stream
40
47
 
41
- splunk = Splunk::Splunk.new config['splunk_server'], config['splunk_user'] , config['splunk_pass']
42
- results = splunk.search "#{ARGV[0]}", 'sort_key' => 'time', 'sort_dir' => 'asc', 'count' => options[:max_results], 'earliest_time' => options[:earliest_time], 'latest_time' => options[:latest_time]
43
- results.reverse!
44
48
  results.each do |result|
45
- print "#{result[:_time]}: " if options[:time]
49
+ print "#{result["_time"]}: " if options[:time]
46
50
  if options[:show_host] || options[:show_source]
47
51
  print "("
48
- print result[:host] if options[:show_host]
52
+ print result["host"] if options[:show_host]
49
53
  print ":" if options[:show_host] && options[:show_source]
50
- print result[:source] if options[:show_source]
54
+ print result["source"] if options[:show_source]
51
55
  print ") "
52
56
  end
53
57
 
54
- puts result[:_raw]
58
+ puts result["_raw"]
55
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,20 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 +01:00
13
- default_executable:
12
+ date: 2013-08-22 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: ruby-splunk
17
- requirement: &70166830835500 !ruby/object:Gem::Requirement
15
+ name: splunk-sdk-ruby
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
21
20
  - !ruby/object:Gem::Version
22
- version: 0.0.4
21
+ version: 1.0.2
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *70166830835500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.2
26
30
  description: Command Line interface to Splunk API
27
31
  email: beezly@beez.ly
28
32
  executables:
@@ -31,7 +35,6 @@ extensions: []
31
35
  extra_rdoc_files: []
32
36
  files:
33
37
  - bin/grunk
34
- has_rdoc: true
35
38
  homepage: http://github.com/beezly/grunk
36
39
  licenses: []
37
40
  post_install_message:
@@ -52,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
55
  version: '0'
53
56
  requirements: []
54
57
  rubyforge_project:
55
- rubygems_version: 1.6.2
58
+ rubygems_version: 1.8.24
56
59
  signing_key:
57
60
  specification_version: 3
58
61
  summary: Grep for Splunk