lib/mutx/tasks/task.rb in mutx-0.1.23 vs lib/mutx/tasks/task.rb in mutx-0.1.24
- old
+ new
@@ -27,12 +27,18 @@
:cron_time,
:last_exec_time,
:application,
:mail,
:subject,
- :notifications
+ :notifications,
+ :value_for_regex,
+ :regex,
+ :notify_on,
+ :blocked
+ REGEX_VALID_VALUES = ["failed","passed","none","warning"]
+ NOTIFY_VALID_VALUES = ["any","warning","passed","failed"]
def self.valid_types
["task","test"]
end
@@ -57,12 +63,16 @@
@cronneable = task_data["cronneable"]
@cron_time = task_data["cron_time"]
@mail = task_data["mail"]
@subject = task_data["subject"] || ""
@notifications = task_data["notifications"]
+ @blocked = task_data["blocked"]
@last_exec_time = task_data["last_exec_time"]
@application = task_data["application"] || "command line"
+ @regex = task_data["regex"]
+ @value_for_regex = task_data["value_for_regex"]
+ @notify_on = task_data["notify_on"] || "any"
else
Mutx::Support::Log.error "Creting task object. Argument is not a hash" if Mutx::Support::Log
raise "Task data not defined correctly. Expecting info about task"
end
save!
@@ -107,12 +117,16 @@
"cronneable" => data["cronneable"],
"cron_time" => data["cron_time"],
"mail" => data["mail"],
"subject" => data["subject"],
"notifications" => data["notifications"],
+ "blocked" => data["blocked"],
"last_exec_time" => Time.now.utc,
- "application" => data["application"]
+ "application" => data["application"],
+ "regex" => data["regex"],
+ "value_for_regex" => data["value_for_regex"],
+ "notify_on" => data["notify_on"]
}
self.new(task_data)
end
def self.validate_and_create(data)
@@ -132,10 +146,12 @@
if data["action"] == "edit"
errors << self.validate_name_with_id(data["name"],data["_id"])
else
errors << self.validate_name(data["name"])
end
+ errors << self.validate_value_for_regex(data['value_for_regex'], data['regex'], data['cucumber'])
+ errors << self.validate_notifications(data['notify_on'], data['notifications'], data['mail'])
errors << self.validate_max_execs(data["max_execs"])
errors << self.validate_type(data["type"])
errors << self.validate_risk_command(data["command"])
errors.compact
end
@@ -188,13 +204,29 @@
end
# command must be evaluated for risks
def self.validate_risk_command command
return "Your commands seems to be unsecure" unless Mutx::Support::Risk.secure? command
+ end
+ def self.validate_value_for_regex value_for_regex=nil, regex=nil, cucumber=nil
+ regex = nil if regex == ""
+ unless cucumber
+ if regex
+ return "Must define a result for regex" if value_for_regex.nil?
+ return "Invalid value for regex #{value_for_regex}" unless REGEX_VALID_VALUES.include? value_for_regex
+ end
+ end
end
+ def self.validate_notifications notify_on=nil, notifications=nil, recipients=nil
+ if notifications
+ return "Must define at least one recipient to notify" if recipients.nil?
+ return "Invalid value for notify on #{notify_on}" if !NOTIFY_VALID_VALUES.include? notify_on
+ end
+ end
+
def task_data_for task_name
Mutx::Database::MongoConnector.task_data_for(task_name)
end
# Returns the structure of a task data
@@ -214,12 +246,16 @@
"platform" => platform,
"cronneable" => cronneable,
"mail" => mail,
"subject" => subject,
"notifications" => notifications,
+ "blocked" => blocked,
"cron_time" => cron_time,
"last_exec_time" => last_exec_time,
- "application" => application
+ "application" => application,
+ "regex" => regex,
+ "value_for_regex" => value_for_regex,
+ "notify_on" => notify_on
}
end
def has_custom_params?
!@custom_params.empty?
\ No newline at end of file