Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Very early prototype of an mcollective resolv client.

  • Loading branch information...
commit 33972bec7d77eb7e7c406d8b94c665ee44b696d6 1 parent 751e65e
Dean Wilson authored
Showing with 69 additions and 0 deletions.
  1. +30 −0 resolver/resolver.ddl
  2. +39 −0 resolver/resolver.rb
View
30 resolver/resolver.ddl
@@ -0,0 +1,30 @@
+metadata :name => "DNS Resolver",
+ :description => "Agent that resolves a given host and record type",
+ :author => "Dean Wilson",
+ :license => "GPLv2",
+ :version => "0.1",
+ :url => "http://www.unixdaemon.net/mcollective-plugins/",
+ :timeout => 20
+
+action "resolve", :description => "Resolve host (and record type)" do
+ display :always
+
+ input :host,
+ :prompt => "Host",
+ :description => "The host to resolve",
+ :type => :string,
+ :validation => '.',
+ :optional => false
+
+ input :type,
+ :prompt => "Record type",
+ :description => "The record type to resolve.",
+ :type => :string,
+ :validation => '.', # TODO
+ :optional => true
+
+ output :records,
+ :description => "Query Results",
+ :display_as => "Query Results"
+
+end
View
39 resolver/resolver.rb
@@ -0,0 +1,39 @@
+module MCollective
+ module Agent
+ class Resolver<RPC::Agent
+
+ require 'resolv'
+
+ metadata :name => "DNS Resolver",
+ :description => "Agent that resolves a given host and record type",
+ :author => "Dean Wilson",
+ :license => "GPLv2",
+ :version => "0.1",
+ :url => "http://www.unixdaemon.net/mcollective-plugins/",
+ :timeout => 20
+
+ action "resolve" do
+ validate :host, String
+ validate :type, String
+
+ type = request[:type] || "A"
+
+ types = { "MX" => "exchange", "A" => "address" }
+ unless types.include? type
+ # return failure
+ end
+
+ resolver = Resolv::DNS.new
+ resource = eval "Resolv::DNS::Resource::IN::#{type}"
+ records = resolver.getresources(request[:host], resource)
+
+ if records.size > 0
+ records.map! { | record | record.send( types[type] ).to_s }
+ reply[:records] = records
+ else
+ reply[:records] = [ "None found" ]
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.