<commit_before>#
# Cookbook Name:: serverdensity
# Recipe:: default
#
# Copyright 2016, Server Density
#
# All rights reserved - Do Not Redistribute
#

return unless node["serverdensity"]["enabled"]

chef_gem 'rest-client' do
    version '~> 1.7.3'
    action :install
    compile_time false if Chef::Resource::ChefGem.method_defined?(:compile_time)
end

case node["platform"]

  when 'debian', 'ubuntu'
    include_recipe 'apt'

    apt_repository 'serverdensity' do
      key 'https://archive.serverdensity.com/sd-packaging-public.key'
      uri 'https://archive.serverdensity.com/ubuntu/'
      distribution 'all'
      components ['main']
      action :add
    end

    dpkg_autostart 'sd-agent' do
      allow false
    end

  when 'centos', 'redhat', 'amazon', 'scientific', 'oracle'

    yum_repository 'serverdensity' do
      description 'Server Density sd-agent'
      baseurl 'https://archive.serverdensity.com/el/$releasever'
      gpgkey 'https://archive.serverdensity.com/sd-packaging-public.key'
    end
end

package 'sd-agent'

service 'sd-agent' do
  supports [:start, :stop, :restart]
  action :nothing
end

serverdensity node.name do
    token node['serverdensity']['token']
end

if node['serverdensity']['apache_status_url']
    package 'sd-agent-apache'
    template '/etc/sd-agent/conf.d/apache.yaml' do<commit_msg>update for new deb repos, install ius-release and epel-release on el6 servers for dependencies<commit_after>#
# Cookbook Name:: serverdensity
# Recipe:: default
#
# Copyright 2016, Server Density
#
# All rights reserved - Do Not Redistribute
#

return unless node["serverdensity"]["enabled"]

chef_gem 'rest-client' do
    version '~> 1.7.3'
    action :install
    compile_time false if Chef::Resource::ChefGem.method_defined?(:compile_time)
end

case node["platform"]

  when 'debian', 'ubuntu'
    include_recipe 'apt'

    case node['lsb']['codename'].downcase
      when 'artful', 'yakkety', 'xenial', 'zesty'
        node.run_state['repo_dist'] = 'xenial'
      when 'trusty', 'utopic', 'vivid', 'wily'
        node.run_state['repo_dist'] = 'trusty'
      when 'precise', 'quantal', 'raring', 'saucy'
        node.run_state['repo_dist'] = 'all'
      when 'wheezy', 'jessie', 'stretch'
        node.run_state['repo_dist'] = node['lsb']['codename'].downcase
      else
        node.run_state['repo_dist'] = 'all'
    end

    apt_repository 'serverdensity' do
      key 'https://archive.serverdensity.com/sd-packaging-public.key'
      uri "https://archive.serverdensity.com/#{node['platform']}/"
      distribution node.run_state['repo_dist']
      components ['main']
      action :add
    end

    dpkg_autostart 'sd-agent' do
      allow false
    end

  when 'centos', 'redhat', 'amazon', 'scientific', 'oracle'
    major = node['platform_version'].to_i
    if major == 6
      if node[:kernel][:machine] == "i686"
         rpm_arch = "i386"
      else
         rpm_arch = node[:kernel][:machine]
      end
      remote_file "#{Chef::Config[:file_cache_path]}/epel-release-latest.noarch.rpm" do
        source "https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
        notifies :install, "rpm_package[epel-release]", :immediately
        retries 5 # We may be redirected to a FTP URL, CHEF-1031.
      end

      rpm_package "epel-release" do
        source "#{Chef::Config[:file_cache_path]}/epel-release-latest.noarch.rpm"
        only_if {::File.exists?("#{Chef::Config[:file_cache_path]}/epel-release-latest.noarch.rpm")}
        action :nothing
      end

      if node["platform"] == "centos"
        ius_package = node["platform"]
      else
        ius_package = "rhel"
      end

      remote_file "#{Chef::Config[:file_cache_path]}/ius-release.rpm" do
        source "https://#{ius_package}6.iuscommunity.org/ius-release.rpm"
        notifies :install, "rpm_package[ius-release]", :immediately
        retries 5 # We may be redirected to a FTP URL, CHEF-1031.
      end

      rpm_package "ius-release" do
        source "#{Chef::Config[:file_cache_path]}/ius-release.rpm"
        only_if {::File.exists?("#{Chef::Config[:file_cache_path]}/ius-release.rpm")}
        action :nothing
      end
    end
    yum_repository 'serverdensity' do
      description 'Server Density sd-agent'
      baseurl 'https://archive.serverdensity.com/el/$releasever'
      gpgkey 'https://archive.serverdensity.com/sd-packaging-public.key'
    end
end

package 'sd-agent'

service 'sd-agent' do
  supports [:start, :stop, :restart]
  action :nothing
end

serverdensity node.name do
    token node['serverdensity']['token']
end

if node['serverdensity']['apache_status_url']
    package 'sd-agent-apache'
    template '/etc/sd-agent/conf.d/apache.yaml' do
{'fraction_non_alphanumeric': 0.13958421722528638, 'fraction_numerical': 0.007212558336868901, 'mean_word_length': 3.341620626151013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 10, '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': '67417', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1535, 'n_words': 335}