Sha256: f5414163d9079453a8214e534af7272af9f29b9deff2ce40a1aab5ab051b07ce

Contents?: true

Size: 1.02 KB

Versions: 21

Compression:

Stored size: 1.02 KB

Contents

#!/usr/bin/env ruby

require 'xmpp4r'

module Flapjack
  module Notifiers
    class Xmpp

      def initialize(opts={})

        @jid = opts[:jid]
        @password = opts[:password]
        @log = opts[:logger]
        unless @jid && @password
          raise ArgumentError, "You have to provide a username and password"
        end

        begin
          @xmpp = Jabber::Client.new(@jid)
          @xmpp.connect
          @xmpp.auth(@password)
        rescue SocketError => e
          @log.error("XMPP: #{e.message}")
        end

      end

      def notify(opts={})

        raise ArgumentError, "a recipient was not specified" unless opts[:who]
        raise ArgumentError, "a result was not specified" unless opts[:result]

        text = <<-DESC
          Check #{opts[:result].check_id} returned the status "#{opts[:result].status}".
            http://localhost:4000/checks/#{opts[:result].check_id}
        DESC

        message = Jabber::Message.new(opts[:who].jid, text)
        @xmpp.send(message)

      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
flapjack-0.6.43 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.42 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.41 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.40 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.39 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.38 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.37 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.36 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.35 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.34 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.33 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.32 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.31 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.30 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.29 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.28 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.27 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.26 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.25 lib/flapjack/notifiers/xmpp/xmpp.rb
flapjack-0.6.24 lib/flapjack/notifiers/xmpp/xmpp.rb