Permalink
Browse files

Write a Validator plugin matching exim message ids that yields a nice…

…r DDL and error messages
  • Loading branch information...
1 parent 5998f86 commit c8ab75f1bd47b2f6e148e93749d3d14a168b1bb9 @ripienaar committed Jul 20, 2012
@@ -1,8 +1,8 @@
-metadata :name => "Exim NG",
+metadata :name => "eximng",
:description => "SimpleRPC based Exim management agent",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "ASL2",
- :version => "0.1",
+ :version => "0.2",
:url => "http://www.devco.net/",
:timeout => 30
@@ -66,7 +66,7 @@ action "mailq", :description => "Retrieves the server mail queue" do
:display_as => "Frozen"
summarize do
- aggregate average(:size), :format => " Average email size: %d"
+ aggregate sum(:size), :format => " Total Email: %d"
end
end
@@ -145,7 +145,7 @@ action "retrymsg", :description => "Retries a specific message" do
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -161,7 +161,7 @@ action "addrecipient", :description => "Add a recipient to a message" do
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -185,7 +185,7 @@ action "setsender", :description => "Sets the sender email address of a message"
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -209,7 +209,7 @@ action "markdelivered", :description => "Marks a specific message as delivered"
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -249,7 +249,7 @@ action "freeze", :description => "Freeze a specific message" do
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -265,7 +265,7 @@ action "thaw", :description => "Thaw a specific message" do
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -281,7 +281,7 @@ action "giveup", :description => "Gives up on a specific message with a NDR" do
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -297,7 +297,7 @@ action "rm", :description => "Removes a specific message without a NDR" do
:prompt => "Message ID",
:description => "Valid message id currently in the mail queue",
:type => :string,
- :validation => '^\w+-\w+-\w+$',
+ :validation => :exim_msgid,
:optional => false,
:maxlength => 16
@@ -1,14 +1,6 @@
module MCollective
module Agent
class Eximng<RPC::Agent
- metadata :name => "Exim NG",
- :description => "SimpleRPC based Exim management agent",
- :author => "R.I.Pienaar <rip@devco.net>",
- :license => "ASL2",
- :version => "0.1",
- :url => "http://www.devco.net/",
- :timeout => 30
-
def startup_hook
@exim = config.pluginconf["exim.paths.exim"] || "/usr/sbin/exim"
@mailq = config.pluginconf["exim.paths.mailq"] || "/usr/bin/mailq"
@@ -0,0 +1,7 @@
+metadata :name => "Exim Message ID",
+ :description => "Validates that a string is a Exim Message ID",
+ :author => "R.I.Pienaar <rip@devco.net>",
+ :license => "ASL 2.0",
+ :version => "1.0",
+ :url => "http://devco.net/",
+ :timeout => 1
@@ -0,0 +1,16 @@
+module MCollective
+ module Validator
+ class Exim_msgidValidator
+ def initialize(key, validator)
+ @validator = validator
+ @key = key
+ end
+
+ def validate
+ raise DDLValidationError, "#{@key} should be a String" unless @validator.is_a?(String)
+
+ raise(DDLValidationError, "%s should be a valid Exim Message ID" % @key) unless @validator.match(/(?:[+-]\d{4} )?(?:\[\d+\] )?(\w{6}\-\w{6}\-\w{2})/)
+ end
+ end
+ end
+end

0 comments on commit c8ab75f

Please sign in to comment.