module Pencil::Helpers

Public Instance Methods

append_query_string(str) click to toggle source
# File lib/pencil/helpers.rb, line 115
def append_query_string(str)
  v = str.dup
  (v << "?#{request.query_string}") unless request.query_string.empty?
  return v
end
cluster_graph(g, cluster, title="wtf") click to toggle source
# File lib/pencil/helpers.rb, line 18
def cluster_graph(g, cluster, title="wtf")
  image_url = \
  @dash.render_cluster_graph(g, cluster,
                             :title => title,
                             :dynamic_url_opts => merge_opts)
  zoom_url = cluster_graph_link(@dash, g, cluster)
  return image_url, zoom_url
end
cluster_selector() click to toggle source
# File lib/pencil/helpers.rb, line 144
def cluster_selector
  @clusters = settings.config.clusters.sort + ["global"]
  erb :'partials/cluster_selector', :layout => false
end
cluster_switcher(clusters) click to toggle source
# File lib/pencil/helpers.rb, line 131
def cluster_switcher(clusters)
  @clusters = clusters
  erb :'partials/cluster_switcher', :layout => false
end
cluster_zoom_graph(g, cluster, host, title) click to toggle source
# File lib/pencil/helpers.rb, line 33
def cluster_zoom_graph(g, cluster, host, title)
  image_url = g.render_url([host.name], [cluster], :title => title,
                           :dynamic_url_opts => merge_opts)
  zoom_url = cluster_zoom_link(cluster, host)
  return image_url, zoom_url
end
css_url() click to toggle source

fixme this isn’t used anymore, but should

# File lib/pencil/helpers.rb, line 95
def css_url
  style = File.join(settings.root, "public/style.css")
  mtime = File.mtime(style).to_i.to_s
  return \
  %Q[<link href="/style.css?#{mtime}" rel="stylesheet" type="text/css">]
end
dash_switcher() click to toggle source
# File lib/pencil/helpers.rb, line 136
def dash_switcher
  erb :'partials/dash_switcher', :layout => false
end
graph_switcher() click to toggle source
# File lib/pencil/helpers.rb, line 140
def graph_switcher
  erb :'partials/graph_switcher', :layout => false
end
header(str) click to toggle source

fixme this is a hack

# File lib/pencil/helpers.rb, line 165
    def header(str)
      <<-FOO
  <div class="path_container">
                <h2>#{@title}</h2>
                  <span class="zoom">
                  #{str}
                  </span>
              </div>
              <div id="timeslice_container">
                <h3 id="timeslice">#{range_string}</h3>
                #{permalink unless @no_graphs}
              </div>
  FOO
    end
hosts_selector(hosts, print_clusters=false) click to toggle source
# File lib/pencil/helpers.rb, line 109
def hosts_selector(hosts, print_clusters=false)
  @print_clusters = print_clusters
  @hosts = hosts
  erb :'partials/hosts_selector', :layout => false
end
input_boxes() click to toggle source

generate the input box fields, filled in to current parameters if specified

# File lib/pencil/helpers.rb, line 81
def input_boxes
  @prefs = @@prefs
  erb :'partials/input_boxes', :layout => false
end
merge_opts() click to toggle source
# File lib/pencil/helpers.rb, line 121
def merge_opts
  static_opts = ["cluster", "dashboard", "zoom", "host", "session_id"]
  opts = params.dup
  session.merge(opts).delete_if { |k,v| static_opts.member?(k) || v.empty? }
end
nowish() click to toggle source
# File lib/pencil/helpers.rb, line 180
def nowish
  if settings.config.global_config[:now_threshold] == false
    return false
  end
  threshold = settings.config.global_config[:now_threshold] || 300
  return @request_time.to_i - @etime.to_i < threshold
end
param_lookup(name) click to toggle source

convert keys to symbols before lookup

# File lib/pencil/helpers.rb, line 11
def param_lookup(name)
  sym_hash = {}
  session.each { |k,v| sym_hash[k.to_sym] = v unless v.empty? }
  params.each { |k,v| sym_hash[k.to_sym] = v unless v.empty? }
  settings.config.global_config[:url_opts].merge(sym_hash)[name.to_sym]
end
range_string() click to toggle source
# File lib/pencil/helpers.rb, line 188
def range_string
  format = settings.config.global_config[:date_format] || "%X %x"
  if @stime && @etime
    if nowish
      "timeslice: from #{@stime.strftime(format)}"
    else
      "timeslice: #{@stime.strftime(format)} - #{@etime.strftime(format)}"
    end
  else
    "invalid time range"
  end

end
refresh() click to toggle source
# File lib/pencil/helpers.rb, line 102
def refresh
  if settings.config.global_config[:refresh_rate] != false && nowish
    rate = settings.config.global_config[:refresh_rate] || 60
    return %Q[<meta http-equiv="refresh" content="#{rate}">]
  end
end
shortcuts(str) click to toggle source
# File lib/pencil/helpers.rb, line 127
def shortcuts(str)
  @str = str
  erb :'partials/shortcuts', :layout => false
end
suggest_dashboards(host, graph) click to toggle source

it’s mildly annoying that when this set is empty there’re no uplinks consider adding a link up to the cluster (which is best we can do)

# File lib/pencil/helpers.rb, line 67
def suggest_dashboards(host, graph)
  ret = Set.new

  host.graphs.each do |g|
    Dashboard.find_by_graph(g).each do |d|
      valid, _ = d.get_valid_hosts(g, host['cluster'])
      ret << d.name if valid.member?(host)
    end
  end

  return ret
end
valid_time(s) click to toggle source
# File lib/pencil/helpers.rb, line 202
def valid_time (s)
  Chronic.parse(s) || s =~ /^\d+$/
end