From c35b3125593c2011af2aac3434a0f8e68a8b5f4d Mon Sep 17 00:00:00 2001 From: nilsver Date: Fri, 14 Jun 2024 09:12:43 +0100 Subject: [PATCH 1/5] logstash should not be running when there are no pipelines --- resources/attributes/default.rb | 2 +- resources/libraries/get_pipelines.rb | 14 ++++++++++++++ resources/recipes/configure.rb | 3 ++- resources/recipes/prepare_system.rb | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 resources/libraries/get_pipelines.rb diff --git a/resources/attributes/default.rb b/resources/attributes/default.rb index ad49c3a..1e10eb2 100644 --- a/resources/attributes/default.rb +++ b/resources/attributes/default.rb @@ -48,7 +48,7 @@ default['redborder']['services']['redborder-scanner'] = true default['redborder']['services']['snmp'] = true default['redborder']['services']['f2k'] = true -default['redborder']['services']['logstash'] = true +default['redborder']['services']['logstash'] = false default['redborder']['services']['pmacct'] = true default['redborder']['services']['rsyslog'] = true default['redborder']['services']['redborder-nmsp'] = true diff --git a/resources/libraries/get_pipelines.rb b/resources/libraries/get_pipelines.rb new file mode 100644 index 0000000..e43330e --- /dev/null +++ b/resources/libraries/get_pipelines.rb @@ -0,0 +1,14 @@ +module RbProxy + module Helpers + def get_pipelines + logstash_pipelines = [] + sensors = get_sensors_info() + + if proxy_services['logstash'] + logstash_pipelines.push('redfish-pipeline') unless sensors['device-sensor'].empty? + logstash_pipelines.push('bulkstats-pipeline') unless sensors['device-sensor'].empty? + end + logstash_pipelines + end + end +end diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index 7385904..727afde 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -99,7 +99,8 @@ namespaces node.run_state['namespaces'] vault_nodes node.run_state['sensors_info_all']['vault-sensor'] device_nodes node.run_state['sensors_info_all']['device-sensor'] - if proxy_services['logstash'] + logstash_pipelines node.default['pipelines'] + if proxy_services['logstash'] && node.default['pipelines'] && !node.default['pipelines'].empty? action [:add] else action [:remove] diff --git a/resources/recipes/prepare_system.rb b/resources/recipes/prepare_system.rb index 49813f5..9336322 100644 --- a/resources/recipes/prepare_system.rb +++ b/resources/recipes/prepare_system.rb @@ -55,6 +55,9 @@ # get namespaces node.run_state['namespaces'] = get_namespaces +# get logstash pipelines +node.default['pipelines'] = get_pipelines() + # get string with all zookeeper hosts and port separated by commas, its needed for multiples services # zk_port = node['redborder']['zookeeper']['port'] # zk_hosts = ['localhost'].map {|z| '#{z}.node:#{zk_port}'}.join(',') From ec5d379983f6b917e9781923ab781119d9f70c35 Mon Sep 17 00:00:00 2001 From: nilsver Date: Fri, 14 Jun 2024 09:13:49 +0100 Subject: [PATCH 2/5] update configure.rb --- 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 727afde..affa49f 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -100,7 +100,7 @@ vault_nodes node.run_state['sensors_info_all']['vault-sensor'] device_nodes node.run_state['sensors_info_all']['device-sensor'] logstash_pipelines node.default['pipelines'] - if proxy_services['logstash'] && node.default['pipelines'] && !node.default['pipelines'].empty? + if proxy_services['logstash'] && !node.default['pipelines'].empty? && !node.default['pipelines'].empty? action [:add] else action [:remove] From 08f57da23b31a47cd4adc586cd82879203c9af96 Mon Sep 17 00:00:00 2001 From: nilsver Date: Thu, 20 Jun 2024 13:47:47 +0100 Subject: [PATCH 3/5] fix logstash not running when pipelines empty --- resources/recipes/configure.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index affa49f..36560ec 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -100,11 +100,13 @@ vault_nodes node.run_state['sensors_info_all']['vault-sensor'] device_nodes node.run_state['sensors_info_all']['device-sensor'] logstash_pipelines node.default['pipelines'] - if proxy_services['logstash'] && !node.default['pipelines'].empty? && !node.default['pipelines'].empty? + logstash_pipelines node.default['pipelines'] + if !logstash_pipelines.nil? && !logstash_pipelines.empty? action [:add] else action [:remove] end + end rsyslog_config 'Configure rsyslog' do From 6185bfad5e6a95e6c3e693b67a6f94592cb021e2 Mon Sep 17 00:00:00 2001 From: nilsver Date: Thu, 20 Jun 2024 13:48:14 +0100 Subject: [PATCH 4/5] fix logstash not running when pipelines empty --- resources/recipes/configure.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/recipes/configure.rb b/resources/recipes/configure.rb index 36560ec..bd9e1be 100644 --- a/resources/recipes/configure.rb +++ b/resources/recipes/configure.rb @@ -100,13 +100,11 @@ vault_nodes node.run_state['sensors_info_all']['vault-sensor'] device_nodes node.run_state['sensors_info_all']['device-sensor'] logstash_pipelines node.default['pipelines'] - logstash_pipelines node.default['pipelines'] if !logstash_pipelines.nil? && !logstash_pipelines.empty? action [:add] else action [:remove] end - end rsyslog_config 'Configure rsyslog' do From e1272bb644533de707c2e2cfbe5c2b94cae8cc84 Mon Sep 17 00:00:00 2001 From: nilsver Date: Thu, 20 Jun 2024 14:18:09 +0100 Subject: [PATCH 5/5] add check for monitor configuration pipelines --- .../libraries/get_monitor_configuration.rb | 17 +++++++++++++++++ resources/libraries/get_pipelines.rb | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 resources/libraries/get_monitor_configuration.rb diff --git a/resources/libraries/get_monitor_configuration.rb b/resources/libraries/get_monitor_configuration.rb new file mode 100644 index 0000000..0c0a85e --- /dev/null +++ b/resources/libraries/get_monitor_configuration.rb @@ -0,0 +1,17 @@ +module RbProxy + module Helpers + def get_monitor_configuration + proxy_config = [] + sensor = search(:node, 'redborder_monitors:[* TO *] AND name:*device*').sort + sensor.each do |node| + monitors = node.normal['redborder']['monitors'] + monitors.each do |monitor| + if monitor['name'] == 'bulkstats_schema' || monitor['name'] == 'thermal' + proxy_config << monitor['name'] + end + end + end + proxy_config + end + end +end diff --git a/resources/libraries/get_pipelines.rb b/resources/libraries/get_pipelines.rb index e43330e..8228836 100644 --- a/resources/libraries/get_pipelines.rb +++ b/resources/libraries/get_pipelines.rb @@ -3,11 +3,14 @@ module Helpers def get_pipelines logstash_pipelines = [] sensors = get_sensors_info() + proxy_config = get_monitor_configuration() + has_device_sensors = !sensors['device-sensor'].nil? && !sensors['device-sensor'].empty? + contains_thermal = proxy_config.include?('thermal') + contains_bulkstats = proxy_config.include?('bulkstats_schema') + + logstash_pipelines.push('redfish-pipeline') if has_device_sensors && contains_thermal + logstash_pipelines.push('bulkstats-pipeline') if has_device_sensors && contains_bulkstats - if proxy_services['logstash'] - logstash_pipelines.push('redfish-pipeline') unless sensors['device-sensor'].empty? - logstash_pipelines.push('bulkstats-pipeline') unless sensors['device-sensor'].empty? - end logstash_pipelines end end