From ce3975f929ccdd647c18a8d9f6dd528a6841a272 Mon Sep 17 00:00:00 2001 From: manegron Date: Sat, 19 Oct 2024 17:27:13 +0100 Subject: [PATCH 1/2] Remove clamav from service list, sort memory services, sort service list, save service list for rbcli --- resources/attributes/default.rb | 25 ++++++++++--------------- resources/libraries/memory_services.rb | 5 +---- resources/recipes/configure.rb | 2 +- resources/recipes/prepare_system.rb | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/resources/attributes/default.rb b/resources/attributes/default.rb index cb35319..5da7a82 100644 --- a/resources/attributes/default.rb +++ b/resources/attributes/default.rb @@ -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'] diff --git a/resources/libraries/memory_services.rb b/resources/libraries/memory_services.rb index a4007ec..a13e132 100644 --- a/resources/libraries/memory_services.rb +++ b/resources/libraries/memory_services.rb @@ -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 @@ -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 diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index 0ef42dd..d28cb80 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -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 diff --git a/resources/recipes/prepare_system.rb b/resources/recipes/prepare_system.rb index f0ac317..7dcd825 100644 --- a/resources/recipes/prepare_system.rb +++ b/resources/recipes/prepare_system.rb @@ -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 From 42e8c16df285c8b9db79df95af17cee121d5a6df Mon Sep 17 00:00:00 2001 From: manegron Date: Sat, 19 Oct 2024 18:13:48 +0100 Subject: [PATCH 2/2] Pass lint --- resources/recipes/prepare_system.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/resources/recipes/prepare_system.rb b/resources/recipes/prepare_system.rb index 7dcd825..cf04851 100644 --- a/resources/recipes/prepare_system.rb +++ b/resources/recipes/prepare_system.rb @@ -65,7 +65,7 @@ memory_services(sysmem_total) # Build service list for rbcli -services = node['redborder']['services'] || [] +services = node['redborder']['services'] || [] systemd_services = node['redborder']['systemdservices'] || [] service_enablement = {} @@ -73,7 +73,5 @@ 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 +Chef::Log.info('Saving services enablement into /etc/redborder/services.json') +File.write('/etc/redborder/services.json', JSON.pretty_generate(service_enablement))