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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6005a5b408631aca853cd7e65baaaeb4ac3fe801
4
- data.tar.gz: 301732f0f7efbd6948e81e200eb14568ba204b11
3
+ metadata.gz: cef5780da8199f4831f87d9726a554fbc777407a
4
+ data.tar.gz: db1105f8c13ae487284241408bba3a7c49be7d41
5
5
  SHA512:
6
- metadata.gz: 79d05973370fa351c292adbd3077a311eeda6ea77a3940ece207645cfc46572ed2ab742ff7d9312294c2b8024ffaa27068ff03bc4847fc5adc1a4dd4db68fd78
7
- data.tar.gz: efb6b2ac7c3013e90cd91e9ff7d75f94c7f7ad5770e35f3918610c0b2c728a076f2f16f0aafd396f70dfdad322ad79eee8869c5b65ee542170399f4003b95255
6
+ metadata.gz: b49dd59dea125c59bf02bea0a2f1309cf89d699ed6b885279bb91c62c997e7f5d2705fb7b4952c89d2054405a835ca61b5cf2db9feae786a2ce6267b22e13f90
7
+ data.tar.gz: 2d8280232b177edc6812aa68402a1548490922e5b6c99d50571741e08d02954e2d5546fc5af8fcb757d68314f726e59530ce57d17314134940849c782fb49876
@@ -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] ...', 'key=value pairs to add to the event, merged with optional file', attribute_name: :kvs
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.each do |kv|
27
- (k, v) = kv.split('=')
28
- attributes[k] = v
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 'notify', 'send notification to the slnky server', Slnky::CLI::Notify
73
+ Slnky::CLI::Main.subcommand('notify', 'send notification to the slnky server', Slnky::CLI::Notify)
data/lib/slnky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slnky
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/slnky.rb CHANGED
@@ -5,6 +5,7 @@ require 'slnky/service'
5
5
  require 'slnky/generator'
6
6
 
7
7
  require 'rest_client'
8
+ require 'active_support/all'
8
9
 
9
10
  module Slnky
10
11
  class << self
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.7.2
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-23 00:00:00.000000000 Z
11
+ date: 2016-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler