Module: SimpleMonitor

Defined in:
lib/simple_monitor.rb,
lib/simple_monitor/version.rb

Constant Summary collapse

LOG_METHODS =
%w[info warn error debug].freeze
VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

A memoized logger.

Returns: a logger that responds to warn, info, debug, and error



83
84
85
# File 'lib/simple_monitor.rb', line 83

def logger
  @logger
end

#only_explicit_loggingObject

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



9
10
11
# File 'lib/simple_monitor.rb', line 9

def only_explicit_logging
  @only_explicit_logging
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/simple_monitor.rb', line 4

def options
  @options
end

Instance Method Details

#alert_log_messageObject

Public: Message to log in case of an alert

Override this in your monitors to inject data

Returns: String



43
44
45
# File 'lib/simple_monitor.rb', line 43

def alert_log_message
  "check generated an alert"
end

#checkObject

Runs the check and sends an alert if needed

Returns false if the check failed, true if passed



21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_monitor.rb', line 21

def check
  if needs_alert?
    warn_alert
    send_alert
    false
  else
    info_passed
    true
  end
end

#info_passedObject



47
48
49
50
51
# File 'lib/simple_monitor.rb', line 47

def info_passed
  unless only_explicit_logging
    info(passed_log_message)
  end
end

#initialize(options = {}) ⇒ Object



13
14
15
16
# File 'lib/simple_monitor.rb', line 13

def initialize(options = {})
  self.only_explicit_logging = options.delete(:only_explicit_logging)
  @options = options
end

#needs_alert?Boolean

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

This should be overridden in your individual monitor classes

Returns a boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/simple_monitor.rb', line 67

def needs_alert?
  false
end

#passed_log_messageObject

Public: Message to log in case of a check passing

Override this in your monitors to inject data

Returns: String



58
59
60
# File 'lib/simple_monitor.rb', line 58

def passed_log_message
  "check passed"
end

#send_alertObject

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



76
77
78
# File 'lib/simple_monitor.rb', line 76

def send_alert
  #no-op
end

#warn_alertObject



32
33
34
35
36
# File 'lib/simple_monitor.rb', line 32

def warn_alert
  unless only_explicit_logging
    warn(alert_log_message)
  end
end