class MonitorTypeProcess

A class for checking if a Process is running in Unix based systems

Public Instance Methods

derived_value() click to toggle source
# File lib/monitor_type/process.rb, line 53
def derived_value
  `ps aux | grep #{@process_name}`.length
end
extract_params() click to toggle source

Extract parameters

@param [String] :process_name THe name of the process to monitor

# File lib/monitor_type/process.rb, line 11
def extract_params
  if @params[:process_name].nil?
    string = "*** Process Name parameter missing, process_name\n" \
             '*** :process_name => <name of the process to ' \
             'be monitored>'
    fail MonitorTypeParameterMissingError, string
  end
  @process_name = @params[:process_name]

  log "#{@process_name}", "result: #{(@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0}"

  unless (@process_name =~ /^(.*\[{1}.+\]{1}.*)$|^(\w+)$/) == 0
    string = '*** Process Name parameter doest not match the required ' \
             "pattern, #{@process_name}\n" \
             "*** :process_name => <plain string, or a string " \
             'with one or more characters enclosed in square brackets, ' \
             "i.e. 'foo', '[f]oo' or '[foo]'>"
    fail InvalidProcessNameError, 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
sanitise() click to toggle source
# File lib/monitor_type/process.rb, line 47
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() click to toggle source
# File lib/monitor_type/process.rb, line 40
def setup
  sanitise
rescue MonitorTypeExceptionHandled => e
  puts e.message
  abort
end