Class: CheckTaskr::XmppChatAction
- Inherits:
-
JobsAction
- Object
- JobsAction
- CheckTaskr::XmppChatAction
- Includes:
- Socket::Constants
- Defined in:
- lib/check-taskr/task/xmpp_chat.rb
Instance Attribute Summary collapse
-
#client1 ⇒ Object
Returns the value of attribute client1.
-
#client2 ⇒ Object
Returns the value of attribute client2.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#error_msg ⇒ Object
Returns the value of attribute error_msg.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#is_failed ⇒ Object
Returns the value of attribute is_failed.
-
#jid1 ⇒ Object
Returns the value of attribute jid1.
-
#jid2 ⇒ Object
Returns the value of attribute jid2.
-
#password1 ⇒ Object
Returns the value of attribute password1.
-
#password2 ⇒ Object
Returns the value of attribute password2.
-
#port ⇒ Object
Returns the value of attribute port.
-
#sjid1 ⇒ Object
Returns the value of attribute sjid1.
-
#sjid2 ⇒ Object
Returns the value of attribute sjid2.
Attributes inherited from JobsAction
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options) ⇒ XmppChatAction
constructor
A new instance of XmppChatAction.
- #login1 ⇒ Object
- #login2 ⇒ Object
Methods inherited from JobsAction
Constructor Details
#initialize(options) ⇒ XmppChatAction
Returns a new instance of XmppChatAction.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 27 def initialize() @name ||= [:name] @ip = [:ip] @port = [:port] || 5222 @sjid1 = [:jid1] @password1 = [:password1] @sjid2 = [:jid2] @password2 = [:password2] @error_code = [:error_code] || @@default_error_code @error_msg = [:error_msg] || @@default_error_msg login1 login2 end |
Instance Attribute Details
#client1 ⇒ Object
Returns the value of attribute client1.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def client1 @client1 end |
#client2 ⇒ Object
Returns the value of attribute client2.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def client2 @client2 end |
#error_code ⇒ Object
Returns the value of attribute error_code.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def error_code @error_code end |
#error_msg ⇒ Object
Returns the value of attribute error_msg.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def error_msg @error_msg end |
#ip ⇒ Object
Returns the value of attribute ip.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def ip @ip end |
#is_failed ⇒ Object
Returns the value of attribute is_failed.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def is_failed @is_failed end |
#jid1 ⇒ Object
Returns the value of attribute jid1.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def jid1 @jid1 end |
#jid2 ⇒ Object
Returns the value of attribute jid2.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def jid2 @jid2 end |
#password1 ⇒ Object
Returns the value of attribute password1.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def password1 @password1 end |
#password2 ⇒ Object
Returns the value of attribute password2.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def password2 @password2 end |
#port ⇒ Object
Returns the value of attribute port.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def port @port end |
#sjid1 ⇒ Object
Returns the value of attribute sjid1.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def sjid1 @sjid1 end |
#sjid2 ⇒ Object
Returns the value of attribute sjid2.
23 24 25 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 23 def sjid2 @sjid2 end |
Instance Method Details
#execute ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 69 def execute log = Log4r::Logger['default'] log.debug "xmpp action: ip=#{@ip}, port=#{@port}, name=#{@name}" hash = {:stat => 0, :ip => @ip, :msg => "OK", :error_id => @error_code } begin unless @client1.is_connected? login1 end unless @client2.is_connected? login2 end body = UUID.generate = Jabber::Message::new(@jid2, body).set_type(:normal).set_id('1') @client1.send() sleep(0.2) hash[:timestamp] = Time.now.to_i unless body.eql?(@message_body) hash[:stat] = 3 hash[:msg] = "在0.2秒内没有收到回应" end rescue Exception => e hash[:stat] = 2 hash[:timestamp] = Time.now.to_i hash[:msg] = "XMPP异常:#{e}" log.error hash.to_json end hash end |
#login1 ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 42 def login1 @jid1 = Jabber::JID.new("#{@sjid1}/check-taskr") if !@client1.nil? && @client1.is_connected? @client1.close end @client1 = Jabber::Client.new(@jid1) @client1.connect(@ip, @port) @client1.auth(@password1) @client1.send(Jabber::Presence.new.set_show(:chat).set_status('check-taskr!')) end |
#login2 ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/check-taskr/task/xmpp_chat.rb', line 53 def login2 @jid2 = Jabber::JID.new("#{@sjid2}/check-taskr") if !@client2.nil? && @client2.is_connected? @client2.close end @client2 = Jabber::Client.new(@jid2) @client2. do |m| if m.type != :error @message_body = m.body end end @client2.connect(@ip, @port) @client2.auth(@password2) @client2.send(Jabber::Presence.new.set_show(:chat).set_status('check-taskr!')) end |