Sha256: 06779cb525dab51e44a3bf152bf2c89879143d8a2ace0bd60653dd0c50abd62c
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
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 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
riemann-babbler-0.0.4 | lib/riemann/babbler/plugin.rb |
riemann-babbler-0.0.3 | lib/riemann/babbler/plugin.rb |