Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a hacky data plugin

  • Loading branch information...
commit 369a272423eee31e601fdcc6f5cf3c277cab02c6 1 parent b33deb2
@ripienaar authored
View
22 agent/eximng/data/domain_mailq_data.ddl
@@ -0,0 +1,22 @@
+metadata :name => "domain_mailq_data",
+ :description => "Checks the mailq for mail to a certain domain",
+ :author => "R.I.Pienaar <rip@devco.net>",
+ :license => "ASL 2.0",
+ :version => "0.1",
+ :url => "http:/devco.net/",
+ :timeout => 1
+
+dataquery :description => "Counts the mail destined for a certain domain" do
+ input :query,
+ :prompt => "Domain",
+ :description => "Domain to check the mail queue for",
+ :type => :string,
+ :validation => :shellsafe,
+ :optional => false,
+ :maxlength => 50
+
+ output :size,
+ :description => "Amount of mail matching the domain in the spool",
+ :display_as => "Size",
+ :default => 0
+end
View
60 agent/eximng/data/domain_mailq_data.rb
@@ -0,0 +1,60 @@
+module MCollective
+ module Data
+ class Domain_mailq_data<Base
+ query do |domain|
+ exiqgrep = Config.instance.pluginconf.fetch("exim.paths.exigrep", "/usr/sbin/exiqgrep")
+
+ mailq = runcmd("#{exiqgrep} -r %s" % domain)
+ mailq = parse_mailq_output(mailq)
+
+ result[:size] = mailq.size
+ end
+
+ def runcmd(command)
+ out = ""
+
+ shell = Shell.new(command, :stdout => out)
+
+ shell.runcommand
+
+ raise("Command #{command} failed with status #{status} and error: #{err}") unless shell.status.exitstatus == 0
+
+ return out.chomp
+ end
+
+ def parse_mailq_output(output)
+ messages = []
+ msg = nil
+
+ output << "\n"
+
+ output.each do |line|
+ line.chomp!
+
+ if line =~ /^\s*(.+?)\s+(.+?)\s+(.+-.+-.+) (<.*>)/
+ msg = {}
+ msg[:recipients] = Array.new
+ msg[:frozen] = false
+
+ msg[:age] = $1
+ msg[:size] = $2
+ msg[:msgid] = $3
+ msg[:sender] = $4
+
+ msg[:frozen] = true if line =~ /frozen/
+ elsif line =~ /\s+(\S+?)@(.+)/ and msg
+ msg[:recipients] << "#{$1}@#{$2}"
+ elsif line =~ /^$/ && msg
+ messages << msg
+ msg = nil
+ end
+ end
+
+ messages
+ end
+ end
+ end
+end
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.