Browse files

Simple filecount agent

  • Loading branch information...
1 parent 672c653 commit 31763b8aa377b678db362d78421b05f085936b71 @deanwilson committed Apr 5, 2011
Showing with 54 additions and 0 deletions.
  1. +24 −0 filecount/filecount.ddl
  2. +30 −0 filecount/filecount.rb
View
24 filecount/filecount.ddl
@@ -0,0 +1,24 @@
+metadata :name => "File Counter",
+ :description => "Agent that counts files in <file>",
+ :author => "Dean Wilson",
+ :license => "GPLv2",
+ :version => "0.1",
+ :url => "http://www.unixdaemon.net/mcollective-plugins/",
+ :timeout => 20
+
+action "filecount", :description => "Count the number of files" do
+ display :always
+
+ input :file,
+ :prompt => "File",
+ :description => "Count files in <file>",
+ :type => :string,
+ :validation => '^.+$',
+ :optional => true,
+ :maxlength => 1024
+
+ output :filecount,
+ :description => "Num matching filename",
+ :display_as => "Num matching filename"
+
+end
View
30 filecount/filecount.rb
@@ -0,0 +1,30 @@
+module MCollective
+ module Agent
+ class Filecount<RPC::Agent
+
+ metadata :name => "File Counter",
+ :description => "Agent that counts files in <file>",
+ :author => "Dean Wilson",
+ :license => "GPLv2",
+ :version => "0.1",
+ :url => "http://www.unixdaemon.net/mcollective-plugins/",
+ :timeout => 20
+
+ # Basic filecount action
+ action "filecount" do
+ validate :file, String
+
+ file = request[:file]
+
+ # to make the common usecase easier
+ # TODO - show difference between not exist and no match?
+ if File.directory? file
+ file = "#{file}/*"
+ end
+
+ count = Dir[ file ].length
+ reply[:filecount] = count
+ end
+ end
+ end
+end

0 comments on commit 31763b8

Please sign in to comment.