Sha256: 10dc98b5a883cb119ebd4f925eee34b61d7e67f5e3694aebdc4db48b72c7bf39
Contents?: true
Size: 1.79 KB
Versions: 5
Compression:
Stored size: 1.79 KB
Contents
#encoding: utf-8 # Базовое описание плагина module Riemann module Babbler require 'riemann/client' def self.included(base) base.instance_eval do def run new.run end end end def initialize @configatron = $configatron super end def log @logger ||= $logger end def options @configatron end alias :opts :options def report(event) event[:tags] = options.riemann.tags unless options.riemann.tags.nil? event[:host] = host log.debug "Report status: #{event.inspect}" riemann << event end def host hostname = `hostname`.chomp.downcase hostname += options.riemann.suffix unless options.riemann.suffix.nil? hostname = options.riemann.prefix + hostname unless options.riemann.prefix.nil? hostname end def riemann @riemann ||= Riemann::Client.new( :host => options.riemann.host, :port => options.riemann.port ) end alias :r :riemann def run t0 = Time.now loop do begin tick rescue => e $stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}" end # Sleep. sleep(plugin.interval - ((Time.now - t0) % plugin.interval)) end end # Переодически вызываемое действие def tick end # Доступ к конфигу определенного плагина def plugin end # хелпер, описание статуса def state(my_state) case when my_state.between?(plugin.states.warning, plugin.states.critical) 'warning' when my_state > plugin.states.warning 'critical' else 'ok' end end end end
Version data entries
5 entries across 5 versions & 1 rubygems