lita-libratoo 0.1.3 → 0.1.4

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: 641821ba24a20cbbf66cb240ad8a2b820d4a5a39
4
- data.tar.gz: f445a0003b17f61c080c7e14e6a7b896cfef9313
3
+ metadata.gz: 32264559607afd62e61078d32be2bb169b9445e9
4
+ data.tar.gz: f4c9304f055db2911ad978c8bfbb258e374033a2
5
5
  SHA512:
6
- metadata.gz: 9baa4cd5c0b0910c7e14f4ee6db2e4326300bfd32613c29156c0f501b69756ca0d6bd0a2a9efc02f33ee91367dd444d4f26d067d5a03dc0f111c04318ff234cb
7
- data.tar.gz: f0029a05d3ab3a37d93390a82e2257fe6b02fead29b58fc2dce7514a53d92ae5ba7dc8e8a69ae00c6a0ee454b3f49ff3419bac96b60cce100987dfd0f51acf8d
6
+ metadata.gz: 6facfde14fa34c258fa8b87b3d222150989f61fc9afc31c15588ed98b4d48d6cd1d447a17d6f1bf9cd673a2a5eddbd7c2373773e583ccb69dd8deb75165de79d
7
+ data.tar.gz: 5c0887c9459513e5e5741e0b672ffeecd020e69b3d7b7854adbaf8921b7f0173130e2976761c624fb24c83c4987458fab39c554aca339c2a87bdab1f2aee7654
@@ -1,32 +1,26 @@
1
1
  require "librato/metrics"
2
+ require "chronic"
3
+
2
4
  module Lita
3
5
  module Handlers
4
6
  class Libratoo < Handler
5
7
  config :email, required: true
6
8
  config :api_key, required: true
7
9
 
8
- route(/^librato get\s(.+)/, :librato_get, command: true, help: {
10
+ route(/^librato get\s([^ ]+)\s(.+)/, :librato_get, command: true, help: {
9
11
  "librato get [metric] [options]" =>
10
- "example: 'lita librato get AWS.RDS.ReplicaLag source: * count: 5 start_time: 2016-03-11-02:00'"
12
+ "example: 'lita librato get AWS.RDS.ReplicaLag, source: *, count: 5, start_time: \"an hour ago\"'"
11
13
  })
12
14
 
13
15
  def librato_get(response)
14
16
  Librato::Metrics.authenticate config.email, config.api_key
15
17
 
16
- arguments = response.matches[0][0].delete(':').split
17
-
18
- if arguments[0] == "search"
19
- metrics = Librato::Metrics.metrics.map{|v| v["name"] }
20
- response_text = metrics.grep(/#{arguments[1]}/i).join(', ')
21
- response_text = "No results" if response_text.empty?
22
- return reply_or_whisper_long response, response_text
23
- end
24
-
25
- metric, options = arguments[0].to_sym, arguments[1..-1]
26
- options = symbolize_keys Hash[*options]
18
+ metric = response.matches[0][0]
19
+ options = parse_options response.matches[0][1]
27
20
  options = { count: 1 }.merge options
21
+
28
22
  if options.key?(:start_time) && !options[:start_time].is_a?(Numeric)
29
- options[:start_time] = DateTime.parse(options[:start_time]).to_time
23
+ options[:start_time] = Chronic.parse(options[:start_time]).utc
30
24
  end
31
25
 
32
26
  results = Librato::Metrics.get_measurements metric, options
@@ -45,21 +39,20 @@ module Lita
45
39
  reply_or_whisper_long response, e.message
46
40
  end
47
41
 
48
- route(/^librato sum\s(.+)/, :librato_sum, command: true, help: {
42
+ route(/^librato sum\s([^ ]+)\s(.+)/, :librato_sum, command: true, help: {
49
43
  "librato sum [metric] [options]" =>
50
- "example: 'lita librato sum payments_controller.stripe.success start_time: 2016-03-11-02:00'"
44
+ "example: 'lita librato sum payments_controller.stripe.success, start_time: \"an hour ago\"'"
51
45
  })
52
46
 
53
47
  def librato_sum(response)
54
48
  Librato::Metrics.authenticate config.email, config.api_key
55
49
 
56
- arguments = response.matches[0][0].delete(':').split
57
-
58
- metric, options = arguments[0].to_sym, arguments[1..-1]
59
- options = symbolize_keys Hash[*options]
50
+ metric = response.matches[0][0]
51
+ options = parse_options response.matches[0][1]
60
52
  options = { resolution: 1 }.merge options
53
+
61
54
  if options.key?(:start_time) && !options[:start_time].is_a?(Numeric)
62
- options[:start_time] = DateTime.parse(options[:start_time]).to_time.to_i
55
+ options[:start_time] = Chronic.parse(options[:start_time]).utc.to_i
63
56
  end
64
57
 
65
58
  results = Librato::Metrics.get_composite %Q[sum(s("#{metric}", "*", {function: "sum"}))], options
@@ -100,6 +93,10 @@ module Lita
100
93
 
101
94
  private
102
95
 
96
+ def parse_options(options)
97
+ symbolize_keys Hash[*options.scan(/('.*?'|".*?"|\S+)/).flatten.map{|e| e.tr %Q['":], '' }]
98
+ end
99
+
103
100
  def reply_or_whisper_long(response, response_text)
104
101
  response_text = response_text.to_s
105
102
  if response_text.length > 400 && !response.message.source.private_message
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-libratoo"
3
- spec.version = "0.1.3"
3
+ spec.version = "0.1.4"
4
4
  spec.authors = ["Eric Boehs"]
5
5
  spec.email = ["ericboehs@gmail.com"]
6
6
  spec.description = "Query librato metrics from Lita"
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.add_runtime_dependency "lita", ">= 4.7"
18
18
  spec.add_runtime_dependency "librato-metrics", "~> 1.6"
19
+ spec.add_runtime_dependency "chronic", "~> 0.10"
19
20
 
20
21
  spec.add_development_dependency "bundler", "~> 1.3"
21
22
  spec.add_development_dependency "pry-byebug"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-libratoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chronic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement