lib/riemann/babbler/plugin.rb in riemann-babbler-0.4.1 vs lib/riemann/babbler/plugin.rb in riemann-babbler-0.4.2
- old
+ new
@@ -26,15 +26,29 @@
@storage = Hash.new
init
run
end
+ # Доступ к конфигу определенного плагина
+ def plugin
+ plugin_name = self.class.name.split( "::" ).last.gsub( /(\p{Lower})(\p{Upper})/, "\\1_\\2" ).downcase
+ options.plugins.send plugin_name
+ end
+
def options
@configatron
end
alias :opts :options
+ def riemann
+ @riemann ||= Riemann::Client.new(
+ :host => options.riemann.host,
+ :port => options.riemann.port
+ )
+ end
+ alias :r :riemann
+
def report(event)
report_with_diff(event) and return if event[:as_diff]
event[:state] = state(event[:metric]) unless plugin.states.critical.nil?
event[:tags] = options.riemann.tags unless options.riemann.tags.nil?
event[:host] = host
@@ -64,30 +78,20 @@
# не запускаем плагин есть
def run_plugin
true
end
- # http rest
- def rest_get(url)
- begin
- RestClient.get url
- rescue
- report({
- :service => plugin.service,
- :state => 'critical',
- :description => "Response from #{url}"
- })
- end
+ # Переодически вызываемое действие
+ def tick
+ posted_array = collect
+ posted_array = posted_array.class == Array ? posted_array : [ posted_array ]
+ posted_array.each { |event| report event }
end
- def riemann
- @riemann ||= Riemann::Client.new(
- :host => options.riemann.host,
- :port => options.riemann.port
- )
+ # Plugin init
+ def init
end
- alias :r :riemann
def run
# выйти если run_plugin не равен true
return 0 unless run_plugin == true
t0 = Time.now
@@ -100,27 +104,26 @@
sleep(plugin.interval - ((Time.now - t0) % plugin.interval))
end
end
- # Переодически вызываемое действие
- def tick
- posted_array = collect
- posted_array = posted_array.class == Array ? posted_array : [ posted_array ]
- posted_array.each { |event| report event }
+ # хелпер, описание статуса
+ def state(my_state)
+ unless plugin.states.warning.nil?
+ case
+ when my_state.between?(plugin.states.warning, plugin.states.critical)
+ 'warning'
+ when my_state > plugin.states.warning
+ 'critical'
+ else
+ 'ok'
+ end
+ else
+ my_state >= plugin.states.critical ? 'critical' : 'ok'
+ end
end
- # Доступ к конфигу определенного плагина
- def plugin
- plugin_name = self.class.name.split( "::" ).last.gsub( /(\p{Lower})(\p{Upper})/, "\\1_\\2" ).downcase
- options.plugins.send plugin_name
- end
-
- # Plugin init
- def init
- end
-
# хэлпер для парса stdout+stderr и exit status
def shell(*cmd)
exit_status=nil
err=nil
out=nil
@@ -140,22 +143,19 @@
else
return true
end
end
- # хелпер, описание статуса
- def state(my_state)
- unless plugin.states.warning.nil?
- case
- when my_state.between?(plugin.states.warning, plugin.states.critical)
- 'warning'
- when my_state > plugin.states.warning
- 'critical'
- else
- 'ok'
- end
- else
- my_state >= plugin.states.critical ? 'critical' : 'ok'
+ # http rest
+ def rest_get(url)
+ begin
+ RestClient.get url
+ rescue
+ report({
+ :service => plugin.service,
+ :state => 'critical',
+ :description => "Response from #{url}"
+ })
end
end
end
end