module SimpleMonitor

Constants

LOG_METHODS
VERSION

Attributes

logger[RW]
only_explicit_logging[RW]

Sets if logging should only occur when you call it, skips implementation logging

options[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/simple_monitor.rb, line 13
def initialize(options = {})
  self.only_explicit_logging = options.delete(:only_explicit_logging)
  @options = options
end

Public Instance Methods

alert_log_message() click to toggle source

Public: Message to log in case of an alert

Override this in your monitors to inject data

Returns: String

# File lib/simple_monitor.rb, line 43
def alert_log_message
  "check generated an alert"
end
check() click to toggle source

Runs the check and sends an alert if needed

Returns false if the check failed, true if passed

# File lib/simple_monitor.rb, line 21
def check
  if needs_alert?
    warn_alert
    send_alert
    false
  else
    info_passed
    true
  end
end
info_passed() click to toggle source
# File lib/simple_monitor.rb, line 47
def info_passed
  unless only_explicit_logging
    info(passed_log_message)
  end
end
needs_alert?() click to toggle source

Public: Conditional method to check if the alert should be sent

This should be overridden in your individual monitor classes

Returns a boolean

# File lib/simple_monitor.rb, line 67
def needs_alert?
  false
end
passed_log_message() click to toggle source

Public: Message to log in case of a check passing

Override this in your monitors to inject data

Returns: String

# File lib/simple_monitor.rb, line 58
def passed_log_message
  "check passed"
end
send_alert() click to toggle source

Public: Send out an alert

This should be overridden in your individual monitor classes, or base monitor class. This might be to send an SMS, email or IRC message

# File lib/simple_monitor.rb, line 76
def send_alert
  #no-op
end
warn_alert() click to toggle source
# File lib/simple_monitor.rb, line 32
def warn_alert
  unless only_explicit_logging
    warn(alert_log_message)
  end
end