Skip to content

Commit

Permalink
initial commit for dynect-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
fetep committed Mar 6, 2012
0 parents commit 756a2b1
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
*.gem
.bundle
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in dynect-utils.gemspec
gemspec
26 changes: 26 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,26 @@
PATH
remote: .
specs:
dynect-utils (0.0.1)
dynect_rest
trollop

GEM
remote: http://rubygems.org/
specs:
dynect_rest (0.4.0)
json
json
rest-client
rest-client
json (1.6.5)
mime-types (1.17.2)
rest-client (1.6.7)
mime-types (>= 1.16)
trollop (1.16.2)

PLATFORMS
ruby

DEPENDENCIES
dynect-utils!
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require "bundler/gem_tasks"
51 changes: 51 additions & 0 deletions bin/check_dynect_gslb_region
@@ -0,0 +1,51 @@
#!/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 "pp"
require "trollop"

progname = File.basename($0)

opts = Trollop::options do
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])
gslb = dyn.get("GSLB/#{opts[:zone]}/#{opts[:record]}")

region = gslb["region"].select { |r| r["region_code"] == opts[:region] }.first
if region.nil?
puts "UNKNOWN: can't find region #{region}"
exit 3
end

down = {}
region["pool"].each do |address|
if address["status"] != "up"
down[address["address"]] = address["status"]
end
end

if down.length > 0
msg = down.collect { |addr, status| "#{addr}=#{status}" }.join("; ")
puts "CRITICAL: GSLB addresses unhealthy: #{msg}"
exit 2
end

puts "OK: all GSLB addresses are healthy"
exit 0
21 changes: 21 additions & 0 deletions dynect-utils.gemspec
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = "dynect-utils"
s.version = "0.0.1"
s.authors = ["Pete Fritchman"]
s.email = ["petef@databits.net"]
s.homepage = "https://github.com/fetep/dynect-utils"
s.summary = %q{Nagios plugin to monitor a DynECT GSLB region}

s.rubyforge_project = "dynect-utils"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_runtime_dependency "dynect_rest"
s.add_runtime_dependency "trollop"
end

0 comments on commit 756a2b1

Please sign in to comment.