Skip to content

Commit

Permalink
add dynect_gslb_manage
Browse files Browse the repository at this point in the history
  • Loading branch information
fetep committed Mar 6, 2012
1 parent 27d13ff commit a18066d
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Expand Up @@ -6,6 +6,8 @@ monitor and manage the service.

## Nagios plugin: check_dynect_gslb_region

Checks the health-check status of the addresses in a GSLB region's pool.

Usage:

Options:
Expand All @@ -24,3 +26,46 @@ Example output:

$ check_dynect_gslb_region -c Customer -u user -p pass123 -z example.org -r bar.example.org
CRITICAL: GSLB addresses unhealthy: 1.2.3.4=down

## Utility: dynect_gslb_manage

Drains/undrains a specific address in a GSLB region's pool.

Usage:

Usage: dynect_gslb_manage [options] command [command opts]

Possible sub-commands:

list
List all GSLB IPs

drain <address|label>
Set the serving mode to "no" for a GSLB address, identified by IP
address or label.

undrain <address|label>
Set the serving mode to "obey" for a GSLB address, identified by IP
address or label.

Main options:

--customer, -c <s>: Dynect customer name
--user, -u <s>: Dynect user name
--pass, -p <s>: Dynect password
--zone, -z <s>: Zone name
--record, -r <s>: GSLB record name
--region, -R <s>: GSLB region (default: global)
--help, -h: Show this message

Example output:

$ dynect_gslb_manage -c Customer -u user -p pass123 -z example.org -r foo.example.org list
foo-backend-1 | 1.2.3.4 | status=up | weight=1 | serve_mode=obey
foo-backend-2 | 1.2.3.5 | status=up | weight=1 | serve_mode=obey

$ dynect_gslb_manage -c Customer -u user -p pass123 -z example.org -r foo.example.org drain foo-backend-1
1.2.3.4 serve_mode changed from obey to no

$ dynect_gslb_manage -c Customer -u user -p pass123 -z example.org -r foo.example.org undrain foo-backend-1
1.2.3.4 serve_mode changed from no to obey
84 changes: 84 additions & 0 deletions bin/dynect_gslb_manage
@@ -0,0 +1,84 @@
#!/usr/bin/env ruby
# Nagios plugin to monitor the status of IP addresses in a GSLB region.

require "rubygems"
require "bundler/setup"

require "dynect_rest"
require "trollop"

progname = File.basename($0)

opts = Trollop::options do
banner <<-EOF
Usage: #{progname} [options] command [command opts]
Possible sub-commands:
list
List all GSLB IPs
drain <address|label>
Set the serving mode to "no" for a GSLB address, identified by IP
address or label.
Main options:
EOF
banner ""

opt :customer, "Dynect customer name", :short => "-c", :type => :string,
:required => true
opt :user, "Dynect user name", :short => "-u", :type => :string,
:required => true
opt :pass, "Dynect password", :short => "-p", :type => :string,
:required => true
opt :zone, "Zone name", :short => "-z", :type => :string,
:required => true
opt :record, "GSLB record name", :short => "-r", :type => :string,
:required => true
opt :region, "GSLB region", :short => "-R", :type => :string,
:default => "global"

end

dyn = DynectRest.new(opts[:customer], opts[:user], opts[:pass], opts[:zone])

command = ARGV.shift

pool = dyn.get("GSLBRegionPoolEntry/#{opts[:zone]}/#{opts[:record]}/#{opts[:region]}/").collect { |p| p.sub("/REST/", "") }

# Takes an IP or label.
def find_address(dyn, pool, match)
pool.each do |path|
entry = dyn.get(path)
if entry["label"] == match or entry["address"] == match
return path, entry
end
end

raise "can't find GSLB entry with address or label matching #{match}"
end

case command
when "list"
pool.each do |path|
entry = dyn.get(path)
puts "#{entry["label"]} | #{entry["address"]} | " \
"status=#{entry["status"]} | weight=#{entry["weight"]} | " \
"serve_mode=#{entry["serve_mode"]}"
end
when "drain", "undrain"
match = ARGV.shift
if !match
Trollop::die "must specify an address to drain"
end
path, entry = find_address(dyn, pool, match)
serve_mode = (command == "drain") ? "no" : "obey"
res = dyn.put(path, {"serve_mode" => serve_mode})
puts "#{entry["address"]} serve_mode changed from #{entry["serve_mode"]} " \
"to #{res["serve_mode"]}"
when nil
Trollop::die "must specify a command"
else
Trollop::die "invalid command #{command}"
end

0 comments on commit a18066d

Please sign in to comment.