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
-
#logger ⇒ Object
A memoized logger.
-
#only_explicit_logging ⇒ Object
Sets if logging should only occur when you call it, skips implementation logging.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#alert_log_message ⇒ Object
Public: Message to log in case of an alert.
-
#check ⇒ Object
Runs the check and sends an alert if needed.
- #info_passed ⇒ Object
- #initialize(options = {}) ⇒ Object
-
#needs_alert? ⇒ Boolean
Public: Conditional method to check if the alert should be sent.
-
#passed_log_message ⇒ Object
Public: Message to log in case of a check passing.
-
#send_alert ⇒ Object
Public: Send out an alert.
- #warn_alert ⇒ Object
Instance Attribute Details
#logger ⇒ Object
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_logging ⇒ Object
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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/simple_monitor.rb', line 4 def @options end |
Instance Method Details
#alert_log_message ⇒ Object
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 "check generated an alert" end |
#check ⇒ Object
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_passed ⇒ Object
47 48 49 50 51 |
# File 'lib/simple_monitor.rb', line 47 def info_passed unless only_explicit_logging info() end end |
#initialize(options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/simple_monitor.rb', line 13 def initialize( = {}) self.only_explicit_logging = .delete(:only_explicit_logging) @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
67 68 69 |
# File 'lib/simple_monitor.rb', line 67 def needs_alert? false end |
#passed_log_message ⇒ Object
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 "check passed" end |
#send_alert ⇒ Object
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_alert ⇒ Object
32 33 34 35 36 |
# File 'lib/simple_monitor.rb', line 32 def warn_alert unless only_explicit_logging warn() end end |