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 +4 -4
- data/lib/lita/handlers/libratoo.rb +27 -4
- data/lita-libratoo.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cc93c1969133762b0b44abc94b947239b35824a
|
4
|
+
data.tar.gz: 419b374f99fcccb0a6da401a5b0ebaee1c3845cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(.+)/, :
|
9
|
-
"librato [metric] [options]" =>
|
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
|
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
|
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
|
data/lita-libratoo.gemspec
CHANGED