riemann-feeds 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/lib/riemann-feeds.rb +10 -0
- data/lib/riemann/feeds/feed-handler.rb +145 -0
- data/lib/riemann/feeds/mixin/standard.rb +37 -0
- data/lib/riemann/feeds/type/jmx.rb +536 -0
- data/lib/riemann/feeds/type/super.rb +328 -0
- data/lib/riemann/feeds/version.rb +9 -0
- metadata +74 -0
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
|
2
|
+
# riemann feed handler
|
3
|
+
|
4
|
+
# manages feeds
|
5
|
+
|
6
|
+
require_relative "mixin/standard"
|
7
|
+
require 'potrubi/mixin/contract-recipes'
|
8
|
+
|
9
|
+
klassContent = Class.new do
|
10
|
+
|
11
|
+
include Riemann::Feeds::Mixin::Standard
|
12
|
+
|
13
|
+
# create the accessors with associated contracts
|
14
|
+
|
15
|
+
def self.feed_specification_keys
|
16
|
+
@feed_spec_keys ||= [:name, :type, :configuration]
|
17
|
+
end
|
18
|
+
|
19
|
+
attrAccessors = {
|
20
|
+
###:type => :string,
|
21
|
+
###:name => :string,
|
22
|
+
##feed: :hash,
|
23
|
+
feed_specification: {edit: {KEY_NAMES: 'self.class.feed_specification_keys'}, spec: :method_accessor_is_value_collection_with_keys},
|
24
|
+
|
25
|
+
#feed_specification_type: :symbol,
|
26
|
+
#feed_specification_name: :string,
|
27
|
+
#feed_specification_configuration: :hash,
|
28
|
+
|
29
|
+
watch: :hash,
|
30
|
+
feed_instance: 'Riemann::Feeds::Type::Super', # all feeds must have this as superclass
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
Potrubi::Mixin::ContractRecipes.recipe_accessors(self, attrAccessors, :package_accessor_with_contract)
|
35
|
+
|
36
|
+
mustbeContracts = {
|
37
|
+
feed_name: :string,
|
38
|
+
feed_type: :symbol,
|
39
|
+
feed_config: :hash,
|
40
|
+
}
|
41
|
+
|
42
|
+
Potrubi::Mixin::ContractRecipes.recipe_mustbes(self, mustbeContracts)
|
43
|
+
|
44
|
+
def initialize(feedArgs=nil, &feedBlok)
|
45
|
+
eye = 'rie::feed-hndl i'
|
46
|
+
|
47
|
+
$DEBUG && logger_me(eye, "FEED HNDL INIT", logger_fmt_kls(:feedArgs => feedArgs, :feedBlok => feedBlok))
|
48
|
+
|
49
|
+
super
|
50
|
+
|
51
|
+
$DEBUG && logger_mx(eye, 'FEED HNDL INIT')
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def make_watch_or_croak(watchArgs=nil, &watchBlok)
|
57
|
+
eye = :'rie::feed-hndl m_watch'
|
58
|
+
|
59
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(watchArgs: watchArgs), logger_fmt_kls(watchBlok: watchBlok) )
|
60
|
+
|
61
|
+
###mustbe_watch_handler_or_croak(watchArgs, eye, "watchArgs not really a watch handler")
|
62
|
+
|
63
|
+
##watchWatch = watch
|
64
|
+
|
65
|
+
###mustbe_hash_or_croak(watchArgs, eye, "watchArgs not hash")
|
66
|
+
|
67
|
+
STOPBEFORMAKEWATCHRETURN
|
68
|
+
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def import_feed_or_croak(feedArgs)
|
74
|
+
eye = :'rie::feed-hndl imp_feed'
|
75
|
+
|
76
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:feedArgs => feedArgs))
|
77
|
+
|
78
|
+
feedSpec = set_feed_specification(read_maybe_configuration_sources_list_or_croak(feedArgs).first) # set will apply contract
|
79
|
+
|
80
|
+
#STOPIMPFEED
|
81
|
+
|
82
|
+
###mustbe_subset_or_croak(feedSpec.keys, self.class.feed_specification_keys, eye) # check allowed keys
|
83
|
+
|
84
|
+
feedName = mustbe_feed_name_key_or_croak(feedSpec, :name)
|
85
|
+
feedType = mustbe_feed_type_key_or_croak(feedSpec, :type)
|
86
|
+
feedConf = mustbe_feed_config_key_or_croak(feedSpec, :configuration)
|
87
|
+
|
88
|
+
$DEBUG && logger_ms(eye, 'FEED', logger_fmt_kls(feedName: feedName, feedType: feedType, feedConf: feedConf))
|
89
|
+
|
90
|
+
feedKlass = find_feed_class_or_croak(feedType)
|
91
|
+
|
92
|
+
feedInst = feedKlass.new(feedConf)
|
93
|
+
|
94
|
+
$DEBUG && logger_mx(eye, 'FEED', logger_fmt_kls(:feedName => feedName, :feedInst => feedInst))
|
95
|
+
|
96
|
+
set_feed_instance(feedInst)
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def find_feed_class_or_croak(feedType)
|
102
|
+
eye = :'rie::feed-hndl f_feed_kls'
|
103
|
+
|
104
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:feedType => feedType))
|
105
|
+
|
106
|
+
feedKlass = case feedType
|
107
|
+
when Class then feedType
|
108
|
+
when Symbol then find_or_require_class_constant_or_croak("Riemann::Feeds::Type::#{feedType}")
|
109
|
+
when String then find_or_require_class_constant_or_croak(feedType)
|
110
|
+
else
|
111
|
+
surprise_exception(feedType, eye, "feedType is what?")
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(:feedType => feedType, :feedKlass => feedKlass))
|
116
|
+
|
117
|
+
mustbe_class_or_croak(feedKlass)
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def run_feed(runArgs=nil, &runBlok)
|
123
|
+
eye = :'rie::feed-hndl r_feed'
|
124
|
+
eyeTale = 'RUN'
|
125
|
+
|
126
|
+
$DEBUG && logger_me(eye, eyeTale, logger_fmt_kls(:runArgs => runArgs, :runBlok => runBlok))
|
127
|
+
|
128
|
+
feedInst = find_feed_instance_or_croak
|
129
|
+
|
130
|
+
feedInst.run(runArgs, &runBlok)
|
131
|
+
|
132
|
+
$DEBUG && logger_mx(eye, eyeTale, logger_fmt_kls(:runArgs => runArgs, :runBlok => runBlok))
|
133
|
+
|
134
|
+
self
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
klassConstant = Potrubi::Core.assign_class_constant_or_croak(klassContent, :Riemann, :Feeds, :FeedHandler)
|
142
|
+
|
143
|
+
__END__
|
144
|
+
|
145
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
# riemann feed mixin standard
|
3
|
+
|
4
|
+
# includes all the usual mixins
|
5
|
+
|
6
|
+
require 'potrubi/core'
|
7
|
+
|
8
|
+
requireList = %w(initialize util persistence configuration)
|
9
|
+
requireList.each {|r| require "potrubi/mixin/#{r}"}
|
10
|
+
|
11
|
+
###["logger", "exceptions", "contracts"].each { |m| require_relative m }
|
12
|
+
|
13
|
+
mixinContent = Module.new do
|
14
|
+
|
15
|
+
include Potrubi::Core
|
16
|
+
include Potrubi::Mixin::Initialize
|
17
|
+
include Potrubi::Mixin::Persistence
|
18
|
+
include Potrubi::Mixin::Configuration
|
19
|
+
include Potrubi::Mixin::Util
|
20
|
+
|
21
|
+
def initialize(initArgs=nil, &initBlok)
|
22
|
+
eye = :'rfms i'
|
23
|
+
|
24
|
+
$DEBUG && logger_me(eye, logger_fmt_kls_only(:initArgs => initArgs, :initBlok => initBlok))
|
25
|
+
|
26
|
+
super
|
27
|
+
|
28
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls_only(:initArgs => initArgs, :initBlok => initBlok))
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
mixinConstant = Potrubi::Core.assign_module_constant_or_croak(mixinContent, :Riemann, :Feeds, :Mixin, :Standard)
|
35
|
+
|
36
|
+
__END__
|
37
|
+
|
@@ -0,0 +1,536 @@
|
|
1
|
+
# riemann feed jmx
|
2
|
+
|
3
|
+
# Java Java Management Extensions (JMX) feed type
|
4
|
+
|
5
|
+
###require "potrubi/mixin/util"
|
6
|
+
require "potrubi/klass/syntax/braket"
|
7
|
+
|
8
|
+
# simple way to disable JMX access
|
9
|
+
|
10
|
+
|
11
|
+
JMX_LIVE_MODE = true
|
12
|
+
#JMX_LIVE_MODE = false
|
13
|
+
|
14
|
+
JMX_LIVE_MODE && (require "jmx4r") # does all the jmx heavy lifting
|
15
|
+
|
16
|
+
require_relative "super"
|
17
|
+
superClass = Riemann::Feeds::Type::Super
|
18
|
+
|
19
|
+
###puts "RIEMAN FEED TPOE JMX SUPER >#{superClass.class}< >#{superClass}<"
|
20
|
+
|
21
|
+
#stopHEREINJMX
|
22
|
+
|
23
|
+
classContent = Class.new(superClass) do
|
24
|
+
|
25
|
+
###include Potrubi::Mixin::Util
|
26
|
+
|
27
|
+
def self.feed_configuration_keys
|
28
|
+
@feed_configuration_keys ||= super.concat([:beans])
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.bean_specification_keys
|
32
|
+
@bean_spec_keys ||= [:event_defaults, :attributes, :bean_name]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.complex_attributes
|
36
|
+
#@complex_attributes ||= super.merge(beans: ->(k,v) {puts("\n\n\nBEAN IMPORT k >#{k}< v >#{v}<"); import_config_beans_or_croak(read_maybe_configuration_sources_or_croak({k => v}).values.first)})
|
37
|
+
@complex_attributes ||= super.merge(beans: ->(k,v) {import_config_beans_or_croak(read_maybe_configuration_sources_or_croak({k => v}).values.first)})
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.simple_attributes
|
41
|
+
@simple_attributes ||= super.merge(Hash[*[:jmx_user, :jmx_pass, :jmx_host, :jmx_port, :jmx_connection].map {|a| [a, nil]}.flatten])
|
42
|
+
end
|
43
|
+
|
44
|
+
# create the accessors with associated contracts
|
45
|
+
|
46
|
+
attrAccessors = {
|
47
|
+
jmx_user: :string,
|
48
|
+
jmx_pass: :string,
|
49
|
+
jmx_host: :string,
|
50
|
+
###:jmx_port => :string,
|
51
|
+
jmx_port: :fixnum,
|
52
|
+
#:jmx_connection => nil,
|
53
|
+
jmx_connection: 'JMX::MBeanServerConnectionProxy',
|
54
|
+
|
55
|
+
#beans_attributes: :hash,
|
56
|
+
beans_attributes: {edit: {KEY_TYPE: :string, VALUE_TYPE: :attributes_definitions}, spec: :method_accessor_is_value_typed_collection},
|
57
|
+
|
58
|
+
#beans_specifications: :hash,
|
59
|
+
beans_specifications: {edit: {KEY_TYPE: :string, VALUE_TYPE: :bean_specification, VALUE_IS_NIL_RESULT: 'true'}, spec: :method_accessor_is_value_typed_collection},
|
60
|
+
|
61
|
+
|
62
|
+
}
|
63
|
+
|
64
|
+
Potrubi::Mixin::ContractRecipes.recipe_accessors(self, attrAccessors, :package_accessor_with_contract)
|
65
|
+
|
66
|
+
#STOPHEREJMXATTS
|
67
|
+
|
68
|
+
mustbeContracts = {
|
69
|
+
beans_container: :array, # just the container
|
70
|
+
bean_name: :string,
|
71
|
+
#bean_spec: :hash,
|
72
|
+
bean_specification: {edit: {KEY_NAMES: 'self.class.bean_specification_keys'}, spec: :method_mustbe_is_value_collection_with_keys},
|
73
|
+
###bean_attributes: :hash,
|
74
|
+
bean_attributes_with_metrics: :hash,
|
75
|
+
jmx_bean: 'JMX::MBean',
|
76
|
+
bean_attributes_specification: :hash,
|
77
|
+
jmx_bean_attributes: {edit: {KEY_TYPE: :string, VALUE_TYPE: :string}, spec: :method_mustbe_is_value_typed_collection},
|
78
|
+
jmx_bean_attributes_with_metrics: {edit: {KEY_TYPE: :string, VALUE_TYPE: :string}, spec: :method_mustbe_is_value_typed_collection},
|
79
|
+
}
|
80
|
+
|
81
|
+
Potrubi::Mixin::ContractRecipes.recipe_mustbes(self, mustbeContracts)
|
82
|
+
|
83
|
+
#STOPHEREJMXMUSTBES
|
84
|
+
|
85
|
+
# def self.simple_attributes
|
86
|
+
# @simple_attributes ||= super.concat([:event_defaults])
|
87
|
+
# end
|
88
|
+
|
89
|
+
def jmx_connection # override the one made by the recipe
|
90
|
+
@jmx_connection ||= open_jmx_connection_or_croak
|
91
|
+
end
|
92
|
+
|
93
|
+
def import_config_beans_or_croak(beanArgs, &beanBlok)
|
94
|
+
eye = :'rftj imp_cfg_beans'
|
95
|
+
|
96
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(beanArgs: beanArgs, beanBlok: beanBlok))
|
97
|
+
|
98
|
+
#STOPBEENARAGSB4VALIDATION
|
99
|
+
|
100
|
+
mustbe_beans_container_or_croak(beanArgs, eye) # jsut an array right now
|
101
|
+
|
102
|
+
#puts("\n\n\n\nBEAN ARGS >#{beanArgs.class}< >#{beanArgs}<")
|
103
|
+
|
104
|
+
# resolved external configuration
|
105
|
+
# afterwards, treat bare strings as bean name and gfake up a hash
|
106
|
+
|
107
|
+
#beansHashes = read_maybe_configuration_sources_list_or_croak(*beanArgs).map {|h| puts("\n\n\n\n\n\nIMPCFGBEAN h >#{h.class}< >#{h}<"); h.is_a?(String) ? {bean_name: h} : h}
|
108
|
+
beansHashes = read_maybe_configuration_sources_list_or_croak(*beanArgs).map {|h| h.is_a?(String) ? {bean_name: h} : h}
|
109
|
+
mustbe_bean_specifications_or_croak(*beansHashes)
|
110
|
+
|
111
|
+
beansSpecs = self.beans_specifications = potrubi_util_array_to_hash(beansHashes) {|v| [mustbe_bean_name_key_or_croak(v, :bean_name), read_maybe_configuration_sources_or_croak(v)] }
|
112
|
+
|
113
|
+
#STOPBEENARAGSAFVALIDATION
|
114
|
+
|
115
|
+
beanObjs = []
|
116
|
+
|
117
|
+
#beanSpecDefault = {}
|
118
|
+
##beanSpecDefault = nil
|
119
|
+
|
120
|
+
self.beans_attributes = beansAttrs = make_beans_attributes_definitions_or_croak(beansSpecs, &beanBlok) # preserve full atributes map
|
121
|
+
|
122
|
+
beansMths = make_beans_attributes_methods_or_croak(beansAttrs)
|
123
|
+
|
124
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(beansMths: beansMths))
|
125
|
+
|
126
|
+
beansMths
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
def make_beans_attributes_definitions_or_croak(beansSpecs, &beanBlok)
|
131
|
+
eye = :'m_beans_attrs_defs'
|
132
|
+
eyeTale = 'BEAN ATTRS DEFS'
|
133
|
+
|
134
|
+
$DEBUG && logger_me(eye, eyeTale, logger_fmt_kls(beansSpecs: beansSpecs, beanBlok: beanBlok))
|
135
|
+
|
136
|
+
mustbe_beans_specifications_or_croak(beansSpecs, eye, "beansSpecs not hash")
|
137
|
+
|
138
|
+
#STOPHEREBEANSATTRSSPECS
|
139
|
+
|
140
|
+
beanSpecDefault = nil # what to do / use this for?
|
141
|
+
|
142
|
+
beansAttrs = potrubi_util_map_hash_v(beansSpecs) do | beanName, beanSpecNom |
|
143
|
+
|
144
|
+
$DEBUG && logger_beg(eye, eyeTale, logger_fmt_kls(beanName: beanName, :beanSpecNom => beanSpecNom))
|
145
|
+
|
146
|
+
beanSpec = potrubi_util_merge_hashes_or_croak(beanSpecDefault, beanSpecNom) # any defaults?
|
147
|
+
|
148
|
+
###attrSpec = make_bean_attrs_specs_or_croak(:bean_name => beanName, :bean_spec => beanSpec)
|
149
|
+
|
150
|
+
attrDefsNom = mustbe_hash_key_or_nil_or_croak(beanSpec, :attributes, eye, "attribute not hash")
|
151
|
+
|
152
|
+
$DEBUG && logger_ms(eye, eyeTale, 'ATTRS NOM', logger_fmt_kls(beanName: beanName, :attrDefsNom => attrDefsNom))
|
153
|
+
|
154
|
+
###STOPHEREATARRTDEFSNOM
|
155
|
+
|
156
|
+
JMX_LIVE_MODE && (attrAll = find_jmx_bean_attributes_with_metrics_or_croak(beanName).keys)
|
157
|
+
JMX_LIVE_MODE || (attrAll = mustbe_hash_key_or_nil_or_croak(attrDefsNom, :definitions, eye, "TESTING attributes map not hash").keys)
|
158
|
+
|
159
|
+
attrDefsNrm = potrubi_util_merge_hashes_or_croak({:all => attrAll}, attrDefsNom)
|
160
|
+
|
161
|
+
$DEBUG && logger_ms(eye, eyeTale, 'ATTRS NRM', logger_fmt_kls(beanName: beanName, :attrDefsNrm => attrDefsNrm))
|
162
|
+
|
163
|
+
attrsDefs = make_attributes_definitions_or_croak(attrDefsNrm)
|
164
|
+
|
165
|
+
$DEBUG && logger_fin(eye, eyeTale, logger_fmt_kls(beanName: beanName, :attrsDefs => attrsDefs))
|
166
|
+
|
167
|
+
attrsDefs
|
168
|
+
end
|
169
|
+
|
170
|
+
$DEBUG && logger_mx(eye, eyeTale, logger_fmt_kls(beansSpecs: beansSpecs, beansAttrs: beansAttrs))
|
171
|
+
|
172
|
+
mustbe_hash_or_croak(beansAttrs, eye, "beansAttrs not hash")
|
173
|
+
|
174
|
+
#STOPMAKEBEENASATTARSDEFS
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
def make_beans_attributes_methods_or_croak(beansAttrs, &beanBlok)
|
179
|
+
eye = :'rftj m_beans_attrs_mths'
|
180
|
+
|
181
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:beansAttrs => beansAttrs, beanBlok: beanBlok))
|
182
|
+
|
183
|
+
#STOPHEREBEASNATTRSMTHS
|
184
|
+
|
185
|
+
mustbe_beans_attributes_or_croak(beansAttrs, eye, "beansAttrs failed contract")
|
186
|
+
|
187
|
+
#STOPMAKEBEASNATTRSMTHS
|
188
|
+
|
189
|
+
beansMths = make_syntax_beans_methods_or_croak(beansAttrs)
|
190
|
+
|
191
|
+
$DEBUG && logger_ms(eye, 'BEANS MTHS', logger_fmt_kls(beansMths: beansMths))
|
192
|
+
|
193
|
+
##STOPHEREBEANSMTHS
|
194
|
+
|
195
|
+
beansDyns = beansMths.values.inject({}) {|s,h| s.merge(h) } # flatten values
|
196
|
+
|
197
|
+
$DEBUG && logger_ms(eye, 'BEANS DYNS', logger_fmt_kls(beansDyns: beansDyns))
|
198
|
+
|
199
|
+
# get the singleton class
|
200
|
+
|
201
|
+
singletonKls = class << self; self; end
|
202
|
+
|
203
|
+
Potrubi::Core.dynamic_define_methods(singletonKls, beansDyns) # make beans methods in singleton class
|
204
|
+
|
205
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(beansDyns: beansDyns))
|
206
|
+
|
207
|
+
beansDyns
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
# Method Syntax
|
212
|
+
# #############
|
213
|
+
|
214
|
+
def make_syntax_beans_methods_or_croak(beansAttrs, &beanBlok)
|
215
|
+
eye = :'rftj ms_beans_mths'
|
216
|
+
|
217
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(beansAttrs: beansAttrs, beanBlok: beanBlok))
|
218
|
+
|
219
|
+
mustbe_hash_or_croak(beansAttrs, eye, "beansAttrs not hash")
|
220
|
+
|
221
|
+
beansMths = potrubi_util_map_hash_v(beansAttrs) { | beanName, beanAttrs | collect_attributes_method_definitions_or_croak(beanAttrs) }
|
222
|
+
|
223
|
+
#mtdSpec = {:bean_name => beanName, :bean_spec => beanAttrs}
|
224
|
+
|
225
|
+
beansMths[:each_event] = {each_event: make_syntax_each_event_method_or_croak(beansAttrs).to_s}
|
226
|
+
|
227
|
+
$DEBUG && logger_ms(eye, logger_fmt_kls(beansAttrs: beansAttrs), logger_fmt_kls_only(beansMths: beansMths))
|
228
|
+
|
229
|
+
mustbe_hash_or_croak(beansMths, eye, "beansMthds not hash")
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
def make_syntax_each_event_method_or_croak(beansAttrs, &mthBlok)
|
235
|
+
eye = :'rftj ms_each_evt_mtd'
|
236
|
+
eyeTale = 'EACH_EVENT'
|
237
|
+
|
238
|
+
$DEBUG && logger_me(eye, eyeTale, logger_fmt_kls(beansAttrs: beansAttrs, :mthBlok => mthBlok))
|
239
|
+
|
240
|
+
mustbe_beans_attributes_or_croak(beansAttrs, eye, "beansAttrs not a beans_attributes")
|
241
|
+
|
242
|
+
braketKls = Potrubi::Klass::Syntax::Braket # class to simplify method text construction
|
243
|
+
|
244
|
+
braketMethod = braketKls.new_method # will hold to_events method's syntax
|
245
|
+
|
246
|
+
braketMethod.cons_head('def each_event',
|
247
|
+
####JMX_LIVE_MODE && 'jmxConn = find_jmx_connection_or_croak',
|
248
|
+
###JMX_LIVE_MODE && 'jmxConn = find_jmx_connection_or_croak',
|
249
|
+
###'beansAttrs = beans_attributes',
|
250
|
+
###'evntIter = Enumerator.new do | enum |', # make a lazy enumerator
|
251
|
+
)
|
252
|
+
|
253
|
+
braketMethod.push_tail(###'end',
|
254
|
+
####JMX_LIVE_MODE && 'close_jmx_connection_or_croak(jmxConn)',
|
255
|
+
###'$DEBUG && logger_ca(:to_evnts, "evntIter >#{evntIter.class}<")',
|
256
|
+
###'evntIter',
|
257
|
+
'self',
|
258
|
+
'end')
|
259
|
+
hostDefaults = {host: jmx_host} # need to specify source of the events
|
260
|
+
eventDefaults = event_defaults
|
261
|
+
beansSpecifications = find_beans_specifications_or_croak
|
262
|
+
|
263
|
+
braketsBeans = beansAttrs.each_with_object([]) do | (beanName, attrsSpecs), a |
|
264
|
+
|
265
|
+
$DEBUG && logger_beg(eye, eyeTale, 'BEAN', logger_fmt_kls(beanName: beanName, :attrsSpecs => attrsSpecs))
|
266
|
+
|
267
|
+
beaneventDefaults = mustbe_event_defaults_key_or_nil_or_croak(beansSpecifications[beanName], :event_defaults, eye, "beanName >#{beanName}< event defaults not hash")
|
268
|
+
|
269
|
+
mustbe_bean_attributes_specification_or_croak(attrsSpecs, eye, "attrsSpecs not hash")
|
270
|
+
|
271
|
+
braketBean = braketKls.new_stanza # will hold syntax for this bean
|
272
|
+
|
273
|
+
braketBean.cons(JMX_LIVE_MODE && "beanInst = find_jmx_bean_or_croak('#{beanName}')")
|
274
|
+
|
275
|
+
attrsSpecs.each do | attrName, attrSpec |
|
276
|
+
|
277
|
+
$DEBUG && logger_beg(eye, eyeTale, 'BEAN ATTR', logger_fmt_kls(beanName: beanName, :attrName => attrName, :attrSpec => attrSpec))
|
278
|
+
|
279
|
+
attrPassThru = mustbe_hash_key_or_nil_or_croak(attrSpec, :pass_thru, eye, "pass thru not hash")
|
280
|
+
|
281
|
+
attreventDefaults = mustbe_event_defaults_key_or_nil_or_croak(attrPassThru, :event_defaults, eye, "beanName >#{beanName}< attrName >#{attrName}< event defaults not hash")
|
282
|
+
|
283
|
+
$DEBUG && logger_ms(eye, eyeTale, 'BEAN ATTR PASS & DEFS', logger_fmt_kls(:passThru => attrPassThru, :attrDefaulst => attreventDefaults))
|
284
|
+
|
285
|
+
defaultFields = merge_event_hashes(hostDefaults, eventDefaults, beaneventDefaults, attreventDefaults)
|
286
|
+
|
287
|
+
# Build the event hash with the wanted attribute (event) fields
|
288
|
+
|
289
|
+
attrDefs = {metric: "beanInst.#{attrName}", description: "'#{attrName}'"}
|
290
|
+
JMX_LIVE_MODE || (attrDefs = {:metric => "2.97", :description => "'#{attrName}'"}) # TESING
|
291
|
+
|
292
|
+
# Create the syntax for the attributes in attrDefs, with normalisation calls if any
|
293
|
+
|
294
|
+
attrFields = attrDefs.each_with_object({}) do | (fieldName, fieldDef), h |
|
295
|
+
fieldBraket = braketKls.new_statement.push(fieldDef) # add the field def
|
296
|
+
(fieldSpec = attrSpec[fieldName]) && fieldBraket.cons_head(fieldSpec[:method_name], '(').push_tail(')')
|
297
|
+
h[fieldName] = fieldBraket.to_s
|
298
|
+
end
|
299
|
+
|
300
|
+
eventFields = merge_event_hashes(defaultFields, attrSpec[:event_defaults], attrFields)
|
301
|
+
|
302
|
+
# Convert the event to text representation - needs custom logic
|
303
|
+
|
304
|
+
braketEvent = eventFields.inject(braketKls.new_statement) do | bkt, (fieldName, fieldValue) |
|
305
|
+
r = case fieldName
|
306
|
+
when :metric, :description then fieldValue
|
307
|
+
when :tags then fieldValue # array to.s is fine
|
308
|
+
else
|
309
|
+
"'#{fieldValue}'" # enclose in single quotes
|
310
|
+
end
|
311
|
+
bkt.push(fieldName, ': ', r.to_s, ', ') # short form symbol key syntax
|
312
|
+
end
|
313
|
+
|
314
|
+
braketEvent.pop # get rid of last comma
|
315
|
+
|
316
|
+
braketEvent.cons_head('{').push_tail('}') # hash syntax
|
317
|
+
|
318
|
+
###braketEvent.raw_debug("BRAKET FIELDS")
|
319
|
+
###puts("BRAKETFIELDS >#{braketEvent}<")
|
320
|
+
|
321
|
+
###STOPHEREAFTERATTRFIELDS
|
322
|
+
|
323
|
+
# Is the event hash to be transformed (mapped)?
|
324
|
+
|
325
|
+
braketTransform = case (transformSpec = attrSpec[:map])
|
326
|
+
when NilClass then braketEvent
|
327
|
+
else
|
328
|
+
#bkt = braketKls.new_statement
|
329
|
+
#bkt.cons_head(transformSpec[:method_name], '(').push_tail(')')
|
330
|
+
#bkt.push(braketEvent)
|
331
|
+
#bkt
|
332
|
+
braketKls.new_statement.cons_head(transformSpec[:method_name], '(').push_tail(')').push(braketEvent)
|
333
|
+
end
|
334
|
+
|
335
|
+
# Construct the yield
|
336
|
+
|
337
|
+
###braketYield = braketKls.new_statement.cons_head('enum.yield(').push_tail(')')
|
338
|
+
braketYield = braketKls.new_statement.cons_head('yield(').push_tail(')')
|
339
|
+
|
340
|
+
# Is event to be filtered (selected)?
|
341
|
+
|
342
|
+
braketAttr = case (filterSpec = attrSpec[:select])
|
343
|
+
when NilClass then braketYield.push(braketTransform) # no filter
|
344
|
+
else
|
345
|
+
bkt = braketKls.new_statement
|
346
|
+
bkt.push('(r = ', braketTransform, ')')
|
347
|
+
bkt.push(' && ', filterSpec[:method_name], '(r)')
|
348
|
+
bkt.push(' && ', braketYield.push('r'))
|
349
|
+
bkt
|
350
|
+
end
|
351
|
+
|
352
|
+
braketBean.push(braketAttr)
|
353
|
+
|
354
|
+
$DEBUG && logger_fin(eye, eyeTale, 'BEAN ATTR', logger_fmt_kls(:attrName => attrName, :attrSpec => attrSpec))
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
a << braketBean
|
359
|
+
|
360
|
+
$DEBUG && logger_fin(eye, eyeTale, 'BEAN', logger_fmt_kls(beanName: beanName, :attrsSpecs => attrsSpecs))
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
braketMethod.push(braketsBeans)
|
365
|
+
|
366
|
+
###braketMethod.raw_debug('TO_EVENT METHOD')
|
367
|
+
$DEBUG && puts("EACH_EVENT METHOD \n>#{braketMethod.to_s}<")
|
368
|
+
|
369
|
+
###STOPHERETOEVENTS
|
370
|
+
|
371
|
+
$DEBUG && logger_me(eye, eyeTale, logger_fmt_kls_only(beansAttrs: beansAttrs, :braketMethod => braketMethod))
|
372
|
+
|
373
|
+
braketMethod
|
374
|
+
|
375
|
+
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
# Bean Finders
|
382
|
+
# ############
|
383
|
+
|
384
|
+
def find_jmx_bean_attributes_or_croak(beanName, &beanBlok)
|
385
|
+
eye = :'rftj f_bean_attrs'
|
386
|
+
beanAttrs = find_jmx_bean_or_croak(beanName).attributes
|
387
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(beanName: beanName, beanAttrs: beanAttrs))
|
388
|
+
mustbe_jmx_bean_attributes_or_croak(beanAttrs, eye, "beanAttrs failed contract")
|
389
|
+
end
|
390
|
+
|
391
|
+
def find_jmx_bean_attributes_with_metrics_or_croak(beanName, &beanBlok)
|
392
|
+
eye = :'rftj f_bean_attrs_w_metrics'
|
393
|
+
metricsRegex = Regexp.new('\Atag\.')
|
394
|
+
beanAttrsWithMetrics = find_jmx_bean_attributes_or_croak(beanName).select {|k,v| ! k.match(metricsRegex) }
|
395
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(beanName: beanName, beanAttrsWithMetrics: beanAttrsWithMetrics))
|
396
|
+
mustbe_jmx_bean_attributes_with_metrics_or_croak(beanAttrsWithMetrics, eye, "beanAttrsWithMetrics failed contract")
|
397
|
+
end
|
398
|
+
|
399
|
+
def find_jmx_bean_or_croak(beanName, &beanBlok)
|
400
|
+
eye = :'rftj f_bean'
|
401
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(beanName: beanName, beanBlok: beanBlok))
|
402
|
+
beanConn = find_jmx_connection_or_croak
|
403
|
+
beanInst = JMX::MBean.find_by_name(beanName, :connection => beanConn)
|
404
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(beanName: beanName, :beinInst => beanInst, :beanConn => beanConn))
|
405
|
+
mustbe_jmx_bean_or_croak(beanInst, eye, 'jmx bean find failed')
|
406
|
+
end
|
407
|
+
|
408
|
+
# JMX Connections
|
409
|
+
# ###############
|
410
|
+
|
411
|
+
|
412
|
+
def open_jmx_connection_or_croak(jmxArgs={}, &jmxBlok)
|
413
|
+
eye = :'rftj o_jmx_conn'
|
414
|
+
|
415
|
+
jmxHost = mustbe_jmx_host_key_or_nil_or_croak(jmxArgs, :jmx_host, eye) || find_jmx_host_or_croak
|
416
|
+
jmxPort = mustbe_jmx_port_key_or_nil_or_croak(jmxArgs, :jmx_port, eye) || find_jmx_port_or_croak
|
417
|
+
jmxUser = mustbe_jmx_user_key_or_nil_or_croak(jmxArgs, :jmx_user, eye) || jmx_user
|
418
|
+
jmxPass = mustbe_jmx_pass_key_or_nil_or_croak(jmxArgs, :jmx_pass, eye) || jmx_pass
|
419
|
+
|
420
|
+
jmxConn = begin
|
421
|
+
|
422
|
+
case
|
423
|
+
when jmxUser.nil? then JMX::MBean.establish_connection(:host => jmxHost, :port => jmxPort)
|
424
|
+
else
|
425
|
+
JMX::MBean.establish_connection(:host => jmxHost, :port => jmxPort, :username => jmxUser, :password => jmxPass)
|
426
|
+
end
|
427
|
+
|
428
|
+
rescue Exception => e
|
429
|
+
errorText = "Connection open error: jmxArgs >#{jmxArgs}< jmxHost >#{jmxHost}< jmxPort >#{jmxPort}< jmxUser >#{jmxUser}< error >#{e.message}"
|
430
|
+
#riemann_alert
|
431
|
+
connection_exception(e, errorText)
|
432
|
+
end
|
433
|
+
|
434
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(:jmxArgs => jmxArgs, :jmxConn => jmxConn))
|
435
|
+
|
436
|
+
self.jmx_connection = jmxConn # contract will validate it
|
437
|
+
|
438
|
+
end
|
439
|
+
|
440
|
+
|
441
|
+
def close_jmx_connection_or_croak(jmxArgs={}, &jmxBlok)
|
442
|
+
eye = :'rftj cl_jmx_conn'
|
443
|
+
|
444
|
+
jmxConn = mustbe_jmx_connection_key_or_nil_or_croak(jmxArgs, :jmx_connection, eye) || (jmxConnAccessor = jmx_connection)
|
445
|
+
|
446
|
+
jmxConn && begin
|
447
|
+
jmxConn.close
|
448
|
+
(jmxConn == jmxConnAccessor) && reset_jmx_connection # reset accessor if same
|
449
|
+
rescue Exception => e
|
450
|
+
errorText = "Connection close error: jmxArgs >#{jmxArgs}< jmxHost >#{jmxHost}< jmxPort >#{jmxPort}< jmxUser >#{jmxUser}< error >#{e.message}"
|
451
|
+
#riemann_alert
|
452
|
+
connection_exception(e, errorText)
|
453
|
+
end
|
454
|
+
|
455
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(:jmxArgs => jmxArgs, :jmxConn => jmxConn))
|
456
|
+
|
457
|
+
self
|
458
|
+
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
klassConstant = Potrubi::Core.assign_class_constant_or_croak(classContent, :Riemann, :Feeds, :Type, :JMX)
|
464
|
+
|
465
|
+
###puts "RIEMANN FEED TYPE JMX >#{klassConstant.class}< >#{klassConstant}<"
|
466
|
+
|
467
|
+
__END__
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
def zzzmake_syntax_bean_methods_or_croak(beanArgs, &beanBlok)
|
475
|
+
eye = :'rftj ms_bean_mths'
|
476
|
+
|
477
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(beanArgs: beanArgs, beanBlok: beanBlok))
|
478
|
+
|
479
|
+
beanName = mustbe_string_key_or_croak(beanArgs, :bean_name, eye, "beanName not string")
|
480
|
+
beanAttrs = mustbe_hash_key_or_croak(beanArgs, :bean_attrs, eye, "beanAttrs not hash")
|
481
|
+
|
482
|
+
beanMths = collect_attribute_method_definitions_or_croak(beanAttrs)
|
483
|
+
|
484
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(beanArgs: beanArgs), logger_fmt_kls(:beanMtds => beanMths))
|
485
|
+
|
486
|
+
mustbe_hash_or_croak(beanMths, eye, "beanMths not hash")
|
487
|
+
|
488
|
+
##STOPEHEREATTR
|
489
|
+
|
490
|
+
end
|
491
|
+
|
492
|
+
jmxConstants = klassConstant.constants(false)
|
493
|
+
|
494
|
+
puts "RIEMANN FEED TYPE JMX CONSTANTS >#{jmxConstants.class}< >#{jmxConstants}<"
|
495
|
+
|
496
|
+
jmxConstants.each do |c|
|
497
|
+
v = klassConstant.const_get(c, false)
|
498
|
+
puts "RIEMANN FEED TYPE JMX CONSTANT c >#{c}< v >#{v.class}< >#{v}<"
|
499
|
+
end
|
500
|
+
|
501
|
+
|
502
|
+
def make_bean_attrs_specs_or_croak(beanArgs, &beanBlok)
|
503
|
+
eye = :'rftj m_bean_attrs_specs'
|
504
|
+
|
505
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(beanArgs: beanArgs, beanBlok: beanBlok))
|
506
|
+
|
507
|
+
STOPMAKEBEANATTRSSPECS
|
508
|
+
|
509
|
+
|
510
|
+
beanSpec = mustbe_bean_spec_or_nil_or_croak(beanArgs[:bean_spec], eye, "beanSpec failed contract") || {}
|
511
|
+
beanName = mustbe_bean_name_or_croak(beanArgs[:bean_name], eye, "beanName failed contract")
|
512
|
+
|
513
|
+
$DEBUG && logger_ms(eye, logger_fmt_kls(beanName: beanName, :beanSpec => beanSpec))
|
514
|
+
|
515
|
+
attrDefsNom = mustbe_hash_key_or_nil_or_croak(beanSpec, :attributes, eye, "attribuste not hash")
|
516
|
+
|
517
|
+
$DEBUG && logger_ms(eye, 'BEAN ATTRS NOM', logger_fmt_kls(:attrDefsNom => attrDefsNom))
|
518
|
+
|
519
|
+
###STOPHEREATARRTDEFSNOM
|
520
|
+
|
521
|
+
JMX_LIVE_MODE && (attrAll = find_jmx_bean_attributes_with_metrics_or_croak(beanName).keys)
|
522
|
+
JMX_LIVE_MODE || (attrAll = mustbe_hash_key_or_nil_or_croak(attrDefsNom, :definitions, eye, "TESTING attributes map not hash").keys)
|
523
|
+
|
524
|
+
attrDefsNrm = potrubi_util_merge_hashes_or_croak({:all => attrAll}, attrDefsNom)
|
525
|
+
|
526
|
+
$DEBUG && logger_ms(eye, 'BEAN ATTRS NRM', logger_fmt_kls(:attrDefsNrm => attrDefsNrm))
|
527
|
+
|
528
|
+
beanAttrs = make_attribute_specs_or_croak(attrDefsNrm)
|
529
|
+
|
530
|
+
##SOPTPOSMAKEATTRSPECS
|
531
|
+
|
532
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(beanName: beanName, :beanAttrs => beanAttrs))
|
533
|
+
|
534
|
+
mustbe_hash_or_croak(beanAttrs, "beanName >#{beanName}< beanAttrs not hash")
|
535
|
+
|
536
|
+
end
|
@@ -0,0 +1,328 @@
|
|
1
|
+
# riemann feed super
|
2
|
+
|
3
|
+
# common methods for all feeder types
|
4
|
+
|
5
|
+
require 'potrubi/mixin/contract-recipes'
|
6
|
+
|
7
|
+
require_relative "../mixin/standard"
|
8
|
+
|
9
|
+
require 'riemann/client'
|
10
|
+
|
11
|
+
classContent = Class.new do
|
12
|
+
|
13
|
+
###include Potrubi::Mixin::Util
|
14
|
+
include Riemann::Feeds::Mixin::Standard
|
15
|
+
|
16
|
+
def self.attributes_specification_keys
|
17
|
+
@attributes_specification_keys ||= [:include, :exclude, :definitions, :all]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.attributes_definition_keys
|
21
|
+
@feed_attribute_definition_keys ||= [:map, :select, :metric, :pass_thru, :event_defaults]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.event_fields
|
25
|
+
@event_fields ||= [:host, :service, :status, :time, :ttl, :tags, :description, :metric]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.feed_configuration_keys
|
29
|
+
@feed_configuration_keys ||= [:include_configuration, :event_defaults] # likely be subclassed
|
30
|
+
end
|
31
|
+
|
32
|
+
# Complex, simple and all attributes are hashes
|
33
|
+
|
34
|
+
def self.complex_attributes
|
35
|
+
@complex_attributes ||= {
|
36
|
+
include_configuration: ->(k,v) {self.set_attributes_from_configuration_sources_list_or_croak(*v)},
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.simple_attributes
|
41
|
+
@simple_attributes ||= Hash[*[:event_defaults, :riemann_host, :riemann_port, :riemann_interval].map {|a| [a, nil]}.flatten]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.all_attributes
|
45
|
+
@all_attributes ||= complex_attributes.merge(simple_attributes)
|
46
|
+
end
|
47
|
+
|
48
|
+
attrAccessors = {
|
49
|
+
riemann_host: :string,
|
50
|
+
riemann_port: :fixnum,
|
51
|
+
riemann_interval: :fixnum,
|
52
|
+
event_defaults: {edit: {KEY_NAMES: 'self.class.event_fields'}, spec: :method_accessor_is_value_collection_with_keys},
|
53
|
+
feed_configuration: {edit: {KEY_NAMES: 'self.class.all_attributes.keys'}, spec: :method_accessor_is_value_collection_with_keys},
|
54
|
+
}
|
55
|
+
|
56
|
+
Potrubi::Mixin::ContractRecipes.recipe_accessors(self, attrAccessors, :package_accessor_with_contract)
|
57
|
+
|
58
|
+
mustbeContracts = {
|
59
|
+
attributes_specification: {edit: {KEY_TYPE: :symbol, VALUE_TYPE: :any, KEY_NAMES: 'self.class.attributes_specification_keys'}, spec: :method_mustbe_is_value_typed_collection_with_keys},
|
60
|
+
|
61
|
+
attributes_specification_all: {edit: {VALUE_TYPE: :string}, spec: :method_mustbe_is_value_typed_array},
|
62
|
+
attributes_specification_include: {edit: {VALUE_TYPE: :string}, spec: :method_mustbe_is_value_typed_array},
|
63
|
+
attributes_specification_exclude: {edit: {VALUE_TYPE: :string}, spec: :method_mustbe_is_value_typed_array},
|
64
|
+
|
65
|
+
attributes_definitions: {edit: {KEY_TYPE: :string, VALUE_TYPE: :attributes_definition_map}, spec: :method_mustbe_is_value_typed_collection},
|
66
|
+
attributes_definition_map: {edit: {KEY_NAMES: 'self.class.attributes_definition_keys'}, spec: :method_mustbe_is_value_collection_with_keys},
|
67
|
+
}
|
68
|
+
|
69
|
+
Potrubi::Mixin::ContractRecipes.recipe_mustbes(self, mustbeContracts)
|
70
|
+
|
71
|
+
#STOPHEREAFTERSUPERCONTRACTS
|
72
|
+
|
73
|
+
def initialize(initArgs=nil, &initBlok)
|
74
|
+
eye = :'rfts i'
|
75
|
+
|
76
|
+
$DEBUG && logger_me(eye, logger_fmt_kls_only(:initArgs => initArgs, :initBlok => initBlok))
|
77
|
+
|
78
|
+
initArgs && import_configuration_or_croak(initArgs)
|
79
|
+
|
80
|
+
#initArgs && mustbe_hash_or_croak(initArgs, eye).each {|k, v| __send__("#{k}=", v) }
|
81
|
+
|
82
|
+
Kernel.block_given? && instance_eval(&initBlok)
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def import_configuration_or_croak(feedConf=nil, &feedBlok)
|
87
|
+
eye = :'rfts imp_cfg'
|
88
|
+
|
89
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:feedConf => feedConf, :feedBlok => feedBlok))
|
90
|
+
|
91
|
+
mustbe_feed_configuration_or_croak(feedConf, eye, "feedConf failed contract")
|
92
|
+
|
93
|
+
set_attributes_using_specification_or_croak(self.class.all_attributes, feedConf)
|
94
|
+
|
95
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls_only(:feedConf => feedConf, :feedBlok => feedBlok))
|
96
|
+
|
97
|
+
self
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_event(*eventHashes)
|
102
|
+
eventHash = potrubi_util_merge_hashes_or_croak(*eventHashes)
|
103
|
+
mustbe_subset_or_croak(eventHash.keys, self.class.event_fields, eye, "unknown event keys / fields")
|
104
|
+
eventHash
|
105
|
+
end
|
106
|
+
|
107
|
+
def merge_event_hashes(*eventHashes)
|
108
|
+
|
109
|
+
mergeHash = eventHashes.inject({}) do | hashSumm, eventHash |
|
110
|
+
|
111
|
+
case eventHash
|
112
|
+
when NilClass then hashSumm # this is ok; convenient to allow nil
|
113
|
+
when Hash
|
114
|
+
|
115
|
+
###print("MEREG EVENT HASHES hashSumm >#{hashSumm}< eventHash >#{eventHash}\n\n\n")
|
116
|
+
|
117
|
+
r = hashSumm.merge(eventHash.select {|k,v| (k != :tags) })
|
118
|
+
|
119
|
+
r[:tags] = merge_event_tags(hashSumm[:tags], eventHash[:tags])
|
120
|
+
|
121
|
+
r
|
122
|
+
|
123
|
+
else
|
124
|
+
surprise_exception(eventHash, :m_evts_hshs, "eventHash not hash")
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
$DEBUG && logger_ca(:m_evts_hshs, logger_fmt_kls(:mergeHash => mergeHash))
|
130
|
+
|
131
|
+
mergeHash
|
132
|
+
|
133
|
+
###STOPMERGEHASHES
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
def merge_event_tags(*eventTags)
|
138
|
+
mergeTags = eventTags.inject([]) do | tagsSumm, eventTags |
|
139
|
+
|
140
|
+
case eventTags
|
141
|
+
when NilClass then tagsSumm # this is ok; convenient to allow nil
|
142
|
+
when Array then tagsSumm.concat(eventTags)
|
143
|
+
else
|
144
|
+
surprise_exception(eventTags, :m_evts_tags, "eventTags not array")
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
$DEBUG && logger_ca(:m_evts_tags, logger_fmt_kls(:mergeTags => mergeTags))
|
150
|
+
|
151
|
+
mergeTags
|
152
|
+
end
|
153
|
+
|
154
|
+
# These from Riemann Tools, modified
|
155
|
+
|
156
|
+
def run(runArgs=nil, &runBlok)
|
157
|
+
eye = 'rfms r'
|
158
|
+
|
159
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:runArgs => runArgs, :runBlok => runBlok))
|
160
|
+
|
161
|
+
###mustbe_hash_or_nil_or_croak(runArgs, eye, "runArgs not hash")
|
162
|
+
|
163
|
+
tickInterval = mustbe_fixnum_key_or_nil_or_croak(runArgs, :interval, eye, "run interval not fixnum") || find_riemann_interval_or_croak
|
164
|
+
|
165
|
+
t0 = Time.now
|
166
|
+
|
167
|
+
loop do
|
168
|
+
|
169
|
+
begin
|
170
|
+
riemann_tick
|
171
|
+
rescue => e
|
172
|
+
$stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
|
173
|
+
break
|
174
|
+
end
|
175
|
+
|
176
|
+
sleep(tickInterval - ((Time.now - t0) % tickInterval)) # Sleep.
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(:runArgs => runArgs))
|
181
|
+
|
182
|
+
self
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
def riemann_client
|
187
|
+
@riemann_client ||= Riemann::Client.new(
|
188
|
+
:host => find_riemann_host_or_croak,
|
189
|
+
:port => find_riemann_port_or_croak,
|
190
|
+
)
|
191
|
+
end
|
192
|
+
|
193
|
+
def riemann_tick
|
194
|
+
|
195
|
+
r = riemann_client
|
196
|
+
|
197
|
+
if (! $DEBUG)
|
198
|
+
each_event {|e| e && (r << e) } # send to riemann
|
199
|
+
else
|
200
|
+
|
201
|
+
#=begin
|
202
|
+
t = Time.now.localtime
|
203
|
+
#to_events.each_with_index do |e,i|
|
204
|
+
to_enum(:each_event).each_with_index do |e, i|
|
205
|
+
|
206
|
+
#i += 1
|
207
|
+
|
208
|
+
puts("TICK #{t} NDX >#{i}< EVT e >#{e}<");
|
209
|
+
|
210
|
+
# COMMNETED FOR TESTINGe && (r << e)
|
211
|
+
|
212
|
+
end # send to riemann #TESTING
|
213
|
+
#=end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# This method is passed the specification and returns
|
218
|
+
# the consoldidated definitions collection
|
219
|
+
|
220
|
+
def make_attributes_definitions_or_croak(attrArgs, &attrBlok)
|
221
|
+
eye = :'m_attrs_defs'
|
222
|
+
|
223
|
+
# Work with attribute as strings
|
224
|
+
|
225
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:attrArgs => attrArgs, :attrBlok => attrBlok))
|
226
|
+
|
227
|
+
mustbe_attributes_specification_or_croak(attrArgs, eye, "attrArgs not attributes_specification")
|
228
|
+
|
229
|
+
#STOPATTRARGSINSUPER
|
230
|
+
|
231
|
+
#attrAll = mustbe_not_empty_or_croak(mustbe_array_key_or_nil_or_croak(attrArgs, :all, eye, "all attributes not array"), eye, "all attributes is empty").map(&:to_s)
|
232
|
+
attrAll = mustbe_not_empty_or_croak(mustbe_attributes_specification_all_key_or_croak(attrArgs, :all, eye), eye, "all attributes is empty").map(&:to_s)
|
233
|
+
|
234
|
+
|
235
|
+
#puts("\n\n\nATTR ALL >#{attrAll}<")
|
236
|
+
|
237
|
+
#STOPMAKEATTRSPECSENTRY
|
238
|
+
|
239
|
+
attrInc = mustbe_attributes_specification_include_key_or_nil_or_croak(attrArgs, :include, eye) # mustbe all strings
|
240
|
+
#puts("ATTR INC >#{attrInc.class}< >#{attrInc}< >#{is_value_not_empty?(attrInc)}<")
|
241
|
+
attrInc && mustbe_not_empty_or_croak(attrInc, eye, "include attributes is empty")
|
242
|
+
|
243
|
+
attrExc = mustbe_attributes_specification_exclude_key_or_nil_or_croak(attrArgs, :exclude, eye) || []
|
244
|
+
|
245
|
+
attrMapNom = mustbe_attributes_definitions_key_or_nil_or_croak(attrArgs, :definitions, eye) || {}
|
246
|
+
attrMap = attrMapNom && potrubi_util_map_hash_kv(attrMapNom) {|k,v| [k.to_s, v]} # keys all strings
|
247
|
+
|
248
|
+
# Ensure all consistent
|
249
|
+
|
250
|
+
attrInc && mustbe_subset_or_croak(attrInc, attrAll, eye, "include attributes contains unknown attributes")
|
251
|
+
mustbe_subset_or_croak(attrExc, attrAll, eye, "exclude attributes contains unknown attributes")
|
252
|
+
mustbe_subset_or_croak(attrMap.keys, attrAll, eye, "attribute map contains unknown attributes")
|
253
|
+
|
254
|
+
attrUse = ((attrInc || attrAll) - attrExc).uniq # list of unique attributes to report on
|
255
|
+
|
256
|
+
# consolidate "faked up" attr specs with ones provided to get the composite attrSpecs
|
257
|
+
|
258
|
+
attrDefsNom = potrubi_util_array_to_hash(attrUse).merge(attrMap.select {|k,v| attrUse.include?(k)}) # consolidated "faked up" attr specs with ones provided
|
259
|
+
|
260
|
+
attrDefs = potrubi_util_map_hash_v(attrDefsNom) do | attrName, attrSpecNom|
|
261
|
+
|
262
|
+
attrSpec =
|
263
|
+
case attrSpecNom
|
264
|
+
when NilClass then {}
|
265
|
+
when Hash then
|
266
|
+
attrSpecNom.each_with_object({}) do | (verbName, verbSpec), h1 |
|
267
|
+
case verbName
|
268
|
+
when :pass_thru then h1[:pass_thru] = verbSpec # dont touch; just pass through
|
269
|
+
when :event_defaults then # add these to pass_thru
|
270
|
+
h1[:pass_thru] = (h1[:pass_thru] || {}).merge(verbName => verbSpec)
|
271
|
+
when :map, :select, :metric then
|
272
|
+
h1[verbName] = {
|
273
|
+
:method_name => "#{verbName}_#{attrName}_#{rand(1000000)}", # make a unqiue name
|
274
|
+
:method_spec => verbSpec # spec must be valid to dynamic_define_methods
|
275
|
+
}
|
276
|
+
else
|
277
|
+
logic_exception(verbName, eye, "attrName >#{attrName}< verbName >#{verbName}< value should be impossible")
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
else
|
282
|
+
logic_exception(attrrSpecNom, eye, "attrSpecNom value should be impossible")
|
283
|
+
end
|
284
|
+
|
285
|
+
attrSpec
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(:attrDefs => attrDefs))
|
290
|
+
|
291
|
+
mustbe_attributes_definitions_or_croak(attrDefs, eye, "attrDefs failed contract")
|
292
|
+
|
293
|
+
#STOPMAKEATTRSPECS
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
def collect_attributes_method_definitions_or_croak(attrSpecs, &attrBlok)
|
298
|
+
eye = :'rfts col_attr_mtd_defs'
|
299
|
+
|
300
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(:attrSpecs => attrSpecs, :attrBlok => attrBlok))
|
301
|
+
|
302
|
+
#STOPCOLLECTATTRSMTDS
|
303
|
+
|
304
|
+
attrMths = attrSpecs.each_with_object({}) do | (attrName, attrSpec), h |
|
305
|
+
|
306
|
+
$DEBUG && logger_beg(eye, 'ATTR MTH', logger_fmt_kls(:attrName => attrName, :attrSpec => attrSpec))
|
307
|
+
|
308
|
+
attrSpec.select {|k,v| v.has_key?(:method_name) }.each {|k, v| h[v[:method_name]] = v[:method_spec] }
|
309
|
+
|
310
|
+
$DEBUG && logger_fin(eye, 'ATTR MTH', logger_fmt_kls(:attrName => attrName, :attrSpec => attrSpec))
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(attrMths: attrMths), logger_fmt_kls(attrSpec: attrSpecs))
|
316
|
+
|
317
|
+
mustbe_hash_or_croak(attrMths, eye, "attrMths not hash")
|
318
|
+
|
319
|
+
#STOPEHERECOLATTRMTDS
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
klassConstant = Potrubi::Core.assign_class_constant_or_croak(classContent, :Riemann, :Feeds, :Type, :Super)
|
326
|
+
|
327
|
+
__END__
|
328
|
+
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riemann-feeds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ian Rumford
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: riemann-client
|
16
|
+
requirement: &20761620 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *20761620
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: potrubi
|
27
|
+
requirement: &20760320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *20760320
|
36
|
+
description: ! 'Riemann-Feeds: a framework for Riemann event collectors'
|
37
|
+
email:
|
38
|
+
- ian@rumford.name
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- README.md
|
44
|
+
- lib/riemann-feeds.rb
|
45
|
+
- lib/riemann/feeds/feed-handler.rb
|
46
|
+
- lib/riemann/feeds/mixin/standard.rb
|
47
|
+
- lib/riemann/feeds/type/jmx.rb
|
48
|
+
- lib/riemann/feeds/type/super.rb
|
49
|
+
- lib/riemann/feeds/version.rb
|
50
|
+
homepage: https://github.com/ianrumford/riemann-feeds
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.9.3
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project: riemann-feeds
|
70
|
+
rubygems_version: 1.8.11
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: ! 'Riemann-Feeds: Riemann event collectors'
|
74
|
+
test_files: []
|