grunk 0.0.1

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 +55 -0
  2. metadata +59 -0
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'splunk'
4
+ require 'getopt/std'
5
+
6
+ options = Hash.new
7
+ options[:time] = false
8
+ options[:show_source] = false
9
+ options[:max_results] = 30
10
+ options[:earliest_time] = '-1d'
11
+ options[:latest_time] = 'now'
12
+
13
+ opt = Getopt::Std.getopts "sdom:f:t:"
14
+
15
+ if opt["t"]
16
+ options[:latest_time] = opt["t"]
17
+ end
18
+
19
+ if opt["f"]
20
+ options[:earliest_time] = opt["f"]
21
+ end
22
+
23
+ if opt["s"]
24
+ options[:show_source] = true
25
+ end
26
+
27
+ if opt["d"]
28
+ options[:time] = true
29
+ end
30
+
31
+ if opt["o"]
32
+ options[:show_host] = true
33
+ end
34
+
35
+ if opt["m"]
36
+ options[:max_results] = opt["m"].to_i
37
+ end
38
+
39
+ config = YAML.load_file "#{ENV['HOME']}/.grunkrc"
40
+
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
+ results.each do |result|
45
+ print "#{result[:_time]}: " if options[:time]
46
+ if options[:show_host] || options[:show_source]
47
+ print "("
48
+ print result[:host] if options[:show_host]
49
+ print ":" if options[:show_host] && options[:show_source]
50
+ print result[:source] if options[:show_source]
51
+ print ") "
52
+ end
53
+
54
+ puts result[:_raw]
55
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grunk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Beresford
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-24 00:00:00.000000000 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-splunk
17
+ requirement: &70166830835500 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70166830835500
26
+ description: Command Line interface to Splunk API
27
+ email: beezly@beez.ly
28
+ executables:
29
+ - grunk
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - bin/grunk
34
+ has_rdoc: true
35
+ homepage: http://github.com/beezly/grunk
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.6.2
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Grep for Splunk
59
+ test_files: []