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
|
# File 'lib/zmonitor.rb', line 94
def get_dashboard(format = '')
max_lines = `tput lines`.to_i - 1
cols = `tput cols`.to_i
eventlist = self.get_events() pretty_output = []
pretty_output << ["Last updated: %8s%#{cols-40}sZmonitor Dashboard".cyan_on_blue % [Time.now.strftime('%T'),'']] if format != 'full'
if eventlist.length != 0
max_hostlen = eventlist.each.max { |a,b| a[:hostname].length <=> b[:hostname].length }[:hostname].length
max_desclen = eventlist.each.max { |a,b| a[:description].length <=> b[:description].length }[:description].length
eventlist.each do |e|
break if pretty_output.length == max_lines and format != 'full'
ack = "N".red
ack = "Y".green if e[:acknowledged] == 1
pretty_output << "%s " % e[:fuzzytime] + "%-#{max_hostlen}s " % e[:hostname] +
"%-#{max_desclen}s".color_by_severity(e[:severity]) % e[:description] + " %s" % ack
end
else
pretty_output << ['',
'The API calls returned 0 results. Either your servers are very happy, or ZMonitor is not working correctly.',
'', "Please check your dashboard at #{@api.server.to_s.gsub(/\/api_jsonrpc.php/, '')} to verify activity.", '',
'ZMonitor will continue to refresh every ten seconds unless you interrupt it.']
end
print "\e[H\e[2J" if format != 'full' puts pretty_output
end
|