Skip to content

Commit

Permalink
Remove clamav from service list, sort memory services, sort service l…
Browse files Browse the repository at this point in the history
…ist, save service list for rbcli
  • Loading branch information
manegron committed Oct 19, 2024
1 parent 184bcd8 commit ce3975f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
25 changes: 10 additions & 15 deletions resources/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,26 @@

# memory
default['redborder']['memory_services'] = {}
default['redborder']['memory_services']['chef-client'] = { 'count': 10, 'memory': 0 }
default['redborder']['memory_services']['snmp'] = { 'count': 5, 'memory': 0, 'max_limit': 10000 }
default['redborder']['memory_services']['barnyard2'] = { 'count': 10, 'memory': 0 }
default['redborder']['memory_services']['redborder-monitor'] = { 'count': 5, 'memory': 0, 'max_limit': 20000 }
default['redborder']['memory_services']['snmp'] = { 'count': 5, 'memory': 0, 'max_limit': 10000 }
default['redborder']['memory_services']['snortd'] = { 'count': 10, 'memory': 0 }
default['redborder']['memory_services']['barnyard2'] = { 'count': 10, 'memory': 0 }

# exclude mem services, setting memory to 0 for each.
default['redborder']['excluded_memory_services'] = ['chef-client']

default['redborder']['services'] = {}
default['redborder']['services']['barnyard2'] = true
default['redborder']['services']['chef-client'] = true
default['redborder']['services']['chrony'] = true
default['redborder']['services']['redborder-exporter'] = true
default['redborder']['services']['redborder-monitor'] = true
default['redborder']['services']['snmp'] = true
default['redborder']['services']['rsyslog'] = true
default['redborder']['services']['snmp'] = true
default['redborder']['services']['snortd'] = true
default['redborder']['services']['barnyard2'] = true
default['redborder']['services']['clamav'] = true
default['redborder']['services']['chrony'] = true
default['redborder']['services']['redborder-exporter'] = true

default['redborder']['systemdservices']['barnyard2'] = ['barnyard2']
default['redborder']['systemdservices']['chef-client'] = ['chef-client']
default['redborder']['systemdservices']['chrony'] = ['chronyd']
default['redborder']['systemdservices']['redborder-exporter'] = ['rb-exporter']
default['redborder']['systemdservices']['redborder-monitor'] = ['redborder-monitor']
default['redborder']['systemdservices']['snmp'] = ['snmpd']
default['redborder']['systemdservices']['rsyslog'] = ['rsyslog']
default['redborder']['systemdservices']['snmp'] = ['snmpd']
default['redborder']['systemdservices']['snortd'] = ['snortd']
default['redborder']['systemdservices']['barnyard2'] = ['barnyard2']
default['redborder']['systemdservices']['redborder-exporter'] = ['rb-exporter']
default['redborder']['systemdservices']['chrony'] = ['chronyd']
5 changes: 1 addition & 4 deletions resources/libraries/memory_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def memory_services(sysmem_total, excluded_services = [])

node['redborder']['memory_services'].each do |name, mem_s|
if node['redborder']['services'][name] &&
!excluded_services.include?(name) &&
!node['redborder']['excluded_memory_services'].include?(name)
!excluded_services.include?(name)
memory_services_size += mem_s['count']
end

Expand All @@ -24,8 +23,6 @@ def memory_services(sysmem_total, excluded_services = [])
node['redborder']['memory_services'].each do |name, mem_s|
next unless node['redborder']['services'][name] && !excluded_services.include?(name)

next unless !node['redborder']['excluded_memory_services'].include?(name)

# service count memory assigned * system memory / assigned services memory size
memory_serv[name] = (mem_s['count'] * sysmem_total / memory_services_size).round

Expand Down
2 changes: 1 addition & 1 deletion resources/recipes/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
end

rb_clamav_config 'Configure ClamAV' do
action(ips_services['clamav'] ? :add : :remove)
action :add
end

rb_chrony_config 'Configure Chrony' do
Expand Down
14 changes: 14 additions & 0 deletions resources/recipes/prepare_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@

# node attributes related with memory are changed inside the function to have simplicity using recursivity
memory_services(sysmem_total)

# Build service list for rbcli
services = node['redborder']['services'] || []
systemd_services = node['redborder']['systemdservices'] || []
service_enablement = {}

systemd_services.each do |service_name, systemd_name|
service_enablement[systemd_name.first] = services[service_name]
end

Chef::Log.info("Saving services enablement into /etc/redborder/services.json")
File.open("/etc/redborder/services.json", "w") do |file|
file.write(JSON.pretty_generate(service_enablement))
end

0 comments on commit ce3975f

Please sign in to comment.