Class: MonitorType_Process
- Inherits:
-
MonitorType_Threshold
- Object
- MonitorType
- MonitorType_Threshold
- MonitorType_Process
- Defined in:
- lib/MonitorType/Process.rb
Overview
A class for checking if a Process is running in Unix based systems
Instance Method Summary collapse
-
#extractParams ⇒ Object
Extract parameters.
- #getValue ⇒ Object
- #sanitise ⇒ Object
- #setup ⇒ Object
Methods inherited from MonitorType_Threshold
Methods inherited from MonitorType
#alert, #initialize, #process, #run, #teardown
Constructor Details
This class inherits a constructor from MonitorType_Threshold
Instance Method Details
#extractParams ⇒ Object
Extract parameters
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/MonitorType/Process.rb', line 12 def extractParams if @params[:process_name].nil? then string = "*** Process Name parameter missing, process_name\n" string = "#{string}*** :process_name => <name of the process to be monitored>" raise MonitorTypeParameterMissingError.new(string) end @process_name = @params[:process_name] log "#{@process_name}", "result: #{(@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0}" unless (@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0 then string = "*** Process Name parameter doest not match the required pattern, #{@process_name}\n" string = "#{string}*** :process_name => <plain string, or a string with one or more characters enclosed in square brackets, i.e. 'foo', '[f]oo' or '[foo]'>" raise InvalidProcessNameError.new(string) end log "*** Min value will be ignored, setting to 1" unless (params[:min].nil? || params[:min] == 0) @min = 1 log "*** Max value will be ignored, setting to nil" unless params[:max].nil? @max = nil @context_sentence = "Checking that process is running, #{@process_name}" end |
#getValue ⇒ Object
49 50 51 |
# File 'lib/MonitorType/Process.rb', line 49 def getValue return `ps aux | grep #{@process_name}`.length end |
#sanitise ⇒ Object
44 45 46 47 |
# File 'lib/MonitorType/Process.rb', line 44 def sanitise #Ensure that the process name contains a single character surrounded by square brackets @process_name = @process_name.insert(0,'[').insert(2,']') unless @process_name =~ /^.*\[.+\].*/ end |
#setup ⇒ Object
37 38 39 40 41 42 |
# File 'lib/MonitorType/Process.rb', line 37 def setup self.sanitise rescue MonitorTypeExceptionHandled => e puts e. abort end |