Sha256: b652d24784cc10349962fb8392c8530bae7e07b6d69aea450fa8314a0b946642

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

class Helpers::Process

  def add_facts(facts, host, collection)
    facts.each{|f|
      if f['certname'].eql?(host)
        fact_name = f['name']
        fact_value = f['value']

        if fact_name.include?('processor')
          fact_name = number_to_name(fact_name)
        end

        if fact_name.include?('path')
          fact_value = fact_value.gsub!('"','')
        end

        if collection.instance_of?(Hash)
          collection[host][fact_name] = fact_value
        elsif collection.instance_of?(Array)
          collection << "#{fact_name}=\"#{fact_value}\" "
        else
        end
      end
    }
    return collection
  end

  def endpoint_processor(output)
    file_name = output.tmp_file
    content = ''
    if File.exist?(file_name)
      file = File.new(file_name)
      t_now = Time.at(Time.now.to_i)
      t_file = Time.at(file.mtime.to_i)

      if t_now < (t_file + 300)
        content = File.new(file_name, 'r').read
      else
        p "#{t_now} #{t_file}"
        endpoint = EndPoint.new()
        content = endpoint.parse(output)
      end
    else
      endpoint = EndPoint.new()
      content = endpoint.parse(output)
    end

    return content
  end

  private
    def number_to_name(name)
      lookup = {
        '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five',
        '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten',
        '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen',
        '15' => 'fifteen', '16' => 'sixteen'
      }

      lookup.each { |k,v|
        if name.include?(k)
          name.gsub!(k,"_#{v}")
        end
      }
      return name
    end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppetdb_rundeck-0.2.3 lib/helpers/process.rb
puppetdb_rundeck-0.2.2 lib/helpers/process.rb
puppetdb_rundeck-0.2.1 lib/helpers/process.rb
puppetdb_rundeck-0.2.0 lib/helpers/process.rb