lib/riemann/babbler/plugin.rb in riemann-babbler-0.3.1 vs lib/riemann/babbler/plugin.rb in riemann-babbler-0.3.3
- old
+ new
@@ -1,35 +1,34 @@
#encoding: utf-8
# Базовое описание плагина
module Riemann
- module Babbler
+ class Babbler
+ def self.registered_plugins
+ @plugins ||= []
+ end
+
+ def self.inherited( klass )
+ registered_plugins << klass
+ end
+
require 'riemann/client'
require 'open3'
require 'timeout'
require 'rest_client'
- def self.included(base)
- base.instance_eval do
- def run
- new.run
- end
- end
- end
+ attr_reader :logger
- def initialize
- @configatron = $configatron
+ def initialize( configatron, logger )
+ @configatron = configatron
+ @logger = logger
@storage = Hash.new
init
run
end
- def log
- @logger ||= $logger
- end
-
def options
@configatron
end
alias :opts :options
@@ -38,11 +37,11 @@
when Hash
report_with_diff(event) and return
end
event[:tags] = options.riemann.tags unless options.riemann.tags.nil?
event[:host] = host
- log.debug "Report status: #{event.inspect}"
+ logger.debug "Report status: #{event.inspect}"
riemann << event
end
def report_with_diff(event)
current_metric = event[:metric][:value]
@@ -104,22 +103,13 @@
# Переодически вызываемое действие
def tick
posted_hash = collect
posted_hash.each_key do |service|
- case service
- when Hash
- report({
- :service => plugin.service + " " + service,
- :metric => posted_hash[service],
- :is_diff => posted_hash[:is_diff]
- })
- else
- report({
- :service => plugin.service + " " + service,
- :metric => posted_hash[service]
- })
- end
+ report({
+ :service => service,
+ :metric => posted_hash[service][:metric]
+ })
end
end
# Доступ к конфигу определенного плагина
def plugin