Module: Arborist::CLI::Summary
- Extended by:
- Subcommand
- Defined in:
- lib/arborist/command/summary.rb
Overview
Command to fetch down/acked/disabled nodes for quick display.
Constant Summary collapse
- BANNER =
[ ' _ _ _', ' __ _ _ _| |__ ___ _ _(_)__| |', '/ _` | \'_| \'_ \\/ _ \\ \'_| (_-< _|', '\\__,_|_| |_.__/\\___/_| |_/__/\\__| %s, %s nodes', ]
Class Method Summary collapse
-
.format_acked(nodes, sort_key) ⇒ Object
Prepare an array of acked/disabled nodes.
-
.format_down(nodes, sort_key) ⇒ Object
Prepare an array of down nodes.
-
.format_warn(nodes, sort_key) ⇒ Object
Prepare an array of nodes in a warning state.
-
.get_status(nodes, status) ⇒ Object
Since we fetch all nodes instead of doing separate API searches, quickly return nodes of a given
status. -
.output_problems(disabled, acked, down, quieted, warning, sort) ⇒ Object
Output all problems.
Methods included from Subcommand
display_table, error_string, exit_now!, extended, headline_string, help_now!, highlight_string, hl, prompt, skips_around, skips_post, skips_pre, success_string, unless_dryrun, visible_chars
Class Method Details
.format_acked(nodes, sort_key) ⇒ Object
Prepare an array of acked/disabled nodes.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/arborist/command/summary.rb', line 123 def format_acked( nodes, sort_key ) header = [ highlight_string( 'identifier' ), highlight_string( 'type' ), highlight_string( 'when' ), highlight_string( 'who' ), highlight_string( 'message' ) ] rows = nodes.sort_by{|n| n[sort_key] }.each_with_object([]) do |node, acc| acc << [ hl.disabled( node['identifier'] ), node[ 'type' ], Time.parse( node[ 'status_changed' ] ).as_delta, node[ 'ack' ][ 'sender' ], node[ 'ack' ][ 'message' ] ] end return header, rows end |
.format_down(nodes, sort_key) ⇒ Object
Prepare an array of down nodes.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/arborist/command/summary.rb', line 146 def format_down( nodes, sort_key ) return nodes.sort_by{|n| n[sort_key] }.each_with_object([]) do |node, acc| errors = node[ 'errors' ].map{|err| "%s: %s" % [ err.first, err.last ]} acc << [ hl.down( node['identifier'] ), node[ 'type' ], Time.parse( node[ 'status_changed' ] ).as_delta, errors.join( "\n" ) ] end end |
.format_warn(nodes, sort_key) ⇒ Object
Prepare an array of nodes in a warning state.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/arborist/command/summary.rb', line 160 def format_warn( nodes, sort_key ) return nodes.sort_by{|n| n[sort_key] }.each_with_object([]) do |node, acc| warnings = node[ 'warnings' ].map{|err| "%s: %s" % [ err.first, err.last ]} acc << [ hl.warn( node['identifier'] ), node[ 'type' ], Time.parse( node[ 'status_changed' ] ).as_delta, warnings.join( "\n" ) ] end end |
.get_status(nodes, status) ⇒ Object
Since we fetch all nodes instead of doing separate API searches, quickly return nodes of a given status.
73 74 75 |
# File 'lib/arborist/command/summary.rb', line 73 def get_status( nodes, status ) return nodes.select{|n| n['status'] == status} end |
.output_problems(disabled, acked, down, quieted, warning, sort) ⇒ Object
Output all problems.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/arborist/command/summary.rb', line 80 def output_problems( disabled, acked, down, quieted, warning, sort ) unless disabled.size.zero? prompt.say hl.headline( "Disabled Nodes" ) display_table( *format_acked(disabled, sort) ) puts end unless acked.size.zero? prompt.say hl.headline( "Acknowledged Outages" ) display_table( *format_acked(acked, sort) ) puts end unless warning.size.zero? prompt.say hl.headline( "Warnings" ) header = [ highlight_string( 'identifier' ), highlight_string( 'type' ), highlight_string( 'when' ), highlight_string( 'warnings' ) ] display_table( header, format_warn(warning, sort) ) puts end unless down.size.zero? prompt.say hl.headline( "Current Outages" ) header = [ highlight_string( 'identifier' ), highlight_string( 'type' ), highlight_string( 'when' ), highlight_string( 'errors' ) ] display_table( header, format_down(down, sort) ) prompt.say "%d nodes have been %s as a result of the above problems." % [ quieted.size, hl.quieted( 'quieted' ) ] puts end end |