From f6bcd5420fad5835470898883e3e6583e9000c1f Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Fri, 28 Jun 2024 10:23:29 +0100 Subject: [PATCH 1/6] add mem2incident --- resources/libraries/get_api_auth_token.rb | 9 +++++++++ resources/recipes/configure.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 resources/libraries/get_api_auth_token.rb diff --git a/resources/libraries/get_api_auth_token.rb b/resources/libraries/get_api_auth_token.rb new file mode 100644 index 00000000..36299b50 --- /dev/null +++ b/resources/libraries/get_api_auth_token.rb @@ -0,0 +1,9 @@ +module RbManager + module Helpers + # TODO: find a good way of doing this + # Gets the first user api token + def get_api_auth_token + `echo "SELECT authentication_token FROM users WHERE id = 1;" | rb_psql redborder | awk 'NR==3 {print $1}' | tr -d '\n'` + end + end +end \ No newline at end of file diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index 54a95cc5..39c8380e 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -512,6 +512,17 @@ end end +mem2incident_config 'Configure redborder-mem2incident' do + cdomain node['redborder']['cdomain'] + memcached_servers node['redborder']['managers_per_services']['memcached'] + auth_token get_api_auth_token + if manager_services['redborder-mem2incident'] + action [:add, :register] + else + action [:remove, :deregister] + end +end + rb_postfix_config 'Configure postfix' do if node['redborder']['services']['postfix'] action :add From 3b3eb219222618f0f3c67b97c180d844a336730d Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Fri, 28 Jun 2024 10:43:07 +0100 Subject: [PATCH 2/6] Configure memcached servers --- resources/recipes/configure.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index 39c8380e..07ba7a3d 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -514,7 +514,7 @@ mem2incident_config 'Configure redborder-mem2incident' do cdomain node['redborder']['cdomain'] - memcached_servers node['redborder']['managers_per_services']['memcached'] + memcached_servers node['redborder']['managers_per_services']['memcached'].map { |s| "#{s}:#{node['redborder']['memcached']['port']}" } auth_token get_api_auth_token if manager_services['redborder-mem2incident'] action [:add, :register] From 3ffe9d4b59be1f6646d71df3cd535cc475ae927e Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Fri, 28 Jun 2024 11:02:47 +0100 Subject: [PATCH 3/6] Fix mem2incident --- resources/attributes/default.rb | 79 +++++++++++++++++---------------- resources/metadata.rb | 1 + 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/resources/attributes/default.rb b/resources/attributes/default.rb index e2d32307..2fd9abcf 100644 --- a/resources/attributes/default.rb +++ b/resources/attributes/default.rb @@ -87,6 +87,7 @@ default['redborder']['memory_services']['n2klocd'] = { 'count': 10, 'memory': 0 } default['redborder']['memory_services']['redborder-cep'] = { 'count': 10, 'memory': 0 } default['redborder']['memory_services']['rb-aioutliers'] = { 'count': 10, 'memory': 0 } +default['redborder']['memory_services']['redborder-mem2incident'] = { 'count': 5, 'memory': 0 } # exclude mem services, setting memory to 0 for each. default['redborder']['excluded_memory_services'] = %w(chef-client) @@ -108,7 +109,7 @@ postgresql redborder-postgresql nginx webui druid-broker druid-historical druid-realtime druid-coordinator f2k redborder-monitor pmacct redborder-dswatcher - redborder-events-counter http2k) + redborder-events-counter http2k redborder-mem2incident) default['redborder']['services_group']['custom'] = [] default['redborder']['services_group']['core'] = %w(consul zookeeper druid-coordinator druid-overlord hadoop-resourcemanager) # consul server @@ -170,44 +171,46 @@ default['redborder']['services']['postfix'] = true default['redborder']['services']['keepalived'] = false default['redborder']['services']['clamav'] = true - -default['redborder']['systemdservices']['chef-client'] = ['chef-client'] -default['redborder']['systemdservices']['chef-server'] = ['opscode-erchef'] -default['redborder']['systemdservices']['consul'] = ['consul'] -default['redborder']['systemdservices']['consul-client'] = ['consul'] -default['redborder']['systemdservices']['druid-realtime'] = ['druid-realtime'] -default['redborder']['systemdservices']['druid-coordinator'] = ['druid-coordinator'] -default['redborder']['systemdservices']['druid-historical'] = ['druid-historical'] -default['redborder']['systemdservices']['druid-broker'] = ['druid-broker'] -default['redborder']['systemdservices']['kafka'] = ['kafka'] -default['redborder']['systemdservices']['zookeeper'] = ['zookeeper'] -default['redborder']['systemdservices']['webui'] = ['webui'] -default['redborder']['systemdservices']['postgresql'] = ['postgresql'] -default['redborder']['systemdservices']['redborder-postgresql'] = ['redborder-postgresql'] -default['redborder']['systemdservices']['nginx'] = ['nginx'] -default['redborder']['systemdservices']['redborder-cep'] = ['redborder-cep'] -default['redborder']['systemdservices']['rb-aioutliers'] = ['rb-aioutliers'] -default['redborder']['systemdservices']['rb-logstatter'] = ['rb-logstatter'] -default['redborder']['systemdservices']['rb-arubacentral'] = ['rb-arubacentral'] -default['redborder']['systemdservices']['memcached'] = ['memcached'] -default['redborder']['systemdservices']['s3'] = ['minio'] -default['redborder']['systemdservices']['mongodb'] = ['mongod'] -default['redborder']['systemdservices']['redborder-monitor'] = ['redborder-monitor'] -default['redborder']['systemdservices']['redborder-scanner'] = ['redborder-scanner'] -default['redborder']['systemdservices']['snmp'] = ['snmpd'] -default['redborder']['systemdservices']['f2k'] = ['f2k'] -default['redborder']['systemdservices']['logstash'] = ['logstash'] -default['redborder']['systemdservices']['pmacct'] = ['sfacctd'] -default['redborder']['systemdservices']['redborder-dswatcher'] = ['redborder-dswatcher'] +default['redborder']['services']['mem2incident'] = false + +default['redborder']['systemdservices']['chef-client'] = ['chef-client'] +default['redborder']['systemdservices']['chef-server'] = ['opscode-erchef'] +default['redborder']['systemdservices']['consul'] = ['consul'] +default['redborder']['systemdservices']['consul-client'] = ['consul'] +default['redborder']['systemdservices']['druid-realtime'] = ['druid-realtime'] +default['redborder']['systemdservices']['druid-coordinator'] = ['druid-coordinator'] +default['redborder']['systemdservices']['druid-historical'] = ['druid-historical'] +default['redborder']['systemdservices']['druid-broker'] = ['druid-broker'] +default['redborder']['systemdservices']['kafka'] = ['kafka'] +default['redborder']['systemdservices']['zookeeper'] = ['zookeeper'] +default['redborder']['systemdservices']['webui'] = ['webui'] +default['redborder']['systemdservices']['postgresql'] = ['postgresql'] +default['redborder']['systemdservices']['redborder-postgresql'] = ['redborder-postgresql'] +default['redborder']['systemdservices']['nginx'] = ['nginx'] +default['redborder']['systemdservices']['redborder-cep'] = ['redborder-cep'] +default['redborder']['systemdservices']['rb-aioutliers'] = ['rb-aioutliers'] +default['redborder']['systemdservices']['rb-logstatter'] = ['rb-logstatter'] +default['redborder']['systemdservices']['rb-arubacentral'] = ['rb-arubacentral'] +default['redborder']['systemdservices']['memcached'] = ['memcached'] +default['redborder']['systemdservices']['s3'] = ['minio'] +default['redborder']['systemdservices']['mongodb'] = ['mongod'] +default['redborder']['systemdservices']['redborder-monitor'] = ['redborder-monitor'] +default['redborder']['systemdservices']['redborder-scanner'] = ['redborder-scanner'] +default['redborder']['systemdservices']['snmp'] = ['snmpd'] +default['redborder']['systemdservices']['f2k'] = ['f2k'] +default['redborder']['systemdservices']['logstash'] = ['logstash'] +default['redborder']['systemdservices']['pmacct'] = ['sfacctd'] +default['redborder']['systemdservices']['redborder-dswatcher'] = ['redborder-dswatcher'] default['redborder']['systemdservices']['redborder-events-counter'] = ['redborder-events-counter'] -default['redborder']['systemdservices']['http2k'] = ['http2k'] -default['redborder']['systemdservices']['rsyslog'] = ['rsyslog'] -default['redborder']['systemdservices']['redborder-nmsp'] = ['redborder-nmsp'] -default['redborder']['systemdservices']['redborder-ale'] = ['redborder-ale'] -default['redborder']['systemdservices']['n2klocd'] = ['n2klocd'] -default['redborder']['systemdservices']['radiusd'] = ['radiusd'] -default['redborder']['systemdservices']['postfix'] = ['postfix'] -default['redborder']['systemdservices']['keepalived'] = ['keepalived'] +default['redborder']['systemdservices']['http2k'] = ['http2k'] +default['redborder']['systemdservices']['rsyslog'] = ['rsyslog'] +default['redborder']['systemdservices']['redborder-nmsp'] = ['redborder-nmsp'] +default['redborder']['systemdservices']['redborder-ale'] = ['redborder-ale'] +default['redborder']['systemdservices']['n2klocd'] = ['n2klocd'] +default['redborder']['systemdservices']['radiusd'] = ['radiusd'] +default['redborder']['systemdservices']['postfix'] = ['postfix'] +default['redborder']['systemdservices']['keepalived'] = ['keepalived'] +default['redborder']['systemdservices']['redborder-mem2incident'] = ['redborder-mem2incident'] default['redborder']['manager']['balanced'] = [ { port: 443, protocol: 'tcp', name: 'redborder webui', service: 'webui', redirected_service: 'nginx', persistence_timeout: 9600 }, { port: 2055, protocol: 'udp', name: 'netflow,ipfix/sflow daemon', service: 'f2k', redirected_service: 'f2k', persistence_timeout: 30 }, { port: 6343, protocol: 'udp', name: 'sflow daemon', service: 'sfacctd', redirected_service: 'sfacctd', persistence_timeout: 30 }, { port: 9092, protocol: 'tcp', name: 'kafka', service: 'kafka', redirected_service: 'kafka', persistence_timeout: 30 } ] diff --git a/resources/metadata.rb b/resources/metadata.rb index 1a580974..c4839140 100644 --- a/resources/metadata.rb +++ b/resources/metadata.rb @@ -44,3 +44,4 @@ depends 'rb-postfix' depends 'rb-clamav' depends 'keepalived' +depends 'mem2incident' \ No newline at end of file From 686f834c60e10b98ff0dc22b2c0f29936a9bd754 Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Fri, 28 Jun 2024 12:54:01 +0100 Subject: [PATCH 4/6] Add auth_token --- resources/recipes/configure.rb | 2 +- resources/recipes/prepare_system.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index 07ba7a3d..d2da6d7d 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -515,7 +515,7 @@ mem2incident_config 'Configure redborder-mem2incident' do cdomain node['redborder']['cdomain'] memcached_servers node['redborder']['managers_per_services']['memcached'].map { |s| "#{s}:#{node['redborder']['memcached']['port']}" } - auth_token get_api_auth_token + auth_token node['auth_token'] if manager_services['redborder-mem2incident'] action [:add, :register] else diff --git a/resources/recipes/prepare_system.rb b/resources/recipes/prepare_system.rb index eac41efc..3046ffb8 100644 --- a/resources/recipes/prepare_system.rb +++ b/resources/recipes/prepare_system.rb @@ -140,6 +140,7 @@ # set webui hosts webui_hosts = node['redborder']['managers_per_services']['webui'].map { |z| "#{z}.node" } node.default['redborder']['webui']['hosts'] = webui_hosts +node.run_state['auth_token'] = get_api_auth_token # set kafka host index if kafka is enabled in this host if node['redborder']['managers_per_services']['kafka'].include?(node.name) From 36a6bda8ffca2d09e11a16036d1a05af4f94b5a3 Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Fri, 28 Jun 2024 16:24:42 +0100 Subject: [PATCH 5/6] fix run state variable --- resources/recipes/configure.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index d2da6d7d..de22e0ab 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -515,7 +515,7 @@ mem2incident_config 'Configure redborder-mem2incident' do cdomain node['redborder']['cdomain'] memcached_servers node['redborder']['managers_per_services']['memcached'].map { |s| "#{s}:#{node['redborder']['memcached']['port']}" } - auth_token node['auth_token'] + auth_token node.run_state['auth_token'] if manager_services['redborder-mem2incident'] action [:add, :register] else From e6946629a179762dc043026b8ab9e3cf1471500b Mon Sep 17 00:00:00 2001 From: Miguel Negron Date: Tue, 9 Jul 2024 12:04:30 +0100 Subject: [PATCH 6/6] fix lint --- resources/libraries/get_api_auth_token.rb | 2 +- resources/metadata.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/libraries/get_api_auth_token.rb b/resources/libraries/get_api_auth_token.rb index 36299b50..ade7dd84 100644 --- a/resources/libraries/get_api_auth_token.rb +++ b/resources/libraries/get_api_auth_token.rb @@ -6,4 +6,4 @@ def get_api_auth_token `echo "SELECT authentication_token FROM users WHERE id = 1;" | rb_psql redborder | awk 'NR==3 {print $1}' | tr -d '\n'` end end -end \ No newline at end of file +end diff --git a/resources/metadata.rb b/resources/metadata.rb index 9de5a1d7..c4933517 100644 --- a/resources/metadata.rb +++ b/resources/metadata.rb @@ -44,4 +44,4 @@ depends 'rb-postfix' depends 'rb-clamav' depends 'keepalived' -depends 'mem2incident' \ No newline at end of file +depends 'mem2incident'