class Flapjack::Gateways::Oobetet::Bot
Attributes
siblings[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 207 def initialize(opts = {}) @lock = opts[:lock] @stop_cond = opts[:stop_condition] @config = opts[:config] @hostname = Socket.gethostname unless @config['watched_check'] raise RuntimeError, 'Flapjack::Oobetet: watched_check must be defined in the config' end @check_matcher = '"' + @config['watched_check'] + '"' Flapjack.logger.debug("new oobetet pikelet with the following options: #{@config.inspect}") end
Public Instance Methods
announce(msg)
click to toggle source
TODO buffer if not connected?
# File lib/flapjack/gateways/oobetet.rb, line 280 def announce(msg) @lock.synchronize do unless @muc_clients.empty? @muc_clients.each_pair do |room, muc_client| muc_client.say(msg) end end end end
start()
click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 222 def start @lock.synchronize do @time_checker ||= @siblings && @siblings.detect {|sib| sib.respond_to?(:receive_status) } Flapjack.logger.info("starting") # ::Jabber::debug = true jabber_id = @config['jabberid'] || 'flapjack' @flapjack_jid = ::Jabber::JID.new(jabber_id + '/' + @hostname) @client = ::Jabber::Client.new(@flapjack_jid) @muc_clients = @config['rooms'].inject({}) do |memo, room| muc_client = ::Jabber::MUC::SimpleMUCClient.new(@client) memo[room] = muc_client memo end @client.connect @client.auth(@config['password']) @client.send(::Jabber::Presence.new.set_type(:available)) @muc_clients.each_pair do |room, muc_client| muc_client.on_message do |time, nick, text| next if nick == jabber_id if @time_checker Flapjack.logger.debug("group message received: #{room}, #{text}") if (text =~ /^((?i:problem|recovery|acknowledgement)).*#{Regexp.escape(@check_matcher)}/) # got something interesting status = Regexp.last_match(1).downcase Flapjack.logger.debug("found the following state for #{@check_matcher}: #{status}") @time_checker.receive_status(status, time.to_i) end end end muc_client.join(room + '/' + @config['alias']) muc_client.say("flapjack oobetet gateway started at #{Time.now}, hello!") end # block this thread until signalled to quit @stop_cond.wait_until { @should_quit } @muc_clients.each_pair do |room, muc_client| muc_client.exit if muc_client.active? end @client.close end end
stop_type()
click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 275 def stop_type :signal end