lib/visage-app/profile.rb in visage-app-1.0.0 vs lib/visage-app/profile.rb in visage-app-2.0.0

- old
+ new

@@ -9,10 +9,19 @@ module Visage class Profile attr_reader :options, :selected_hosts, :hosts, :selected_metrics, :metrics, :name, :errors + def self.old_format? + profiles = Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {} + profiles.each_pair do |name, attrs| + return true if attrs[:hosts] =~ /\*/ || attrs[:metrics] =~ /\*/ + end + + false + end + def self.load Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {} end def self.get(id) @@ -30,49 +39,33 @@ def initialize(opts={}) @options = opts @options[:url] = @options[:profile_name] ? @options[:profile_name].downcase.gsub(/[^\w]+/, "+") : nil @errors = {} - - # FIXME: this is nasty - # FIXME: doesn't work if there's only one host - # FIXME: add regex matching option - if @options[:hosts].blank? - @selected_hosts = [] - @hosts = Visage::Collectd::RRDs.hosts - else - @selected_hosts = Visage::Collectd::RRDs.hosts(:hosts => @options[:hosts]) - @hosts = Visage::Collectd::RRDs.hosts - @selected_hosts - end - - if @options[:metrics].blank? - @selected_metrics = [] - @metrics = Visage::Collectd::RRDs.metrics - else - @selected_metrics = Visage::Collectd::RRDs.metrics(:metrics => @options[:metrics]) - @metrics = Visage::Collectd::RRDs.metrics - @selected_metrics - end + @options[:hosts] = @options[:hosts].values if @options[:hosts].class == Hash + @options[:metrics] = @options[:metrics].values if @options[:metrics].class == Hash end # Hashed based access to @options. def method_missing(method) @options[method] end def save if valid? # Construct record. - attrs = { :hosts => @options[:hosts], - :metrics => @options[:metrics], + attrs = { :hosts => @options[:hosts], + :metrics => @options[:metrics], :profile_name => @options[:profile_name], - :url => @options[:profile_name].downcase.gsub(/[^\w]+/, "+") } + :url => @options[:profile_name].downcase.gsub(/[^\w]+/, "+") } # Save it. profiles = self.class.load profiles[attrs[:url]] = attrs Visage::Config::File.open('profiles.yaml') do |file| + file.truncate(0) file << profiles.to_yaml end true else @@ -83,13 +76,13 @@ def valid? valid_profile_name? end def graphs - graphs = [] - - hosts = Visage::Collectd::RRDs.hosts(:hosts => @options[:hosts]) + graphs = [] + hosts = @options[:hosts] metrics = @options[:metrics] + hosts.each do |host| attrs = {} globs = Visage::Collectd::RRDs.metrics(:host => host, :metrics => metrics) globs.each do |n| parts = n.split('/')