dynect-utils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/bin/check_dynect_gslb_region +50 -0
- data/bin/dynect_gslb_manage +84 -0
- data/dynect-utils.gemspec +25 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dynect-utils (0.0.1)
|
5
|
+
dynect_rest
|
6
|
+
trollop
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
dynect_rest (0.4.0)
|
12
|
+
json
|
13
|
+
json
|
14
|
+
rest-client
|
15
|
+
rest-client
|
16
|
+
json (1.6.5)
|
17
|
+
mime-types (1.17.2)
|
18
|
+
rest-client (1.6.7)
|
19
|
+
mime-types (>= 1.16)
|
20
|
+
trollop (1.16.2)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
dynect-utils!
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# dynect-utils
|
2
|
+
|
3
|
+
This is a set of utilities that use the
|
4
|
+
[DynECT](http://dyn.com/dns/dynect-managed-dns/) REST API to help
|
5
|
+
monitor and manage the service.
|
6
|
+
|
7
|
+
## Nagios plugin: check_dynect_gslb_region
|
8
|
+
|
9
|
+
Checks the health-check status of the addresses in a GSLB region's pool.
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
|
13
|
+
Options:
|
14
|
+
--customer, -c <s>: Dynect customer name
|
15
|
+
--user, -u <s>: Dynect user name
|
16
|
+
--pass, -p <s>: Dynect password
|
17
|
+
--zone, -z <s>: Zone name
|
18
|
+
--record, -r <s>: GSLB record name
|
19
|
+
--region, -R <s>: GSLB region (default: global)
|
20
|
+
--help, -h: Show this message
|
21
|
+
|
22
|
+
Example output:
|
23
|
+
|
24
|
+
$ check_dynect_gslb_region -c Customer -u user -p pass123 -z example.org -r foo.example.org
|
25
|
+
OK: all GSLB addresses are healthy
|
26
|
+
|
27
|
+
$ check_dynect_gslb_region -c Customer -u user -p pass123 -z example.org -r bar.example.org
|
28
|
+
CRITICAL: GSLB addresses unhealthy: 1.2.3.4=down
|
29
|
+
|
30
|
+
## Utility: dynect_gslb_manage
|
31
|
+
|
32
|
+
Drains/undrains a specific address in a GSLB region's pool.
|
33
|
+
|
34
|
+
Usage:
|
35
|
+
|
36
|
+
Usage: dynect_gslb_manage [options] command [command opts]
|
37
|
+
|
38
|
+
Possible sub-commands:
|
39
|
+
|
40
|
+
list
|
41
|
+
List all GSLB IPs
|
42
|
+
|
43
|
+
drain <address|label>
|
44
|
+
Set the serving mode to "no" for a GSLB address, identified by IP
|
45
|
+
address or label.
|
46
|
+
|
47
|
+
undrain <address|label>
|
48
|
+
Set the serving mode to "obey" for a GSLB address, identified by IP
|
49
|
+
address or label.
|
50
|
+
|
51
|
+
Main options:
|
52
|
+
|
53
|
+
--customer, -c <s>: Dynect customer name
|
54
|
+
--user, -u <s>: Dynect user name
|
55
|
+
--pass, -p <s>: Dynect password
|
56
|
+
--zone, -z <s>: Zone name
|
57
|
+
--record, -r <s>: GSLB record name
|
58
|
+
--region, -R <s>: GSLB region (default: global)
|
59
|
+
--help, -h: Show this message
|
60
|
+
|
61
|
+
Example output:
|
62
|
+
|
63
|
+
$ dynect_gslb_manage -c Customer -u user -p pass123 -z example.org -r foo.example.org list
|
64
|
+
foo-backend-1 | 1.2.3.4 | status=up | weight=1 | serve_mode=obey
|
65
|
+
foo-backend-2 | 1.2.3.5 | status=up | weight=1 | serve_mode=obey
|
66
|
+
|
67
|
+
$ dynect_gslb_manage -c Customer -u user -p pass123 -z example.org -r foo.example.org drain foo-backend-1
|
68
|
+
1.2.3.4 serve_mode changed from obey to no
|
69
|
+
|
70
|
+
$ dynect_gslb_manage -c Customer -u user -p pass123 -z example.org -r foo.example.org undrain foo-backend-1
|
71
|
+
1.2.3.4 serve_mode changed from no to obey
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Nagios plugin to monitor the status of IP addresses in a GSLB region.
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler/setup"
|
6
|
+
|
7
|
+
require "dynect_rest"
|
8
|
+
require "trollop"
|
9
|
+
|
10
|
+
progname = File.basename($0)
|
11
|
+
|
12
|
+
opts = Trollop::options do
|
13
|
+
opt :customer, "Dynect customer name", :short => "-c", :type => :string,
|
14
|
+
:required => true
|
15
|
+
opt :user, "Dynect user name", :short => "-u", :type => :string,
|
16
|
+
:required => true
|
17
|
+
opt :pass, "Dynect password", :short => "-p", :type => :string,
|
18
|
+
:required => true
|
19
|
+
opt :zone, "Zone name", :short => "-z", :type => :string,
|
20
|
+
:required => true
|
21
|
+
opt :record, "GSLB record name", :short => "-r", :type => :string,
|
22
|
+
:required => true
|
23
|
+
opt :region, "GSLB region", :short => "-R", :type => :string,
|
24
|
+
:default => "global"
|
25
|
+
end
|
26
|
+
|
27
|
+
dyn = DynectRest.new(opts[:customer], opts[:user], opts[:pass], opts[:zone])
|
28
|
+
gslb = dyn.get("GSLB/#{opts[:zone]}/#{opts[:record]}")
|
29
|
+
|
30
|
+
region = gslb["region"].select { |r| r["region_code"] == opts[:region] }.first
|
31
|
+
if region.nil?
|
32
|
+
puts "UNKNOWN: can't find region #{region}"
|
33
|
+
exit 3
|
34
|
+
end
|
35
|
+
|
36
|
+
down = {}
|
37
|
+
region["pool"].each do |address|
|
38
|
+
if address["status"] != "up"
|
39
|
+
down[address["address"]] = address["status"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if down.length > 0
|
44
|
+
msg = down.collect { |addr, status| "#{addr}=#{status}" }.join("; ")
|
45
|
+
puts "CRITICAL: GSLB addresses unhealthy: #{msg}"
|
46
|
+
exit 2
|
47
|
+
end
|
48
|
+
|
49
|
+
puts "OK: all GSLB addresses are healthy"
|
50
|
+
exit 0
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Nagios plugin to monitor the status of IP addresses in a GSLB region.
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler/setup"
|
6
|
+
|
7
|
+
require "dynect_rest"
|
8
|
+
require "trollop"
|
9
|
+
|
10
|
+
progname = File.basename($0)
|
11
|
+
|
12
|
+
opts = Trollop::options do
|
13
|
+
banner <<-EOF
|
14
|
+
Usage: #{progname} [options] command [command opts]
|
15
|
+
|
16
|
+
Possible sub-commands:
|
17
|
+
|
18
|
+
list
|
19
|
+
List all GSLB IPs
|
20
|
+
|
21
|
+
drain <address|label>
|
22
|
+
Set the serving mode to "no" for a GSLB address, identified by IP
|
23
|
+
address or label.
|
24
|
+
|
25
|
+
Main options:
|
26
|
+
EOF
|
27
|
+
banner ""
|
28
|
+
|
29
|
+
opt :customer, "Dynect customer name", :short => "-c", :type => :string,
|
30
|
+
:required => true
|
31
|
+
opt :user, "Dynect user name", :short => "-u", :type => :string,
|
32
|
+
:required => true
|
33
|
+
opt :pass, "Dynect password", :short => "-p", :type => :string,
|
34
|
+
:required => true
|
35
|
+
opt :zone, "Zone name", :short => "-z", :type => :string,
|
36
|
+
:required => true
|
37
|
+
opt :record, "GSLB record name", :short => "-r", :type => :string,
|
38
|
+
:required => true
|
39
|
+
opt :region, "GSLB region", :short => "-R", :type => :string,
|
40
|
+
:default => "global"
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
dyn = DynectRest.new(opts[:customer], opts[:user], opts[:pass], opts[:zone])
|
45
|
+
|
46
|
+
command = ARGV.shift
|
47
|
+
|
48
|
+
pool = dyn.get("GSLBRegionPoolEntry/#{opts[:zone]}/#{opts[:record]}/#{opts[:region]}/").collect { |p| p.sub("/REST/", "") }
|
49
|
+
|
50
|
+
# Takes an IP or label.
|
51
|
+
def find_address(dyn, pool, match)
|
52
|
+
pool.each do |path|
|
53
|
+
entry = dyn.get(path)
|
54
|
+
if entry["label"] == match or entry["address"] == match
|
55
|
+
return path, entry
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
raise "can't find GSLB entry with address or label matching #{match}"
|
60
|
+
end
|
61
|
+
|
62
|
+
case command
|
63
|
+
when "list"
|
64
|
+
pool.each do |path|
|
65
|
+
entry = dyn.get(path)
|
66
|
+
puts "#{entry["label"]} | #{entry["address"]} | " \
|
67
|
+
"status=#{entry["status"]} | weight=#{entry["weight"]} | " \
|
68
|
+
"serve_mode=#{entry["serve_mode"]}"
|
69
|
+
end
|
70
|
+
when "drain", "undrain"
|
71
|
+
match = ARGV.shift
|
72
|
+
if !match
|
73
|
+
Trollop::die "must specify an address to drain"
|
74
|
+
end
|
75
|
+
path, entry = find_address(dyn, pool, match)
|
76
|
+
serve_mode = (command == "drain") ? "no" : "obey"
|
77
|
+
res = dyn.put(path, {"serve_mode" => serve_mode})
|
78
|
+
puts "#{entry["address"]} serve_mode changed from #{entry["serve_mode"]} " \
|
79
|
+
"to #{res["serve_mode"]}"
|
80
|
+
when nil
|
81
|
+
Trollop::die "must specify a command"
|
82
|
+
else
|
83
|
+
Trollop::die "invalid command #{command}"
|
84
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "dynect-utils"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Pete Fritchman"]
|
8
|
+
s.email = ["petef@databits.net"]
|
9
|
+
s.homepage = "https://github.com/fetep/dynect-utils"
|
10
|
+
s.summary = %q{Utilities to interact with the DynECT API}
|
11
|
+
s.description = %q{
|
12
|
+
Utilities included: nagios plugin to check GSLB status, tool to manipulate
|
13
|
+
the serving mode of GSLB addresses
|
14
|
+
}
|
15
|
+
|
16
|
+
s.rubyforge_project = "dynect-utils"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency "dynect_rest"
|
24
|
+
s.add_runtime_dependency "trollop"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dynect-utils
|
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
|
+
- Pete Fritchman
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-07 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: dynect_rest
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: trollop
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: |
|
49
|
+
|
50
|
+
Utilities included: nagios plugin to check GSLB status, tool to manipulate
|
51
|
+
the serving mode of GSLB addresses
|
52
|
+
|
53
|
+
email:
|
54
|
+
- petef@databits.net
|
55
|
+
executables:
|
56
|
+
- check_dynect_gslb_region
|
57
|
+
- dynect_gslb_manage
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/check_dynect_gslb_region
|
69
|
+
- bin/dynect_gslb_manage
|
70
|
+
- dynect-utils.gemspec
|
71
|
+
homepage: https://github.com/fetep/dynect-utils
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: dynect-utils
|
100
|
+
rubygems_version: 1.8.10
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Utilities to interact with the DynECT API
|
104
|
+
test_files: []
|
105
|
+
|