<commit_before>require 'puppet'
require 'yaml'

begin
  require 'dogapi'
rescue LoadError => e
  Puppet.info "You need the `dogapi` gem to use the DataDog report"
end

Puppet::Reports.register_report(:datadog) do

  configfile = File.join([File.dirname(Puppet.settings[:config]), "datadog.yaml"])
  raise(Puppet::ParseError, "DataDog report config file #{configfile} not readable") unless File.exist?(configfile)
  config = YAML.load_file(configfile)
  API_KEY = config[:datadog_api_key]
  ENV['DATADOG_HOST'] = 'https://app.datadoghq.com/'

  desc <<-DESC
  Send notification of metrics to DataDog
  DESC

  def process
    @status = self.status
    @msg_host = self.host

    Puppet.debug "Sending metrics for #{@msg_host} to DataDog"
    @dog = Dogapi::Client.new(API_KEY, 'https://app.datadoghq.com/')
    self.metrics.each { |metric,data|
      data.values.each { |val|
        name = "puppet.#{val[1].gsub(/ /, '_')}.#{metric}".downcase
        value = val[2]
        @dog.emit_point("#{name}", value, :host => "#{@msg_host}")
      }
    }

    Puppet.debug "Sending events for #{@msg_host} to DataDog"
    output = []
    self.logs.each do |log|
      output << log
    end
    Dogapi::EventService.new('https://app.datadoghq.com').submit(API_KEY, Dogapi::Event.new(output.join("\n"), :msg_title => "Puppet run on #{@msg_host} (status: #{@status})", :event_type => 'Puppet'))
  end
end<commit_msg>updated to remove deprecated methods and to work nicely with dogapi-1.2.0<commit_after>require 'puppet'
require 'yaml'

begin
  require 'dogapi'
rescue LoadError => e
  Puppet.info "You need the `dogapi` gem to use the DataDog report"
end

Puppet::Reports.register_report(:datadog) do

  configfile = File.join([File.dirname(Puppet.settings[:config]), "datadog.yaml"])
  raise(Puppet::ParseError, "DataDog report config file #{configfile} not readable") unless File.exist?(configfile)
  config = YAML.load_file(configfile)
  API_KEY = config[:datadog_api_key]

  desc <<-DESC
  Send notification of metrics to DataDog
  DESC

  def process
    @status = self.status
    @msg_host = self.host

    Puppet.debug "Sending metrics for #{@msg_host} to DataDog"
    @dog = Dogapi::Client.new(API_KEY)
    self.metrics.each { |metric,data|
      data.values.each { |val|
        name = "puppet.#{val[1].gsub(/ /, '_')}.#{metric}".downcase
        value = val[2]
        @dog.emit_point("#{name}", value, :host => "#{@msg_host}")
      }
    }

    Puppet.debug "Sending events for #{@msg_host} to DataDog"
    output = []
    self.logs.each do |log|
      output << log
    end
    @dog.emit_event(Dogapi::Event.new(output.join("\n"), :msg_title => "Puppet run on #{@msg_host} (status: #{@status})", :event_type => 'Puppet'))
  end
end
{'fraction_non_alphanumeric': 0.15697036223929747, 'fraction_numerical': 0.002561287961946579, 'mean_word_length': 3.7630662020905925, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4414042', 'n_tokens_mistral': 994, 'n_tokens_neox': 971, 'n_words': 221}