Class: ServerMonitor::Mailq

Inherits:
Object
  • Object
show all
Defined in:
lib/servermonitor/mailq.rb

Class Method Summary collapse

Class Method Details

.configObject



17
18
19
# File 'lib/servermonitor/mailq.rb', line 17

def self.config
  @config ||= MailqConfiguration.new
end

.configure {|config| ... } ⇒ Object

Yields:



21
22
23
# File 'lib/servermonitor/mailq.rb', line 21

def self.configure
  yield(config)
end

.runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/servermonitor/mailq.rb', line 25

def self.run

  queue = `#{self.config.path} | #{self.config.grep} -v 'Mail queue is empty' | #{self.config.grep} -c '^[A-Z0-9]'`

  # Set the no_msg (number of messages) from queue variable if no_msg does not = 0
  queue == 0 ? no_msg = 0 : no_msg = queue.to_i

  # Compare and return 0 for success and 1 for error
  if no_msg >= self.config.critical.to_i
    puts "#{no_msg} messages in the postfix mail queue"
    puts exit 1 unless self.config.exit_codes == false
  elsif no_msg >= self.config.warning.to_i
    puts "#{no_msg} messages in the postfix mail queue"
    puts exit 1 unless self.config.exit_codes == false
  else
    puts "#{no_msg} messages in the postfix mail queue"
    puts exit 0 unless self.config.exit_codes == false
  end
end