check_slony 0.0.1
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/.autotest +23 -0
- data/History.txt +6 -0
- data/Manifest.txt +8 -0
- data/README.txt +52 -0
- data/Rakefile +26 -0
- data/bin/check_slony +3 -0
- data/lib/check_slony.rb +91 -0
- data/test/test_check_slony.rb +8 -0
- metadata +93 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= check_slony
|
2
|
+
|
3
|
+
http://rubyforge.org/projects/checkslony/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This is an check plugin for Nagios.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
|
12
|
+
== SYNOPSIS:
|
13
|
+
|
14
|
+
% check_slony.rb -d slonydb -c replication -e 10 -l 10
|
15
|
+
POSTGRES_REPLICATION_LAG OK: SUBSCRIBER 1 ON ORIGIN 2 : EVENT LAG=0 TIME LAG=8s ||
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
pg
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
% sudo gem install check_slony -r
|
24
|
+
|
25
|
+
|
26
|
+
== DEVELOPERS:
|
27
|
+
|
28
|
+
|
29
|
+
== LICENSE:
|
30
|
+
|
31
|
+
(The MIT License)
|
32
|
+
|
33
|
+
Copyright (c) 2011 FIX
|
34
|
+
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
36
|
+
a copy of this software and associated documentation files (the
|
37
|
+
'Software'), to deal in the Software without restriction, including
|
38
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
39
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
40
|
+
permit persons to whom the Software is furnished to do so, subject to
|
41
|
+
the following conditions:
|
42
|
+
|
43
|
+
The above copyright notice and this permission notice shall be
|
44
|
+
included in all copies or substantial portions of the Software.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
47
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
48
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
49
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
50
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
51
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
52
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
# Hoe.plugin :compiler
|
7
|
+
# Hoe.plugin :cucumberfeatures
|
8
|
+
# Hoe.plugin :gem_prelude_sucks
|
9
|
+
# Hoe.plugin :inline
|
10
|
+
# Hoe.plugin :manifest
|
11
|
+
# Hoe.plugin :newgem
|
12
|
+
# Hoe.plugin :racc
|
13
|
+
# Hoe.plugin :rubyforge
|
14
|
+
# Hoe.plugin :website
|
15
|
+
|
16
|
+
Hoe.spec 'check_slony' do
|
17
|
+
# HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
|
18
|
+
# you'll never have to touch them again!
|
19
|
+
# (delete this comment too, of course)
|
20
|
+
|
21
|
+
developer('kakikubo', 'kakikubo@gmail.com')
|
22
|
+
|
23
|
+
self.rubyforge_name = 'check_slony'
|
24
|
+
end
|
25
|
+
|
26
|
+
# vim: syntax=ruby
|
data/bin/check_slony
ADDED
data/lib/check_slony.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
requrie 'rubygems'
|
2
|
+
require 'pg'
|
3
|
+
require 'optparse'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
class CheckSlony
|
7
|
+
VERSION = '0.0.1'
|
8
|
+
end
|
9
|
+
|
10
|
+
pgoptions=''
|
11
|
+
pgtty=''
|
12
|
+
@result=''
|
13
|
+
@problems = 0
|
14
|
+
@timeout = 10
|
15
|
+
|
16
|
+
OptionParser.new do |opt|
|
17
|
+
opt.on("-H","--host=DBHOSTNAME", String, "Specify the DBHOSTNAME"){|h| @hostname = h }
|
18
|
+
opt.on("-P","--port=PORTNUMBER", Integer, "Specify the DB port number"){|p| @port = p }
|
19
|
+
opt.on("-u","--username=DBUSER", String, "Specify the DB user name"){|u| @user = u }
|
20
|
+
opt.on("-d","--dbname=DBNAME", String, "Specify the DB name"){|d| @dbname = d }
|
21
|
+
opt.on("-p","--password=PASSWORD", String, "Specify the DB password"){|p| @password = p }
|
22
|
+
opt.on("-C","--cluster=CLUSTERNAME", String, "Specify the DB CLUSTER NAME"){|c| @cluster = c }
|
23
|
+
opt.on("-e","--events=EVENTS", Integer, "Specify the Event Counts"){|e| @event = e }
|
24
|
+
opt.on("-l","--lagtime=LAGTIME", Integer, "Specify the LAGTIME"){|l| @lagtime = l }
|
25
|
+
opt.on("-t","--timeout=TIMEOUT", Integer, "Specify the TIMEOUT"){|t| @timeout = t }
|
26
|
+
|
27
|
+
begin
|
28
|
+
opt.parse!(ARGV)
|
29
|
+
rescue OptionParser::ParseError => err
|
30
|
+
$stderr.puts err.message
|
31
|
+
$stderr.puts opt.help
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
timeout(@timeout){
|
37
|
+
# sleep 3 # for debug
|
38
|
+
con = PGconn.new(@hostname, @port, pgoptions, pgtty, @dbname, @user, @password)
|
39
|
+
query = 'SELECT st_origin, st_received, st_lag_num_events, round(extract(epoch from st_lag_time)) from "_' + @cluster + '".sl_status'
|
40
|
+
|
41
|
+
res = con.exec(query)
|
42
|
+
unless res
|
43
|
+
print "POSTGRES_REPLICATION_LAG CRITICAL: Cannot prepare $DBI::errstr\n";
|
44
|
+
exit 2
|
45
|
+
end
|
46
|
+
|
47
|
+
res.each do |r|
|
48
|
+
|
49
|
+
node = r["st_received"]
|
50
|
+
master = r["st_origin"]
|
51
|
+
lag = r["st_lag_num_events"]
|
52
|
+
round = r["round"]
|
53
|
+
|
54
|
+
@result += "SUBSCRIBER " + node + " ON ORIGIN " + master + " : EVENT LAG=" + lag
|
55
|
+
if (lag.to_i > 0) && (@event < lag.to_i)
|
56
|
+
@result = @result + " (BEHIND " + (lag.to_i - @event).to_s + ") ";
|
57
|
+
@problems += 1
|
58
|
+
end
|
59
|
+
@result = @result + " TIME LAG=" + round + "s";
|
60
|
+
|
61
|
+
if (@lagtime > 0) && (@lagtime < round.to_i)
|
62
|
+
@result = @result + " (BEHIND " + (round.to_i - @lagtime).to_s + "s) ";
|
63
|
+
@problems += 1
|
64
|
+
end
|
65
|
+
@result = @result + " || ";
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
if @problems > 0
|
70
|
+
@result = "POSTGRES_REPLICATION_LAG CRITICAL: " + @result + "\n"
|
71
|
+
print @result
|
72
|
+
exit 2
|
73
|
+
else
|
74
|
+
@result = "POSTGRES_REPLICATION_LAG OK: " + @result + "\n"
|
75
|
+
print @result
|
76
|
+
exit 0
|
77
|
+
end
|
78
|
+
|
79
|
+
print $problems;
|
80
|
+
con.close
|
81
|
+
}
|
82
|
+
|
83
|
+
rescue Timeout::Error => ex
|
84
|
+
print "POSTGRES_REPLICATION_LAG TIMEOUT: #{ex.message}";
|
85
|
+
exit 3
|
86
|
+
rescue => ex
|
87
|
+
print "POSTGRES_REPLICATION_LAG UNKNOWN: #{ex.message}";
|
88
|
+
exit 3
|
89
|
+
end
|
90
|
+
|
91
|
+
exit;
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: check_slony
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- kakikubo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-09 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hoe
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 8
|
33
|
+
- 0
|
34
|
+
version: 2.8.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: This is an check plugin for Nagios.
|
38
|
+
email:
|
39
|
+
- kakikubo@gmail.com
|
40
|
+
executables:
|
41
|
+
- check_slony
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
files:
|
49
|
+
- .autotest
|
50
|
+
- History.txt
|
51
|
+
- Manifest.txt
|
52
|
+
- README.txt
|
53
|
+
- Rakefile
|
54
|
+
- bin/check_slony
|
55
|
+
- lib/check_slony.rb
|
56
|
+
- test/test_check_slony.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://rubyforge.org/projects/checkslony/
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.txt
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: check_slony
|
88
|
+
rubygems_version: 1.4.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: This is an check plugin for Nagios.
|
92
|
+
test_files:
|
93
|
+
- test/test_check_slony.rb
|