diff --git a/CHANGELOG.md b/CHANGELOG.md index a8de4f4..21bef8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ cookbook-pmacct CHANGELOG =============== +## 0.0.6 + + - Miguel Negron + - [3ec8ebb] Merge with development + - [eb39baa] Fix lint + ## 0.0.5 - Miguel Negrón diff --git a/resources/attributes/default.rb b/resources/attributes/default.rb index 9bb4f4a..f1f5e94 100644 --- a/resources/attributes/default.rb +++ b/resources/attributes/default.rb @@ -1,3 +1,2 @@ -#Flags -default["pmacct"]["registered"] = false - +# Flags +default['pmacct']['registered'] = false diff --git a/resources/metadata.rb b/resources/metadata.rb index c05add2..cdccfa4 100644 --- a/resources/metadata.rb +++ b/resources/metadata.rb @@ -3,4 +3,4 @@ maintainer_email 'git@redborder.com' license 'AGPL-3.0' description 'Installs/Configures cookbook-pmacct' -version '0.0.5' \ No newline at end of file +version '0.0.6' diff --git a/resources/providers/config.rb b/resources/providers/config.rb index d0db552..906cad3 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -1,75 +1,69 @@ - -# Cookbook Name:: pmacct -# +# Cookbook:: pmacct # Provider:: config -# include Pmacct::Helper action :add do begin - user = new_resource.user - cdomain = new_resource.cdomain kafka_hosts = new_resource.kafka_hosts kafka_topic = new_resource.kafka_topic kafka_broker_port = new_resource.kafka_broker_port geo_country = new_resource.geo_country - dnf_package "pmacct" do + dnf_package 'pmacct' do action :upgrade flush_cache [:before] end - execute "create_user" do + execute 'create_user' do command "/usr/sbin/useradd -r #{user}" ignore_failure true not_if "getent passwd #{user}" end - directory "/etc/pmacct" do + directory '/etc/pmacct' do owner user group group - mode 0755 + mode '0755' end flow_nodes = [] - template "/etc/pmacct/sfacctd.conf" do - source "sfacctd.conf.erb" + template '/etc/pmacct/sfacctd.conf' do + source 'sfacctd.conf.erb' owner user group user - mode 0644 + mode '0644' ignore_failure true - cookbook "pmacct" - variables(:flow_nodes => flow_nodes, - :kafka_hosts => kafka_hosts, - :kafka_topic => kafka_topic, - :kafka_broker_port => kafka_broker_port, - :geo_country => geo_country - ) - notifies :restart, "service[sfacctd]", :delayed + cookbook 'pmacct' + variables(flow_nodes: flow_nodes, + kafka_hosts: kafka_hosts, + kafka_topic: kafka_topic, + kafka_broker_port: kafka_broker_port, + geo_country: geo_country) + notifies :restart, 'service[sfacctd]', :delayed end - template "/etc/pmacct/pretag.map" do - source "pretag.map.erb" + template '/etc/pmacct/pretag.map' do + source 'pretag.map.erb' owner user group user - mode 0644 + mode '0644' ignore_failure true - cookbook "pmacct" - variables(:flow_nodes => flow_nodes) - notifies :restart, "service[sfacctd]", :delayed + cookbook 'pmacct' + variables(flow_nodes: flow_nodes) + notifies :restart, 'service[sfacctd]', :delayed end - service "sfacctd" do - service_name "sfacctd" + service 'sfacctd' do + service_name 'sfacctd' ignore_failure true - supports :status => true, :reload => true, :restart => true, :enable => true + supports status: true, reload: true, restart: true, enable: true action [:start, :enable] end - Chef::Log.info("Pmacct cookbook has been processed") + Chef::Log.info('Pmacct cookbook has been processed') rescue => e Chef::Log.error(e.message) end @@ -77,26 +71,25 @@ action :remove do begin - - service "sfacctd" do - service_name "sfacctd" + service 'sfacctd' do + service_name 'sfacctd' ignore_failure true - supports :status => true, :enable => true + supports status: true, enable: true action [:stop, :disable] end - %w[ /etc/pmacct ].each do |path| + %w(/etc/pmacct).each do |path| directory path do recursive true action :delete end end - dnf_package "pmacct" do + dnf_package 'pmacct' do action :remove end - Chef::Log.info("Pmacct cookbook has been processed") + Chef::Log.info('Pmacct cookbook has been processed') rescue => e Chef::Log.error(e.message) end @@ -104,21 +97,21 @@ action :register do begin - if !node["pmacct"]["registered"] + unless node['pmacct']['registered'] query = {} - query["ID"] = "sfacct-#{node["hostname"]}" - query["Name"] = "sfacct" - query["Address"] = "#{node["ipaddress"]}" - query["Port"] = "6343" + query['ID'] = "sfacct-#{node['hostname']}" + query['Name'] = 'sfacct' + query['Address'] = "#{node['ipaddress']}" + query['Port'] = '6343' json_query = Chef::JSONCompat.to_json(query) execute 'Register service in consul' do - command "curl -X PUT http://localhost:8500/v1/agent/service/register -d '#{json_query}' &>/dev/null" - action :nothing + command "curl -X PUT http://localhost:8500/v1/agent/service/register -d '#{json_query}' &>/dev/null" + action :nothing end.run_action(:run) - node.normal["pmacct"]["registered"] = true - Chef::Log.info("sfacct service has been registered to consul") + node.normal['pmacct']['registered'] = true + Chef::Log.info('sfacct service has been registered to consul') end rescue => e Chef::Log.error(e.message) @@ -127,14 +120,14 @@ action :deregister do begin - if node["pmacct"]["registered"] + if node['pmacct']['registered'] execute 'Deregister service in consul' do - command "curl -X PUT http://localhost:8500/v1/agent/service/deregister/sfacct-#{node["hostname"]} &>/dev/null" + command "curl -X PUT http://localhost:8500/v1/agent/service/deregister/sfacct-#{node['hostname']} &>/dev/null" action :nothing end.run_action(:run) - node.normal["pmacct"]["registered"] = false - Chef::Log.info("sfacct service has been deregistered from consul") + node.normal['pmacct']['registered'] = false + Chef::Log.info('sfacct service has been deregistered from consul') end rescue => e Chef::Log.error(e.message) diff --git a/resources/recipes/default.rb b/resources/recipes/default.rb index c85e634..a9a93dd 100644 --- a/resources/recipes/default.rb +++ b/resources/recipes/default.rb @@ -1,12 +1,8 @@ -# -# Cookbook Name:: pmacct +# Cookbook:: pmacct # Recipe:: default -# -# Copyright 2016, redborder -# -# All rights reserved - Do Not Redistribute -# +# Copyright:: 2024, redborder +# License:: Affero General Public License, Version 3 -pmacct_config "config" do +pmacct_config 'config' do action :add end diff --git a/resources/resources/config.rb b/resources/resources/config.rb index 7f1dd7b..48272a4 100644 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -1,17 +1,13 @@ -# Cookbook Name:: pmacct -# +# Cookbook:: pmacct # Resource:: config -# actions :add, :remove, :register, :deregister default_action :add -attribute :user, :kind_of => String, :default => "pmacct" -attribute :cdomain, :kind_of => String, :default => "redborder.cluster" -attribute :sensors, :kind_of => Hash, :default => {} -attribute :kafka_hosts, :kind_of => Array, :default => ["127.0.0.1"] -attribute :kafka_topic, :kind_of => String, :default => "sflow" -attribute :kafka_broker_port, :kind_of => Integer, :default => 9092 -attribute :geo_country, :kind_of => String, :default => "/usr/share/GeoIP/GeoLiteCountry.dat" - - +attribute :user, kind_of: String, default: 'pmacct' +attribute :cdomain, kind_of: String, default: 'redborder.cluster' +attribute :sensors, kind_of: Hash, default: {} +attribute :kafka_hosts, kind_of: Array, default: ['127.0.0.1'] +attribute :kafka_topic, kind_of: String, default: 'sflow' +attribute :kafka_broker_port, kind_of: Integer, default: 9092 +attribute :geo_country, kind_of: String, default: '/usr/share/GeoIP/GeoLiteCountry.dat'