check-taskr 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/check-taskr +7 -1
- data/jobs.rb +9 -3
- data/lib/check-taskr/base.rb +6 -5
- data/lib/check-taskr/cli.rb +2 -6
- data/lib/check-taskr/task/http_code.rb +1 -1
- data/lib/check-taskr/task/http_json.rb +1 -1
- data/lib/check-taskr/task/http_result.rb +4 -4
- data/lib/check-taskr/task/sockets.rb +1 -1
- data/lib/check-taskr/task/xmpp_chat.rb +104 -0
- metadata +17 -3
data/Rakefile
CHANGED
@@ -18,6 +18,7 @@ begin
|
|
18
18
|
gem.add_dependency "json"
|
19
19
|
gem.add_dependency "haml"
|
20
20
|
gem.add_dependency "log4r"
|
21
|
+
gem.add_dependency "xmpp4r"
|
21
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
23
|
end
|
23
24
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.3
|
data/bin/check-taskr
CHANGED
@@ -10,7 +10,7 @@ require 'sinatra'
|
|
10
10
|
|
11
11
|
require 'log4r'
|
12
12
|
require "log4r/outputter/datefileoutputter"
|
13
|
-
|
13
|
+
|
14
14
|
require "check-taskr"
|
15
15
|
|
16
16
|
filename = "jobs"
|
@@ -20,6 +20,12 @@ if ARGV.size > 0
|
|
20
20
|
logdir = File.dirname(File.realdirpath(filename)) + "/logs"
|
21
21
|
end
|
22
22
|
|
23
|
+
log = Log4r::Logger.new('default')
|
24
|
+
log.outputters = Log4r::DateFileOutputter.new('check_log', :dirname => logdir)
|
25
|
+
log.level = Log4r::DEBUG
|
26
|
+
|
27
|
+
log.debug("load #{filename} file, log on #{logdir} ...")
|
28
|
+
|
23
29
|
CheckTaskr::Cli.execute(filename, :logdir => logdir)
|
24
30
|
config = CheckTaskr::JobsConfiguration.instance
|
25
31
|
|
data/jobs.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
JobsConfiguration.init(:port => 4899) do |check|
|
3
|
-
check.log_level
|
3
|
+
check.log_level DEBUG
|
4
4
|
|
5
5
|
check.setup_tcp_port :error_code => 10231
|
6
6
|
|
@@ -9,9 +9,15 @@ JobsConfiguration.init(:port => 4899) do |check|
|
|
9
9
|
check.tcp_port "NotExistsDB", :hosts => "10.251.251.38", :port => 18299, :error_msg => "这一服务没有打开"
|
10
10
|
|
11
11
|
check.http_returncode "HudsonWeb", :hosts => ["10.241.12.38", "10.241.12.40"],
|
12
|
-
|
12
|
+
:port => 8099, :error_code => 909915
|
13
13
|
|
14
14
|
check.http_json "Sujie", :hosts => ["10.241.38.75", "10.241.38.22", "10.241.12.38", "10.241.14.35"],
|
15
|
-
|
15
|
+
:port => 8080, :path => "/admin/msg_admin_check_status", :error_code => 324234
|
16
16
|
|
17
|
+
# xmpp0004@mim.snda=f18f13ea13af3127ad06f194ebabe602
|
18
|
+
# xmpp0003@mim.snda=778108e5e15a96b6e4becc9b59571414
|
19
|
+
check.xmpp_chat "XMPP", :hosts => "test.mim.iccs.sdo.com", :port => 5222,
|
20
|
+
:jid1 => "xmpp0004@mim.snda", :password1 => 'f18f13ea13af3127ad06f194ebabe602',
|
21
|
+
:jid2 => "xmpp0003@mim.snda", :password2 => "778108e5e15a96b6e4becc9b59571414",
|
22
|
+
:error_code => "32420001", :error_msg => "failed!"
|
17
23
|
end
|
data/lib/check-taskr/base.rb
CHANGED
@@ -17,6 +17,7 @@ module CheckTaskr
|
|
17
17
|
class JobsConfiguration
|
18
18
|
|
19
19
|
include Singleton
|
20
|
+
include Log4r
|
20
21
|
|
21
22
|
attr_accessor :sleep_time, :results, :listen_port, :locked
|
22
23
|
attr_reader :load_paths, :actions
|
@@ -54,13 +55,13 @@ module CheckTaskr
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def execute_all
|
58
|
+
log = Log4r::Logger['default']
|
57
59
|
return if @locked
|
58
|
-
log = Logger['default']
|
59
|
-
|
60
60
|
results = Hash.new
|
61
61
|
had_error = false
|
62
62
|
|
63
63
|
fail_actions = run_actions(@actions, results)
|
64
|
+
|
64
65
|
# 如果有失败,过0.1秒后重试失败的
|
65
66
|
if fail_actions.size > 0
|
66
67
|
sleep(0.1)
|
@@ -77,7 +78,7 @@ module CheckTaskr
|
|
77
78
|
|
78
79
|
def run_actions(actions, results)
|
79
80
|
fail_actions = []
|
80
|
-
log = Logger['default']
|
81
|
+
log = Log4r::Logger['default']
|
81
82
|
actions.each do |action|
|
82
83
|
hash = action.execute
|
83
84
|
unless hash.nil?
|
@@ -109,13 +110,13 @@ module CheckTaskr
|
|
109
110
|
|
110
111
|
# set log level
|
111
112
|
def log_level(level)
|
112
|
-
log = Logger['default']
|
113
|
+
log = Log4r::Logger['default']
|
113
114
|
log.level = level
|
114
115
|
end
|
115
116
|
|
116
117
|
# process hosts from options
|
117
118
|
def process_hosts(options)
|
118
|
-
log = Logger['default']
|
119
|
+
log = Log4r::Logger['default']
|
119
120
|
hosts = options.delete(:hosts)
|
120
121
|
if block_given?
|
121
122
|
if hosts.nil?
|
data/lib/check-taskr/cli.rb
CHANGED
@@ -2,20 +2,16 @@
|
|
2
2
|
require "fastthread"
|
3
3
|
require "check-taskr/base"
|
4
4
|
|
5
|
-
|
6
5
|
Dir[File.join(File.dirname(__FILE__), 'task/*.rb')].sort.each { |lib| require lib }
|
7
6
|
|
8
7
|
module CheckTaskr
|
8
|
+
include Log4r
|
9
|
+
|
9
10
|
class Cli
|
10
11
|
|
11
12
|
def self.execute(filename, options = {})
|
12
13
|
logdir = options.delete(:logdir)
|
13
14
|
# create a logger named 'mylog' that logs to stdout
|
14
|
-
log = Logger.new 'default'
|
15
|
-
log.outputters = Log4r::DateFileOutputter.new('check_log', :dirname => logdir)
|
16
|
-
log.level = WARN
|
17
|
-
|
18
|
-
log.debug("load #{filename} file, log on #{logdir} ...")
|
19
15
|
|
20
16
|
config = CheckTaskr::JobsConfiguration.instance
|
21
17
|
config.load_from_file(filename)
|
@@ -29,13 +29,13 @@ module CheckTaskr
|
|
29
29
|
@path = options[:path] || "/"
|
30
30
|
@method = options[:method] || :get
|
31
31
|
@post_data = options[:post_data]
|
32
|
-
@expect_result = options[:expect_result] || "
|
32
|
+
@expect_result = options[:expect_result] || "ok" #默认期望返回200
|
33
33
|
@error_code = options[:error_code] || @@default_error_code
|
34
34
|
@error_msg = options[:error_msg] || @@default_error_msg
|
35
35
|
end
|
36
36
|
|
37
37
|
def execute
|
38
|
-
log = Logger['default']
|
38
|
+
log = Log4r::Logger['default']
|
39
39
|
log.debug "http action: ip=#{@ip}, port=#{@port}, name=#{@name}"
|
40
40
|
hash = {:stat => 0, :ip => @ip, :msg => "OK", :error_id => @error_code }
|
41
41
|
begin
|
@@ -52,9 +52,9 @@ module CheckTaskr
|
|
52
52
|
end
|
53
53
|
result = response.body
|
54
54
|
hash[:timestamp] = Time.now.to_i
|
55
|
-
unless
|
55
|
+
unless result.include?(@expect_result)
|
56
56
|
hash[:stat] = 1
|
57
|
-
hash[:msg] = "HTTP #{@method.to_s} #{@path}
|
57
|
+
hash[:msg] = "HTTP #{@method.to_s} #{@path}期望返回值包含\"#{@expect_result}\",但返回\"#{result}\""
|
58
58
|
log.warn hash.to_json
|
59
59
|
end
|
60
60
|
end
|
@@ -35,7 +35,7 @@ module CheckTaskr
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def execute
|
38
|
-
log = Logger['default']
|
38
|
+
log = Log4r::Logger['default']
|
39
39
|
log.debug "action: ip=#{@ip}, port=#{@port}, name=#{@name}"
|
40
40
|
hash = { :stat => 0, :ip => @ip, :msg => "OK", :timestamp => Time.now.to_i, :error_id => @error_code }
|
41
41
|
begin
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'net/http'
|
3
|
+
require 'uuid'
|
4
|
+
require 'xmpp4r'
|
5
|
+
|
6
|
+
module CheckTaskr
|
7
|
+
|
8
|
+
class JobsConfiguration
|
9
|
+
|
10
|
+
def setup_xmpp_chat(options)
|
11
|
+
HttpReturnCodeAction.setup(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def xmpp_chat(name, options = {})
|
15
|
+
process_hosts(options) do |host|
|
16
|
+
action = XmppChatAction.new({:name => "#{name}-#{host}", :ip => host}.merge(options))
|
17
|
+
@actions << action
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class XmppChatAction < JobsAction
|
23
|
+
attr_accessor :ip, :port, :sjid1, :jid1, :password1, :sjid2, :jid2, :password2, :error_code, :error_msg, :client1, :client2, :is_failed
|
24
|
+
|
25
|
+
include Socket::Constants
|
26
|
+
|
27
|
+
def initialize(options)
|
28
|
+
@name ||= options[:name]
|
29
|
+
@ip = options[:ip]
|
30
|
+
@port = options[:port] || 5222
|
31
|
+
@sjid1 = options[:jid1]
|
32
|
+
@password1 = options[:password1]
|
33
|
+
@sjid2 = options[:jid2]
|
34
|
+
@password2 = options[:password2]
|
35
|
+
@error_code = options[:error_code] || @@default_error_code
|
36
|
+
@error_msg = options[:error_msg] || @@default_error_msg
|
37
|
+
|
38
|
+
login1
|
39
|
+
login2
|
40
|
+
end
|
41
|
+
|
42
|
+
def login1
|
43
|
+
@jid1 = Jabber::JID.new("#{@sjid1}/check-taskr")
|
44
|
+
if !@client1.nil? && @client1.is_connected?
|
45
|
+
@client1.close
|
46
|
+
end
|
47
|
+
@client1 = Jabber::Client.new(@jid1)
|
48
|
+
@client1.connect(@ip, @port)
|
49
|
+
@client1.auth(@password1)
|
50
|
+
@client1.send(Jabber::Presence.new.set_show(:chat).set_status('check-taskr!'))
|
51
|
+
end
|
52
|
+
|
53
|
+
def login2
|
54
|
+
@jid2 = Jabber::JID.new("#{@sjid2}/check-taskr")
|
55
|
+
if !@client2.nil? && @client2.is_connected?
|
56
|
+
@client2.close
|
57
|
+
end
|
58
|
+
@client2 = Jabber::Client.new(@jid2)
|
59
|
+
@client2.add_message_callback do |m|
|
60
|
+
if m.type != :error
|
61
|
+
@message_body = m.body
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@client2.connect(@ip, @port)
|
65
|
+
@client2.auth(@password2)
|
66
|
+
@client2.send(Jabber::Presence.new.set_show(:chat).set_status('check-taskr!'))
|
67
|
+
end
|
68
|
+
|
69
|
+
def execute
|
70
|
+
log = Log4r::Logger['default']
|
71
|
+
log.debug "xmpp action: ip=#{@ip}, port=#{@port}, name=#{@name}"
|
72
|
+
hash = {:stat => 0, :ip => @ip, :msg => "OK", :error_id => @error_code }
|
73
|
+
begin
|
74
|
+
unless @client1.is_connected?
|
75
|
+
login1
|
76
|
+
end
|
77
|
+
|
78
|
+
unless @client2.is_connected?
|
79
|
+
login2
|
80
|
+
end
|
81
|
+
|
82
|
+
body = UUID.generate
|
83
|
+
message = Jabber::Message::new(@jid2, body).set_type(:normal).set_id('1')
|
84
|
+
@client1.send(message)
|
85
|
+
|
86
|
+
sleep(0.2)
|
87
|
+
|
88
|
+
hash[:timestamp] = Time.now.to_i
|
89
|
+
unless body.eql?(@message_body)
|
90
|
+
hash[:stat] = 3
|
91
|
+
hash[:msg] = "在0.2秒内没有收到回应"
|
92
|
+
end
|
93
|
+
|
94
|
+
rescue Exception => e
|
95
|
+
hash[:stat] = 2
|
96
|
+
hash[:timestamp] = Time.now.to_i
|
97
|
+
hash[:msg] = "XMPP异常:#{e}"
|
98
|
+
log.error hash.to_json
|
99
|
+
end
|
100
|
+
hash
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 3
|
9
|
+
version: 1.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- crazycode
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-17 00:00:00 +08:00
|
18
18
|
default_executable: check-taskr
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,19 @@ dependencies:
|
|
82
82
|
version: "0"
|
83
83
|
type: :runtime
|
84
84
|
version_requirements: *id005
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: xmpp4r
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :runtime
|
97
|
+
version_requirements: *id006
|
85
98
|
description: check taskr for sdo
|
86
99
|
email: crazycode@gmail.com
|
87
100
|
executables:
|
@@ -106,6 +119,7 @@ files:
|
|
106
119
|
- lib/check-taskr/task/http_json.rb
|
107
120
|
- lib/check-taskr/task/http_result.rb
|
108
121
|
- lib/check-taskr/task/sockets.rb
|
122
|
+
- lib/check-taskr/task/xmpp_chat.rb
|
109
123
|
- test/helper.rb
|
110
124
|
- test/test_check-runner.rb
|
111
125
|
has_rdoc: true
|