class SystemdMon::StateChange
Attributes
changed[RW]
original[RW]
states[RW]
Public Class Methods
new(original_state = nil)
click to toggle source
# File lib/systemd_mon/state_change.rb, line 7 def initialize(original_state = nil) self.states = [] states << original_state if original_state end
Public Instance Methods
<<(state)
click to toggle source
# File lib/systemd_mon/state_change.rb, line 20 def <<(state) self.states << state @diff = nil end
auto_restart?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 51 def auto_restart? first.ok? && last.ok? && changes.any? { |s| s.sub == "auto-restart" } end
changes()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 31 def changes states[1..-1] end
diff()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 89 def diff @diff ||= zipped.reject { |states| match = states.first.value states.all? { |s| s.value == match } } end
each() { |state| ... }
click to toggle source
# File lib/systemd_mon/state_change.rb, line 25 def each states.each do |state| yield state end end
fail?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 43 def fail? last.fail? end
important?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 81 def important? if length == 1 first.fail? else diff.map(&:last).any?(&:important?) end end
last()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 12 def last states.last end
length()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 16 def length states.length end
ok?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 39 def ok? last.ok? end
recovery?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 35 def recovery? first.fail? && last.ok? end
reload?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 55 def reload? first.ok? && last.ok? && changes.any? { |s| s.active == "reloading" } end
restart?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 47 def restart? first.ok? && last.ok? && changes.any? { |s| s.active == "deactivating" } end
status_text()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 63 def status_text if recovery? "recovered" elsif auto_restart? "automatically restarted" elsif restart? "restarted" elsif reload? "reloaded" elsif still_fail? "still failed" elsif fail? "failed" else "started" end end
still_fail?()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 59 def still_fail? length > 1 && first.fail? && last.fail? end
to_s()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 104 def to_s diff.inject("") { |s, (*states)| first = states.shift s << "#{first.name} state changed from #{first.value} to " s << states.map(&:value).join(" then ") s << "\n" s } end
zipped()
click to toggle source
# File lib/systemd_mon/state_change.rb, line 96 def zipped if length == 1 first.all_states else first.all_states.zip(*changes.map(&:all_states)) end end