check_slony 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- .autotest
2
1
  History.txt
3
2
  Manifest.txt
4
3
  README.txt
data/README.txt CHANGED
@@ -14,6 +14,7 @@ This is an check plugin for Nagios.
14
14
  % check_slony.rb -d slonydb -c replication -e 10 -l 10
15
15
  POSTGRES_REPLICATION_LAG OK: SUBSCRIBER 1 ON ORIGIN 2 : EVENT LAG=0 TIME LAG=8s ||
16
16
 
17
+
17
18
  == REQUIREMENTS:
18
19
 
19
20
  pg
@@ -5,7 +5,6 @@ require 'pg'
5
5
  require 'optparse'
6
6
  require 'timeout'
7
7
 
8
-
9
8
  pgoptions=''
10
9
  pgtty=''
11
10
  @result=''
@@ -25,6 +24,8 @@ OptionParser.new do |opt|
25
24
  opt.on("-e","--events=EVENTS", Integer, "Specify the Event Counts"){|e| @event = e }
26
25
  opt.on("-l","--lagtime=LAGTIME", Integer, "Specify the LAGTIME"){|l| @lagtime = l }
27
26
  opt.on("-t","--timeout=TIMEOUT", Integer, "Specify the TIMEOUT"){|t| @timeout = t }
27
+ opt.on("-c","--countall", "All Tables count check(must be against master node)"){ @countall = true }
28
+ opt.on("-v","--verbose", "verbose output(when specify the '-c')"){ @verbose = true }
28
29
 
29
30
  begin
30
31
  opt.parse!(ARGV)
@@ -34,46 +35,141 @@ OptionParser.new do |opt|
34
35
  end
35
36
  end
36
37
 
37
- begin
38
- timeout(@timeout){
39
- # sleep 3 # for debug
40
- con = PGconn.new(@hostname, @port, pgoptions, pgtty, @dbname, @user, @password)
41
- query = 'SELECT st_origin, st_received, st_lag_num_events, round(extract(epoch from st_lag_time)) from "_' + @cluster + '".sl_status'
38
+ def countcheck_all_tables(options, tty)
39
+ result_hash = {}
40
+ result_hash["status"] = "OK"
41
+ error_str = ""
42
+ con = PGconn.new(@hostname, @port, options, tty, @dbname, @user, @password)
43
+ #
44
+ query = 'SELECT tab_relname from "_' + @cluster + '".sl_table'
45
+ res = con.exec(query)
46
+
47
+ sl_table = []
48
+ res.each do |r|
49
+ sl_table << r["tab_relname"]
50
+ end
51
+ #
52
+ query = 'SELECT pa_server, pa_conninfo from "_' + @cluster + '".sl_path order by pa_server'
53
+ res = con.exec(query)
54
+ @pg_hash = {}
55
+ res.each do |r|
56
+ info_hash = {}
57
+ r["pa_conninfo"].split(" ").each do |info|
58
+ # puts "******"
59
+ # puts info.split("=")[0] + '=' + info.split("=")[1]
60
+ info_hash[info.split("=")[0]] = info.split("=")[1]
61
+ end
62
+ @pg_hash[r["pa_server"]] = info_hash
63
+ end
64
+ con.close
42
65
 
66
+ @master = @pg_hash.delete("1")
67
+ # save master node data
68
+ con = PGconn.new(@master["host"], @master["port"], options, tty, @master["dbname"], @master["user"], @master["password"])
69
+ sl_table.each do |t|
70
+ query = 'SELECT count(*) as cnt from ' + t
43
71
  res = con.exec(query)
44
- unless res
45
- print "POSTGRES_REPLICATION_LAG CRITICAL: Cannot prepare $DBI::errstr\n";
46
- exit 2
72
+ @master[t] = res[0]["cnt"]
73
+ end
74
+ con.close
75
+
76
+ # save slave node data
77
+ @pg_hash.each {|node, info|
78
+ con = PGconn.new(info["host"], info["port"], options, tty, info["dbname"], info["user"], info["password"])
79
+ sl_table.each do |t|
80
+ query = 'SELECT count(*) as cnt from ' + t
81
+ res = con.exec(query)
82
+ info[t] = [res[0]["cnt"], false]
83
+ if @master[t] != info[t][0]
84
+ info[t][1] = true
85
+ result_hash["status"] = "NG"
86
+ error_str += "node #{node} #{t}"
87
+ end
88
+ end
89
+ con.close
90
+ }
91
+ result_hash["error"] = error_str
92
+
93
+ # only '-v'
94
+ if @verbose
95
+ fmt_str = '| %10s'
96
+ cols = fmt_str * @pg_hash.count
97
+ state = '| %2s'
98
+ fmt = "%-35s | %10s" + cols + state + "\n"
99
+ @val_ary = ["tablename", "master"]
100
+ @pg_hash.each{ |node,val|
101
+ @val_ary << node
102
+ }
103
+ @val_ary << "status"
104
+ puts fmt % @val_ary
105
+ puts '-' * ((@pg_hash.count * 15) + 60)
106
+ sl_table.each do |t|
107
+ temp_array = [t, @master[t]]
108
+ @pg_hash.each{ |k,v|
109
+ temp_array << v[t][0]
110
+ temp_array << (v[t][1] ? "NG" : "OK")
111
+ }
112
+ puts fmt % temp_array
47
113
  end
114
+ end
48
115
 
49
- res.each do |r|
116
+ return result_hash
117
+ end
50
118
 
51
- node = r["st_received"]
52
- master = r["st_origin"]
53
- lag = r["st_lag_num_events"]
54
- round = r["round"]
55
119
 
56
- @result += "SUBSCRIBER " + node + " ON ORIGIN " + master + " : EVENT LAG=" + lag
57
- if (lag.to_i > 0) && (@event < lag.to_i)
58
- @result = @result + " (BEHIND " + (lag.to_i - @event).to_s + ") ";
120
+ begin
121
+ timeout(@timeout){
122
+ # sleep 3 # for debug
123
+ title = "POSTGRES_"
124
+ if @countall
125
+ title += "COUNTCHECK "
126
+ state = countcheck_all_tables(pgoptions, pgtty)
127
+ if state["status"] == "OK"
128
+ @result = "NO DIFFERENCE"
129
+ else
130
+ @result = "DIFFERENCE OCCURED ON " + state["error"]
59
131
  @problems += 1
60
132
  end
61
- @result = @result + " TIME LAG=" + round + "s";
62
-
63
- if (@lagtime > 0) && (@lagtime < round.to_i)
64
- @result = @result + " (BEHIND " + (round.to_i - @lagtime).to_s + "s) ";
65
- @problems += 1
133
+ else
134
+ title += "REPLICATION_LAG "
135
+ con = PGconn.new(@hostname, @port, pgoptions, pgtty, @dbname, @user, @password)
136
+ query = 'SELECT st_origin, st_received, st_lag_num_events, round(extract(epoch from st_lag_time)) from "_' + @cluster + '".sl_status'
137
+
138
+ res = con.exec(query)
139
+ unless res
140
+ print "#{title} CRITICAL: Cannot prepare $DBI::errstr\n";
141
+ exit 2
66
142
  end
67
- @result = @result + " || ";
68
143
 
144
+ res.each do |r|
145
+
146
+ node = r["st_received"]
147
+ master = r["st_origin"]
148
+ lag = r["st_lag_num_events"]
149
+ round = r["round"]
150
+
151
+ @result += "SUBSCRIBER " + node + " ON ORIGIN " + master + " : EVENT LAG=" + lag
152
+ if (lag.to_i > 0) && (@event < lag.to_i)
153
+ @result = @result + " (BEHIND " + (lag.to_i - @event).to_s + ") ";
154
+ @problems += 1
155
+ end
156
+ @result = @result + " TIME LAG=" + round + "s";
157
+
158
+ if (@lagtime > 0) && (@lagtime < round.to_i)
159
+ @result = @result + " (BEHIND " + (round.to_i - @lagtime).to_s + "s) ";
160
+ @problems += 1
161
+ end
162
+ @result = @result + " || ";
163
+
164
+ end
69
165
  end
70
166
 
71
167
  if @problems > 0
72
- @result = "POSTGRES_REPLICATION_LAG CRITICAL: " + @result + "\n"
168
+ @result = title + "CRITICAL: " + @result + "\n"
73
169
  print @result
74
170
  exit 2
75
171
  else
76
- @result = "POSTGRES_REPLICATION_LAG OK: " + @result + "\n"
172
+ @result = title + "OK: " + @result + "\n"
77
173
  print @result
78
174
  exit 0
79
175
  end
@@ -92,6 +188,3 @@ end
92
188
 
93
189
 
94
190
 
95
-
96
- exit;
97
- abort "you need to write me"
@@ -1,4 +1,4 @@
1
1
  class CheckSlony
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_slony
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - kakikubo
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-10 00:00:00 +09:00
19
- default_executable:
18
+ date: 2011-11-29 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: hoe
@@ -46,7 +45,6 @@ extra_rdoc_files:
46
45
  - Manifest.txt
47
46
  - README.txt
48
47
  files:
49
- - .autotest
50
48
  - History.txt
51
49
  - Manifest.txt
52
50
  - README.txt
@@ -54,7 +52,6 @@ files:
54
52
  - bin/check_slony
55
53
  - lib/check_slony.rb
56
54
  - test/test_check_slony.rb
57
- has_rdoc: true
58
55
  homepage: https://github.com/kakikubo/check_slony
59
56
  licenses: []
60
57
 
@@ -85,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
82
  requirements: []
86
83
 
87
84
  rubyforge_project: check_slony
88
- rubygems_version: 1.4.2
85
+ rubygems_version: 1.8.11
89
86
  signing_key:
90
87
  specification_version: 3
91
88
  summary: This is an check plugin for Nagios.
data/.autotest DELETED
@@ -1,23 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'autotest/restart'
4
-
5
- # Autotest.add_hook :initialize do |at|
6
- # at.extra_files << "../some/external/dependency.rb"
7
- #
8
- # at.libs << ":../some/external"
9
- #
10
- # at.add_exception 'vendor'
11
- #
12
- # at.add_mapping(/dependency.rb/) do |f, _|
13
- # at.files_matching(/test_.*rb$/)
14
- # end
15
- #
16
- # %w(TestA TestB).each do |klass|
17
- # at.extra_class_map[klass] = "test/test_misc.rb"
18
- # end
19
- # end
20
-
21
- # Autotest.add_hook :run_command do |at|
22
- # system "rake build"
23
- # end