51: def mkhtml
52: images = Dir.entries(hostdir).find_all { |d| d =~ /\.png/ }
53:
54: periodorder = %w{daily weekly monthly yearly}
55:
56: periods = {}
57: types = {}
58: images.each do |n|
59: type, period = n.sub(".png", '').split("-")
60: periods[period] ||= []
61: types[type] ||= []
62: periods[period] << n
63: types[type] << n
64: end
65:
66: files = []
67:
68: periodorder.each do |period|
69: unless ary = periods[period]
70: raise Puppet::Error, "Could not find graphs for %s" % period
71: end
72: files << htmlfile(period, ary, :first)
73: end
74:
75:
76: types.sort { |a,b| a[0] <=> b[0] }.each do |type, ary|
77: newary = []
78: periodorder.each do |period|
79: if graph = ary.find { |g| g.include?("-%s.png" % period) }
80: newary << graph
81: else
82: raise "Could not find %s-%s graph" % [type, period]
83: end
84: end
85:
86: files << htmlfile(type, newary, :second)
87: end
88:
89: File.open(File.join(hostdir, "index.html"), "w") do |of|
90: of.puts "<html><head><title>Report graphs for %s</title></head><body>" %
91: host
92: files.each do |file|
93: of.puts "<a href='%s'>%s</a><br/>" %
94: [File.basename(file),
95: File.basename(file).sub(".html",'').capitalize]
96: end
97: of.puts "</body></html>"
98: end
99: end