slnky 0.7.2 → 0.8.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 +4 -4
- data/lib/slnky/cli/notify.rb +41 -9
- data/lib/slnky/version.rb +1 -1
- data/lib/slnky.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cef5780da8199f4831f87d9726a554fbc777407a
|
|
4
|
+
data.tar.gz: db1105f8c13ae487284241408bba3a7c49be7d41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b49dd59dea125c59bf02bea0a2f1309cf89d699ed6b885279bb91c62c997e7f5d2705fb7b4952c89d2054405a835ca61b5cf2db9feae786a2ce6267b22e13f90
|
|
7
|
+
data.tar.gz: 2d8280232b177edc6812aa68402a1548490922e5b6c99d50571741e08d02954e2d5546fc5af8fcb757d68314f726e59530ce57d17314134940849c782fb49876
|
data/lib/slnky/cli/notify.rb
CHANGED
|
@@ -9,9 +9,14 @@ module Slnky
|
|
|
9
9
|
end
|
|
10
10
|
f
|
|
11
11
|
end
|
|
12
|
+
option %w{-n --dry-run}, :flag, "just output the event, don't send"
|
|
12
13
|
parameter 'NAME', 'the name of the event to send'
|
|
13
|
-
parameter '[ATTRIBUTES] ...',
|
|
14
|
-
|
|
14
|
+
parameter '[ATTRIBUTES] ...', <<-DESC.strip_heredoc, attribute_name: :kvs
|
|
15
|
+
key=value pairs to add to the event, merged with optional file
|
|
16
|
+
supports dotted notation keys, and will merge them into nested hash
|
|
17
|
+
chat.* keys are specially handled, they are not encoded as part of the
|
|
18
|
+
attributes, they will be moved to their own keyspace
|
|
19
|
+
DESC
|
|
15
20
|
def execute
|
|
16
21
|
attributes = {}
|
|
17
22
|
if file
|
|
@@ -23,19 +28,46 @@ module Slnky
|
|
|
23
28
|
exit(1)
|
|
24
29
|
end
|
|
25
30
|
end
|
|
26
|
-
kvs
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
msg = Slnky::Message.new({name: name, attributes: attributes})
|
|
31
|
+
attributes.merge!(dothash(kvs)) if kvs
|
|
32
|
+
chat = attributes.delete(:chat)
|
|
33
|
+
msg = Slnky::Message.new({name: name, attributes: attributes, chat: chat})
|
|
31
34
|
cfg = Slnky.config
|
|
32
35
|
srv = server || cfg['slnky']['url']
|
|
33
36
|
|
|
34
37
|
puts 'sending message:'
|
|
35
38
|
puts JSON.pretty_generate(msg.to_h)
|
|
36
|
-
Slnky.notify(msg)
|
|
39
|
+
Slnky.notify(msg, srv) unless dry_run?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# convert list of dot notation key.name=value into nested hash
|
|
43
|
+
def dothash(list)
|
|
44
|
+
input_hash = list.inject({}) {|h, e| (k,v)=e.split('='); h[k]=v; h}
|
|
45
|
+
input_hash.map do |main_key, main_value|
|
|
46
|
+
main_key.to_s.split(".").reverse.inject(main_value) do |value, key|
|
|
47
|
+
{key.to_sym => value(value)}
|
|
48
|
+
end
|
|
49
|
+
end.inject(&:deep_merge)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# convert value from string to internal types
|
|
53
|
+
def value(value)
|
|
54
|
+
return value unless value.is_a?(String)
|
|
55
|
+
case value
|
|
56
|
+
when 'true'
|
|
57
|
+
true
|
|
58
|
+
when 'false'
|
|
59
|
+
false
|
|
60
|
+
when /^\d+\.\d+\.\d+/ # ip addr
|
|
61
|
+
value
|
|
62
|
+
when /^\d+$/ # number
|
|
63
|
+
value.to_i
|
|
64
|
+
when /^[\d\.]+$/ # float
|
|
65
|
+
value.to_f
|
|
66
|
+
else
|
|
67
|
+
value
|
|
68
|
+
end
|
|
37
69
|
end
|
|
38
70
|
end
|
|
39
71
|
end
|
|
40
72
|
end
|
|
41
|
-
Slnky::CLI::Main.subcommand
|
|
73
|
+
Slnky::CLI::Main.subcommand('notify', 'send notification to the slnky server', Slnky::CLI::Notify)
|
data/lib/slnky/version.rb
CHANGED
data/lib/slnky.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slnky
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shawn Catanzarite
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-03-
|
|
11
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|