Merge pull request 'Update nodes ref and fix zerotier Ohai plugin (follow-up to #699)' (#700) from gitea-crawler-mitigation into master
Reviewed-on: #700
This commit was merged in pull request #700.
This commit is contained in:
4 files changed
+89
-2
No files matched your search
+1
-1
Submodule nodes updated: c904defa3c...b9dcdfc814.
@@ -9,3 +9,4 @@ chef_version '>= 14.0'
|
||||
|
||||
depends 'kosmos-base'
|
||||
depends 'zerotier'
|
||||
depends 'ohai'
|
||||
@@ -3,7 +3,20 @@
|
||||
# Recipe:: ohai_plugin
|
||||
#
|
||||
|
||||
include_recipe "zerotier::ohai_plugin"
|
||||
# Use our own copy of the community plugin template: the upstream one calls
|
||||
# File.exists?, which was removed in Ruby 3.4 (Cinc Client 19), making the
|
||||
# plugin fail and dropping the `zerotier` attribute from the node.
|
||||
ohai_plugin "zerotier_ohai" do
|
||||
compile_time false
|
||||
resource :template
|
||||
cookbook "kosmos_zerotier"
|
||||
source_file "zerotier_ohai.rb"
|
||||
variables(
|
||||
zerotier_binary: node["zerotier"]["binary"],
|
||||
control_port: node["zerotier"]["control_port"],
|
||||
data_dir: node["zerotier"]["data_dir"]
|
||||
)
|
||||
end
|
||||
|
||||
ohai "reload_zerotier" do
|
||||
action :reload
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
Ohai.plugin(:ZeroTier) do
|
||||
provides 'zerotier'
|
||||
|
||||
def zerotier_command (subcommand)
|
||||
return "<%= @zerotier_binary %> <% unless @zerotier_binary.end_with?('-cli') %>-q<% end %> #{subcommand} -p<%= @control_port %> -D<%= @data_dir %>"
|
||||
end
|
||||
|
||||
def linux_get_networks
|
||||
networks = Mash.new
|
||||
cmd = zerotier_command('listnetworks')
|
||||
Ohai::Log.info(cmd)
|
||||
so = shell_out(cmd)
|
||||
first_line = true
|
||||
so.stdout.lines do |line|
|
||||
if first_line
|
||||
# skip the header line
|
||||
first_line = false
|
||||
next
|
||||
end
|
||||
|
||||
data = line.strip.split(/\s+/)
|
||||
|
||||
cur_network = Mash.new
|
||||
cur_network[:network_name] = data[3]
|
||||
cur_network[:mac] = data[4]
|
||||
cur_network[:status] = data[5]
|
||||
cur_network[:type] = data[6]
|
||||
cur_network[:interface] = data[7]
|
||||
cur_network[:addresses] = []
|
||||
|
||||
data[8].split(',').each do |addr|
|
||||
cur_network[:addresses].push(addr)
|
||||
end
|
||||
|
||||
networks[data[2]] = cur_network
|
||||
end
|
||||
return networks
|
||||
end
|
||||
|
||||
def linux_get_node_id
|
||||
node_id = ''
|
||||
|
||||
# File.exists? was removed in Ruby 3.4, use File.exist?
|
||||
if ::File.exist?("<%= @data_dir %>/identity.public")
|
||||
node_id = ::File.read("<%= @data_dir %>/identity.public")
|
||||
node_id = node_id[0..9]
|
||||
Ohai
|
||||
else
|
||||
Ohai::Log.warn("<%= @data_dir %>/identity.public' does not exist")
|
||||
end
|
||||
|
||||
return node_id unless node_id.empty?
|
||||
end
|
||||
|
||||
def get_version
|
||||
so = shell_out("<%= @zerotier_binary %> -v 2>&1")
|
||||
version = so.stdout.strip
|
||||
return version unless version.empty?
|
||||
end
|
||||
|
||||
collect_data(:linux) do
|
||||
# File.exists? was removed in Ruby 3.4, use File.exist?
|
||||
if ::File.exist?("<%= @zerotier_binary %>")
|
||||
zerotier Mash.new
|
||||
zerotier[:version] = get_version
|
||||
zerotier[:node_id] = linux_get_node_id
|
||||
zerotier[:networks] = linux_get_networks
|
||||
else
|
||||
Ohai::Log.warn("Cannot find zerotier binary")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user