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