<commit_before>require "boxen/hook"
require "opentsdb"

module Boxen
  class Hook
    class OpenTSDB < Hook
      def perform?
        enabled?
      end

      private
      def call
        payload = {
          :login  => config.user,
          :sha    => checkout.sha,
          :status => result.success? ? 'success' : 'failure',
        }

        send_opentsdb_data payload
      end

      def send_opentsdb_data(payload)
        host = ENV['BOXEN_OPENTSDB_HOST']
        port = ENV["BOXEN_OPENTSDB_PORT"]

        @client = OpenTSDB::Client.new({:hostname => host, :port => port})

        boxen_run = { :metric => 'boxen.runs', :value => 1, :timestamp => Time.now.to_i, :tags => payload }
        @client.put(boxen_run)
      end

      def required_environment_variables
        ['BOXEN_OPENTSDB_HOST', 'BOXEN_OPENTSDB_PORT']
      end
    end
  end
end

Boxen::Hook.register Boxen::Hook::OpenTSDB<commit_msg>Throwaway test.<commit_after>require "boxen/hook"
require "opentsdb"

module Boxen
  class Hook
    class OpenTSDB < Hook
      def perform?
        enabled?
      end

      private
      def call
        payload = {
          :login  => config.user,
          :sha    => checkout.sha,
          :status => result.success? ? 'success' : 'failure',
        }

        send_opentsdb_data payload
      end

      def send_opentsdb_data(payload)
        host = ENV['BOXEN_OPENTSDB_HOST']
        port = ENV['BOXEN_OPENTSDB_PORT'].to_i

        @client = OpenTSDB::Client.new({:hostname => host, :port => port})

        boxen_run = { :metric => 'boxen.runs', :value => 1, :timestamp => Time.now.to_i, :tags => payload }
        @client.put(boxen_run)

        require 'pp'
        pp boxen_run
      end

      def required_environment_variables
        ['BOXEN_OPENTSDB_HOST', 'BOXEN_OPENTSDB_PORT']
      end
    end
  end
end

Boxen::Hook.register Boxen::Hook::OpenTSDB
{'fraction_non_alphanumeric': 0.11322751322751323, 'fraction_numerical': 0.0010582010582010583, 'mean_word_length': 2.2324786324786325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, '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': '7289404', 'n_tokens_mistral': 634, 'n_tokens_neox': 624, 'n_words': 128}