itamae/cookbooks/prometheus/snmp_exporter_install.rb

53 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2020-10-24 04:23:45 +00:00
snmp_url = ''
snmp_bin = ''
vtag = ''
tag = ''
# Calculate the Download URL:
begin
require 'net/http'
uri = URI.parse('https://github.com/prometheus/snmp_exporter/releases/latest')
Timeout.timeout(3) do
response = Net::HTTP.get_response(uri)
2022-10-15 01:49:11 +00:00
vtag = $1 if response['location'] =~ %r{tag\/(v\d+\.\d+\.\d+)}
2020-10-24 04:23:45 +00:00
tag = vtag.sub(/^v/, '')
snmp_bin = "#{node['snmp_exporter']['prefix']}#{tag}#{node['snmp_exporter']['postfix']}"
snmp_url = "#{node['snmp_exporter']['url']}/#{vtag}/#{snmp_bin}"
end
rescue
# Abort the chef client process:
raise 'Cannot connect to http://github.com.'
end
# Download:
TMP = "/tmp/#{snmp_bin}"
execute "wget #{snmp_url} -O #{TMP}"
# Install:
directory node['snmp_exporter']['storage'] do
owner 'root'
group 'root'
mode '755'
end
execute "tar zxf #{TMP} -C #{node['snmp_exporter']['storage']} --strip-components 1"
# Change Owner and Permissions:
file "#{node['snmp_exporter']['storage']}snmp_exporter" do
owner 'root'
group 'root'
mode '755'
end
# Create Link
link "#{node['snmp_exporter']['location']}snmp_exporter" do
to "#{node['snmp_exporter']['storage']}snmp_exporter"
end