class Dropsonde

Constants

VERSION

Public Class Methods

generate_example(size, filename) click to toggle source
# File lib/dropsonde.rb, line 69
def self.generate_example(size, filename)
  metrics = Dropsonde::Metrics.new
  File.open(filename, 'w') do |file|
    for i in 0...size
      file.write(metrics.example.to_json)
      file.write("\n")
    end
  end
end
generate_report(format) click to toggle source
# File lib/dropsonde.rb, line 35
def self.generate_report(format)
  case format
  when 'json'
    puts JSON.pretty_generate(Dropsonde::Metrics.new.report)
  when 'human'
    puts
    puts Dropsonde::Metrics.new.preview
  else
    raise "unknown format"
  end
end
generate_schema() click to toggle source
# File lib/dropsonde.rb, line 26
def self.generate_schema
  puts JSON.pretty_generate(Dropsonde::Metrics.new.schema)
end
list_metrics() click to toggle source
# File lib/dropsonde.rb, line 30
def self.list_metrics
  puts
  puts Dropsonde::Metrics.new.list
end
puppetDB() click to toggle source
# File lib/dropsonde.rb, line 79
def self.puppetDB
  return @@pdbclient if @@pdbclient

  config = File.join(Puppet.settings[:confdir], 'puppetdb.conf')

  return unless File.file? config

  server = IniFile.load(config)['main']['server_urls'].split(',').first

  @@pdbclient = PuppetDB::Client.new({
    :server => server,
    :pem    => {
        'key'     => Puppet.settings[:hostprivkey],
        'cert'    => Puppet.settings[:hostcert],
        'ca_file' => Puppet.settings[:localcacert],
    }
  })
end
settings() click to toggle source
# File lib/dropsonde.rb, line 22
def self.settings
  @@settings
end
settings=(arg) click to toggle source
# File lib/dropsonde.rb, line 17
def self.settings=(arg)
  raise "Requires a Hash to set all settings at once, not a #{arg.class}" unless arg.is_a? Hash
  @@settings = arg
end
submit_report(endpoint, port) click to toggle source
# File lib/dropsonde.rb, line 47
def self.submit_report(endpoint, port)
  client = HTTPClient.new()
  result = client.post("#{endpoint}:#{port}",
                :header => {'Content-Type' => 'application/json'},
                :body   => Dropsonde::Metrics.new.report.to_json
              )

  if result.status == 200
    data = JSON.parse(result.body)
    if data['newer']
      puts 'A newer version of the telemetry client is available:'
      puts "  -- #{data['link']}"
    else
      puts data['message']
    end
  else
    puts 'Failed to submit report'
    puts JSON.pretty_generate(result.body) if Dropsonde.settings[:verbose]
    exit 1
  end
end