lita-libratoo 0.1.0 → 0.1.1

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: 5d8284cea4e40109db108068f8c6223a9445b473
4
- data.tar.gz: 0f6390a54a35c0abcfab6d78d9bcc862d26339f2
3
+ metadata.gz: 4cc93c1969133762b0b44abc94b947239b35824a
4
+ data.tar.gz: 419b374f99fcccb0a6da401a5b0ebaee1c3845cf
5
5
  SHA512:
6
- metadata.gz: 39ea718e58c70c1b9606ceadd1c894e4a784129b057f7a4185391ccd0890519c864173afbda9bb05ce085c8b00be4c3a0eb0cb119fa375c79e295baeba3483d3
7
- data.tar.gz: 4ee4b563bd3b34a944cddcb417cd847400213e8897a95cd04832d0f808468013ba810f1d215e62e899b1211802609622b25c6e93d26399914bc0198abf9a43ed
6
+ metadata.gz: d68737ce25cb24a180df160dca960054e838bf970d3ceddf73a39b78238ac77515d8db8c8f70f5dc0a2a7410d96b1e802e4aad79912fd7ead7902747a3ab2fca
7
+ data.tar.gz: c32dfa78249bc777a271a081be3416e246317de0e76173051018a838818d1c58393ac32738737dd23b9c511f287df1333a7048bc4ddbd82e11427cf0e43b864f
@@ -5,11 +5,12 @@ module Lita
5
5
  config :email, required: true
6
6
  config :api_key, required: true
7
7
 
8
- route(/^librato\s(.+)/, :librato, command: true, help: {
9
- "librato [metric] [options]" => "example: 'lita librato AWS.RDS.ReplicaLag source: * count: 5'"
8
+ route(/^librato get\s(.+)/, :librato_get, command: true, help: {
9
+ "librato get [metric] [options]" =>
10
+ "example: 'lita librato get AWS.RDS.ReplicaLag source: * count: 5 start_time: 2016-03-11-02:00'"
10
11
  })
11
12
 
12
- def librato(response)
13
+ def librato_get(response)
13
14
  Librato::Metrics.authenticate config.email, config.api_key
14
15
 
15
16
  arguments = response.matches[0][0].delete(':').split
@@ -29,7 +30,9 @@ module Lita
29
30
  metric, options = arguments[0].to_sym, arguments[1..-1]
30
31
  options = symbolize_keys Hash[*options]
31
32
  options = { count: 1 }.merge options
32
- options[:start_time] = DateTime.parse(options[:start_time]).to_time unless options[:start_time].is_a? Numeric
33
+ if options.key?(:start_time) && !options[:start_time].is_a?(Numeric)
34
+ options[:start_time] = DateTime.parse(options[:start_time]).to_time
35
+ end
33
36
 
34
37
  results = Librato::Metrics.get_measurements metric, options
35
38
  results = Hash[results.map {|source, r| [source, r.map{|v| v["value"] }]}]
@@ -50,6 +53,26 @@ module Lita
50
53
  end
51
54
  end
52
55
 
56
+ route(/^librato search\s(.+)/, :librato_search, command: true, help: {
57
+ "librato search [metric]" => "example: 'lita librato search replica'"
58
+ })
59
+
60
+ def librato_search(response)
61
+ Librato::Metrics.authenticate config.email, config.api_key
62
+
63
+ arguments = response.matches[0][0].delete(':').split
64
+
65
+ metrics = Librato::Metrics.metrics.map{|v| v["name"] }
66
+ response_text = metrics.grep(/#{arguments[1]}/i).join(', ')
67
+ response_text = "No results" if response_text.empty?
68
+ if response_text.length > 400 && !response.message.source.private_message
69
+ return response.reply "Large result set. Sending you a direct message."
70
+ return response.reply_privately response_text
71
+ else
72
+ return response.reply response_text
73
+ end
74
+ end
75
+
53
76
  def symbolize_keys(hash)
54
77
  Hash[hash.map { |(k, v)| [ k.to_sym, v ] }]
55
78
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-libratoo"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.1.1"
4
4
  spec.authors = ["Eric Boehs"]
5
5
  spec.email = ["ericboehs@gmail.com"]
6
6
  spec.description = "Query librato metrics from Lita"
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs