Skip to content

Commit

Permalink
Merge pull request #9 from redBorder/development
Browse files Browse the repository at this point in the history
Release 0.0.6
  • Loading branch information
nilsver authored Jun 4, 2024
2 parents b495140 + fa26cc0 commit 08170fb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 75 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions resources/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#Flags
default["pmacct"]["registered"] = false

# Flags
default['pmacct']['registered'] = false
2 changes: 1 addition & 1 deletion resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
maintainer_email '[email protected]'
license 'AGPL-3.0'
description 'Installs/Configures cookbook-pmacct'
version '0.0.5'
version '0.0.6'
95 changes: 44 additions & 51 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
@@ -1,124 +1,117 @@

# 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
end

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
end

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)
Expand All @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions resources/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 8 additions & 12 deletions resources/resources/config.rb
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 08170fb

Please sign in to comment.