Permalink
Browse files

MCollective "locate" wrapper

  • Loading branch information...
1 parent 31763b8 commit 751e65e8b16982882b099a674c6f7439cd4334a7 @deanwilson committed Apr 5, 2011
Showing with 71 additions and 0 deletions.
  1. +39 −0 locator/locator.ddl
  2. +32 −0 locator/locator.rb
View
@@ -0,0 +1,39 @@
+metadata :name => "File Locator",
+ :description => "Agent that 'locates' all instances of a filename",
+ :author => "Dean Wilson",
+ :license => "GPLv2",
+ :version => "0.1",
+ :url => "http://www.unixdaemon.net/mcollective-plugins/",
+ :timeout => 20
+
+action "locator", :description => "Locate filename" do
+ display :always
+
+ input :filename,
+ :prompt => "Filename",
+ :description => "The file to locate",
+ :type => :string,
+ :validation => '.',
+ :optional => false
+
+ output :occurances,
+ :description => "Paths matching filename",
+ :display_as => "Paths matching filename"
+end
+
+
+action "count_located", :description => "Count of filenames located" do
+ display :always
+
+ input :filename,
+ :prompt => "Filename",
+ :description => "The file to locate",
+ :type => :string,
+ :validation => '.',
+ :optional => false
+
+ output :count,
+ :description => "Number of paths matching filename",
+ :display_as => "Located"
+
+end
View
@@ -0,0 +1,32 @@
+module MCollective
+ module Agent
+ class Locator<RPC::Agent
+
+ metadata :name => "File Locator",
+ :description => "Agent that 'locates' all instances of a filename",
+ :author => "Dean Wilson",
+ :license => "GPLv2",
+ :version => "0.1",
+ :url => "http://www.unixdaemon.net/mcollective-plugins/",
+ :timeout => 20
+
+
+ action "locator" do
+ validate :filename, String
+
+ matching = `locate --regex #{request[:filename]}`.to_a.map(&:chomp)
+
+ reply[:occurances] = matching
+
+ end
+
+ action "count_located" do
+ validate :filename, String
+
+ count = `locate --regex #{request[:filename]}`.to_a.map(&:chomp).length
+
+ reply[:count] = count
+ end
+ end
+ end
+end

0 comments on commit 751e65e

Please sign in to comment.