hutils 0.2.3 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6377c61f4cb6224f93e56cb1c0c0a3a2ebec5ec
4
- data.tar.gz: 2f92ed9f0c685c64604dca8f3c9a924e3ab12f50
3
+ metadata.gz: ae97daa9f753f4d2ca5e40dac56ae46403d49f13
4
+ data.tar.gz: ede5236d2a555615a6e4cf90f5386074f403326a
5
5
  SHA512:
6
- metadata.gz: 7e2e50000c379d0d51d45984ac8fb86f83bccfb175c49858d83dcc636c9bcfcbd4f8afb923178ba1acf1a28ff34b2e691d8750cbd5c486b5081a55b134a5534a
7
- data.tar.gz: b7494f90c22b8ae2856804b273450bed52cc7bdda0a5534a40f195526adf4793cee8dd4df21684e20bb47622766d255ff4e23f5f2d0c6467220162e3a64106d7
6
+ metadata.gz: eda70d9d6e3defea2d158964a9a9c78014d0afadbd19b22d928e40089bc4623ac2cb710b561b112d094abca8cc18264eea0c9e6c9d441050d0a4dd9071c185bd
7
+ data.tar.gz: 09ef57610dd6dd8edf8ed516f96a5bbc4da8adbda33c2ce6903746d7e4846039df1ee0b8227ed9044994f7265647568ccf5b5b674718d9a85db6a2f4030487d8
data/bin/ltap CHANGED
@@ -30,8 +30,12 @@ end
30
30
  opts.parse!
31
31
 
32
32
  # load a profile from ~/.ltap if one was specified
33
- if conf.profile
34
- conf.load_section(conf.profile)
33
+ begin
34
+ if conf.profile
35
+ conf.load_section(conf.profile)
36
+ end
37
+ rescue Hutils::Ltap::Conf::SectionNotFound
38
+ abort("No such section: #{conf.profile}")
35
39
  end
36
40
 
37
41
  unless conf.type
@@ -50,6 +54,8 @@ if !(earliest = parser.parse(conf.earliest, from: Time.now.getutc))
50
54
  end
51
55
 
52
56
  drainer = case conf.type
57
+ when "lvat"
58
+ Hutils::Ltap::LvatDrainer
53
59
  when "papertrail"
54
60
  Hutils::Ltap::PaperTrailDrainer
55
61
  when "splunk"
@@ -58,15 +64,19 @@ else
58
64
  abort("Unknown type: #{conf.type}")
59
65
  end
60
66
 
61
- drainer = drainer.new(
62
- earliest: earliest,
63
- key: conf.key,
64
- query: ARGV.first,
65
- timeout: conf.timeout,
66
- timestamps: conf.timestamps,
67
- url: conf.url,
68
- verbose: conf.verbose
69
- )
67
+ begin
68
+ drainer = drainer.new(
69
+ earliest: earliest,
70
+ key: conf.key,
71
+ query: ARGV.first,
72
+ timeout: conf.timeout,
73
+ timestamps: conf.timestamps,
74
+ url: conf.url,
75
+ verbose: conf.verbose
76
+ )
77
+ rescue ArgumentError
78
+ abort($!.message)
79
+ end
70
80
 
71
81
  thread = Thread.start do
72
82
  $stdout.puts drainer.run
data/lib/hutils/ltap.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative "ltap/conf"
2
+ require_relative "ltap/lvat_drainer"
2
3
  require_relative "ltap/paper_trail_drainer"
3
4
  require_relative "ltap/splunk_drainer"
4
5
  require_relative "ltap/time_bound_parser"
@@ -24,16 +24,21 @@ module Hutils::Ltap
24
24
  end
25
25
 
26
26
  def load_section(name)
27
- if section = @ini && @ini[name]
28
- load_value(section, :earliest)
29
- load_value(section, :key)
30
- load_value(section, :profile)
31
- load_value(section, :timeout)
32
- load_value(section, :timestamps)
33
- load_value(section, :type)
34
- load_value(section, :url)
35
- load_value(section, :verbose)
36
- end
27
+ return unless @ini
28
+ raise SectionNotFound unless @ini.has_section?(name)
29
+
30
+ section = @ini[name]
31
+ load_value(section, :earliest)
32
+ load_value(section, :key)
33
+ load_value(section, :profile)
34
+ load_value(section, :timeout)
35
+ load_value(section, :timestamps)
36
+ load_value(section, :type)
37
+ load_value(section, :url)
38
+ load_value(section, :verbose)
39
+ end
40
+
41
+ class SectionNotFound < StandardError
37
42
  end
38
43
 
39
44
  private
@@ -0,0 +1,28 @@
1
+ require "json"
2
+
3
+ module Hutils::Ltap
4
+ class LvatDrainer
5
+ def initialize(earliest:, key:, timeout:, query:, timestamps:, url:, verbose:)
6
+ @query = query
7
+
8
+ if timestamps
9
+ raise ArgumentError, "lvat does not supported `timestamps` option"
10
+ end
11
+
12
+ @api = Excon.new(url, read_timeout: timeout)
13
+ end
14
+
15
+ def run
16
+ resp = @api.get(
17
+ path: "/messages",
18
+ expects: [200, 404],
19
+ query: {
20
+ query: @query
21
+ })
22
+
23
+ return [] if resp.status == 404
24
+
25
+ JSON.parse(resp.body)
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -84,6 +84,7 @@ files:
84
84
  - "./lib/hutils/curses_visualizer.rb"
85
85
  - "./lib/hutils/ltap.rb"
86
86
  - "./lib/hutils/ltap/conf.rb"
87
+ - "./lib/hutils/ltap/lvat_drainer.rb"
87
88
  - "./lib/hutils/ltap/paper_trail_drainer.rb"
88
89
  - "./lib/hutils/ltap/splunk_drainer.rb"
89
90
  - "./lib/hutils/ltap/time_bound_parser.rb"