|
4 | 4 | # |
5 | 5 | # thanks @indirect ! |
6 | 6 | # Adapted from the original https://github.com/indirect/ey-cloud-recipes/tree/master/cookbooks/papertrail |
| 7 | +# and https://github.com/bhoggard/remote_syslog2 |
7 | 8 | # |
8 | 9 | # This recipe makes EngineYard Gentoo instances send logs to Papertrail (papertrailapp.com). |
9 | 10 | # * syslog-ng is used to monitor syslog |
10 | | -# * remote_syslog is used for other (application, database, etc.) logs |
| 11 | +# * remote_syslog2 is used for other (application, database, etc.) logs |
11 | 12 | # * TLS is used instead of UDP |
12 | 13 |
|
13 | 14 | app_name = node[:applications].keys.first |
14 | 15 | env = node[:environment][:framework_env] |
15 | 16 | PAPERTRAIL_CONFIG = { |
16 | | - :syslog_ng_version => '3.3.5', |
17 | | - :remote_syslog_gem_version => '~>1.6', |
18 | | - :port => 11111111111111, # YOUR PORT HERE |
| 17 | + :syslog_ng_version => '3.3.5-r1', |
| 18 | + :remote_syslog_version => 'v0.12', |
| 19 | + :remote_syslog_filename => 'remote_syslog_linux_amd64.tar.gz', |
| 20 | + :remote_syslog_checksum => 'ecb1ed1831ef9645c6379151fae6859bfe7db3ac9c6b096ae4a063dc79930a70', |
| 21 | + :port => 111111111111111, # YOUR PORT HERE |
| 22 | + :destination_host => 'HOST.papertrailapp.com', # YOUR HOST HERE |
19 | 23 | :hostname => [app_name, node[:instance_role], `hostname`.chomp].join('_'), |
20 | 24 | :other_logs => [ |
21 | 25 | '/var/log/engineyard/nginx/*log', |
|
27 | 31 | '400 0 "-" "-" "-', # seen in ssl access logs |
28 | 32 | ], |
29 | 33 | } |
| 34 | +remote_syslog_src_filename = PAPERTRAIL_CONFIG[:remote_syslog_filename] |
| 35 | +remote_syslog_src_filepath = "#{Chef::Config['file_cache_path']}#{remote_syslog_src_filename}" |
| 36 | +remote_syslog_extract_path = "#{Chef::Config['file_cache_path']}remote_syslog2/#{PAPERTRAIL_CONFIG[:remote_syslog_checksum]}" |
30 | 37 |
|
31 | 38 | # install syslog-ng |
32 | 39 |
|
|
46 | 53 | action :install |
47 | 54 | end |
48 | 55 |
|
49 | | -remote_file '/etc/syslog.papertrail.crt' do |
50 | | - source 'https://papertrailapp.com/tools/syslog.papertrail.crt' |
51 | | - checksum '7d6bdd1c00343f6fe3b21db8ccc81e8cd1182c5039438485acac4d98f314fe10' |
52 | | - mode '0644' |
53 | | -end |
54 | | - |
55 | 56 | directory '/etc/syslog-ng/cert.d' do |
56 | 57 | recursive true |
57 | 58 | end |
58 | 59 |
|
59 | | -link '/etc/syslog-ng/cert.d/2f2c2f7c.0' do |
60 | | - to '/etc/syslog.papertrail.crt' |
61 | | - link_type :symbolic |
| 60 | +remote_file '/etc/syslog-ng/cert.d/papertrail-bundle.tar.gz' do |
| 61 | + source 'https://papertrailapp.com/tools/papertrail-bundle.tar.gz' |
| 62 | + checksum '5590de7f7f957508eff58767212cae8fa2fb8cf503e5b5b801f32087501060f3' |
| 63 | + mode '0644' |
| 64 | +end |
| 65 | + |
| 66 | +bash 'extract SSL certificates' do |
| 67 | + cwd '/etc/syslog-ng/cert.d' |
| 68 | + code <<-EOH |
| 69 | + tar xzf papertrail-bundle.tar.gz |
| 70 | + EOH |
62 | 71 | end |
63 | 72 |
|
64 | 73 | template '/etc/syslog-ng/syslog-ng.conf' do |
|
77 | 86 | command %{/etc/init.d/syslog-ng restart} |
78 | 87 | end |
79 | 88 |
|
80 | | -# install remote_syslog daemon |
| 89 | +# remove remote_syslog gem & install remote_syslog2 daemon |
| 90 | + |
| 91 | +execute 'stop existing instances of remote_syslog' do |
| 92 | + command %{/etc/init.d/remote_syslog stop} |
| 93 | + only_if { ::File.exists?("/etc/init.d/remote_syslog") } |
| 94 | +end |
| 95 | + |
| 96 | +execute 'remove remote_syslog gem' do |
| 97 | + command %{gem uninstall remote_syslog -x} |
| 98 | +end |
| 99 | + |
| 100 | +execute "Get remote_syslog" do |
| 101 | + command "wget -O #{remote_syslog_src_filepath} https://github.com/papertrail/remote_syslog2/releases/download/#{PAPERTRAIL_CONFIG[:remote_syslog_version]}/#{PAPERTRAIL_CONFIG[:remote_syslog_filename]}" |
| 102 | +end |
| 103 | + |
| 104 | +bash 'extract and copy executable' do |
| 105 | + cwd ::File.dirname(remote_syslog_src_filepath) |
| 106 | + code <<-EOH |
| 107 | + mkdir -p #{remote_syslog_extract_path} |
| 108 | + tar xzf #{remote_syslog_src_filename} -C #{remote_syslog_extract_path} |
| 109 | + mv #{remote_syslog_extract_path}/remote_syslog/remote_syslog /usr/local/bin |
| 110 | + EOH |
| 111 | + not_if { ::File.exists?(remote_syslog_extract_path) } |
| 112 | +end |
81 | 113 |
|
82 | | -execute 'install remote_syslog gem' do |
83 | | - command %{gem install remote_syslog -v '#{PAPERTRAIL_CONFIG[:remote_syslog_gem_version]}'} |
84 | | - creates '/usr/bin/remote_syslog' |
| 114 | +file "/usr/local/bin/remote_syslog" do |
| 115 | + owner "root" |
| 116 | + group "root" |
| 117 | + mode "0755" |
| 118 | + action :touch |
85 | 119 | end |
86 | 120 |
|
87 | 121 | # remote_syslog config file |
|
0 commit comments