Class: Deadpool::StateSnapshot
- Inherits:
-
Object
- Object
- Deadpool::StateSnapshot
- Defined in:
- lib/deadpool/state_snapshot.rb
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #all_error_messages ⇒ Object
- #full_report ⇒ Object
-
#initialize(state) ⇒ StateSnapshot
constructor
A new instance of StateSnapshot.
- #nagios_report ⇒ Object
- #overall_status ⇒ Object
- #status_code_to_s(code) ⇒ Object
- #to_s(indent = 0) ⇒ Object
Constructor Details
#initialize(state) ⇒ StateSnapshot
Returns a new instance of StateSnapshot.
8 9 10 11 12 13 14 15 |
# File 'lib/deadpool/state_snapshot.rb', line 8 def initialize(state) @name = state.name @timestamp = state. @status_code = state.status_code @all_messages = state. @error_messages = state. @children = [] end |
Instance Method Details
#add_child(child) ⇒ Object
17 18 19 |
# File 'lib/deadpool/state_snapshot.rb', line 17 def add_child(child) @children << child end |
#all_error_messages ⇒ Object
25 26 27 28 29 |
# File 'lib/deadpool/state_snapshot.rb', line 25 def @children.inject(@error_messages) do |arr, child| arr + child. end end |
#full_report ⇒ Object
42 43 44 45 46 47 |
# File 'lib/deadpool/state_snapshot.rb', line 42 def full_report output = "System Status: #{status_code_to_s(overall_status)}\n\n" output += self.to_s return output end |
#nagios_report ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deadpool/state_snapshot.rb', line 31 def nagios_report = '' if overall_status != OK += .join(' | ') end += " last checked #{(Time.now - @timestamp).round} seconds ago." "#{status_code_to_s(overall_status)} - #{}\n" end |
#overall_status ⇒ Object
21 22 23 |
# File 'lib/deadpool/state_snapshot.rb', line 21 def overall_status @children.map { |child| child.overall_status }.push(@status_code).max end |
#status_code_to_s(code) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/deadpool/state_snapshot.rb', line 69 def status_code_to_s(code) case code when OK then 'OK' when WARNING then 'WARNING' when CRITICAL then 'CRITICAL' else 'UNKNOWN' end end |
#to_s(indent = 0) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/deadpool/state_snapshot.rb', line 49 def to_s(indent=0) indent_space = ' ' * indent output = "#{indent_space}#{@name}\n" output += "#{indent_space}#{status_code_to_s(@status_code)} - checked #{(Time.now - @timestamp).round} seconds ago.\n" unless @error_messages.empty? output += "#{indent_space}!!! #{@error_messages.join("\n#{indent_space}!!! ")}\n" end unless @all_messages.empty? output += "#{indent_space}#{@all_messages.join("\n#{indent_space}")}\n" end output += "\n" @children.each do |child| output += child.to_s(indent+1) end return output end |