From 96d68de5d490dfcf285e2b1bfb5349db870d59a0 Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sat, 1 Jun 2024 14:35:02 +0100 Subject: [PATCH 1/8] lint attributes --- resources/attributes/default.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 From 29d3d4cdda4dd4802df30902ecb15f69c300c066 Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sat, 1 Jun 2024 14:35:08 +0100 Subject: [PATCH 2/8] lint metadata --- resources/metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/metadata.rb b/resources/metadata.rb index e01e797..1764330 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.4' \ No newline at end of file +version '0.0.4' From a2e10d00b473248b63ae8a46809bc812416be6f2 Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sat, 1 Jun 2024 14:35:12 +0100 Subject: [PATCH 3/8] lint providers --- resources/providers/config.rb | 91 ++++++++++++++++------------------- 1 file changed, 42 insertions(+), 49 deletions(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index a0b7c19..7dfe8e6 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -1,27 +1,22 @@ - -# 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}" @@ -29,41 +24,40 @@ 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 @@ -71,26 +65,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 @@ -98,21 +91,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) @@ -121,14 +114,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) From 6ba0c41211bde12a04b05747e76a199e53e3be62 Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sat, 1 Jun 2024 14:35:21 +0100 Subject: [PATCH 4/8] lint recipes --- resources/recipes/default.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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 From a3cdc680d2fed21e5a24aba945d9c3710ddc5dfa Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sat, 1 Jun 2024 14:35:27 +0100 Subject: [PATCH 5/8] lint resources --- resources/resources/config.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) 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' From 5a0ad8ce137e42b47c3ffe0dcc87bb9129dc151e Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sun, 2 Jun 2024 00:09:04 +0100 Subject: [PATCH 6/8] Fix lint resources --- resources/providers/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index bff380d..f3be963 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -22,7 +22,7 @@ not_if "getent passwd #{user}" end - directory "/etc/pmacct" do + directory '/etc/pmacct' do owner user group group mode 0755 From eb39baa31cec1d7290917889ec8c65750e83a9ca Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Sun, 2 Jun 2024 00:12:51 +0100 Subject: [PATCH 7/8] Fix lint resources --- resources/providers/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index f3be963..906cad3 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -25,7 +25,7 @@ directory '/etc/pmacct' do owner user group group - mode 0755 + mode '0755' end flow_nodes = [] From fa26cc05c92dfa9bef10490e9dc3fcfe80e27f50 Mon Sep 17 00:00:00 2001 From: nilsver Date: Tue, 4 Jun 2024 08:19:00 +0100 Subject: [PATCH 8/8] Release 0.0.6 --- CHANGELOG.md | 6 ++++++ resources/metadata.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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/metadata.rb b/resources/metadata.rb index e1584c2..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' +version '0.0.6'